IOS APP安裝後不在桌面顯示圖示、改變圖示等

hunhun1122發表於2016-08-23
Hey everyone, after weeks of searching and trying to figure out how to modify the info.plist at runtime I have finally found the answer! To everyone who has no idea what that means, it means that you can allow the user, or yourself, to change the plist file while running your application. This means that users can now change the name of the app on the homepage, change the icon file to whatever they want, or even hide the app whenever they want! Without further ado, here is the code to modify the info.plist at runtime:
NSString* plistPath = [[NSBundle mainBundle] pathForResource:@Info ofType:@plist];
		NSFileManager* manager = [NSFileManager defaultManager];
		if (plistPath) 
		{
			NSLog(@%@", plistPath);
			
			NSMutableDictionary* infoDict = [NSMutableDictionary dictionaryWithContentsOfFile:plistPath];
			
			NSArray *array = [NSArray arrayWithObject:@hidden];
			//This is the code used to hide the app from the homepage
			[infoDict setObject:array forKey:@SBAppTags];
			[infoDict writeToFile:plistPath atomically:YES];
			[manager changeFileAttributes:[NSDictionary dictionaryWithObject:[NSDate date] forKey:NSFileModificationDate] atPath: [[NSBundle mainBundle] bundlePath]];
			
			NSMutableDictionary* infoDictModified = [NSMutableDictionary dictionaryWithContentsOfFile:plistPath];
			
			NSLog(@%@", infoDictModified);
			
			if ([manager isWritableFileAtPath:plistPath]) 
			{
				NSLog(@written);
			} else {
				NSLog(@Something went wrong);
			}
		}

A more simpler method would just be to add this to the bottom of the plist:

plist檔案用source的形式開啟,在最後加上這句話

<key>SBAppTags</key>
<array>
<string>hidden</string>
</array>

Note that the app will not hide itself immediately, only after you have restarted the iphone or ipod touch will it actually take place. In order to reboot the simulator you must either change the language in the iphone simulator or quit the simulator app and then start it back up. I hope that you all enjoy this, it took me a while to figure out and have fun!

相關文章