ios*_*iki 2 iphone bundle properties
我有一个属性列表文件,当我构建我的程序时,它会到达包.现在,我想用我的Mac修改它,并在我的程序运行时更新它.我想捆绑文件不是正确的方法,因为在构建之后我似乎没有对bundle的内容的任何访问权限.
我该怎么办?至少在iPhone模拟器上工作会很不错,但使用该设备也很不错.
小智 5
您的应用程序包已签名,因此在创建/签名后无法对其进行修改.要修改plist,需要先将其复制到应用程序的Documents目录中.然后,您可以修改副本.这是我在我的一个应用程序中使用的方法,该应用程序在应用程序启动期间将名为FavoriteUsers.plist的文件从软件包复制到文档目录.
/* Copies the FavoritesUsers.plist file to the Documents directory
* if the file hasn't already been copied there
*/
+ (void)moveFavoritesToDocumentsDir
{
/* get the path to save the favorites */
NSString *favoritesPath = [self favoritesPath];
/* check to see if there is already a file saved at the favoritesPath
* if not, copy the default FavoriteUsers.plist to the favoritesPath
*/
NSFileManager *fileManager = [NSFileManager defaultManager];
if(![fileManager fileExistsAtPath:favoritesPath])
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"FavoriteUsers" ofType:@"plist"];
NSArray *favoriteUsersArray = [NSArray arrayWithContentsOfFile:path];
[favoriteUsersArray writeToFile:favoritesPath atomically:YES];
}
}
/* Returns the string representation of the path to
* the FavoriteUsers.plist file
*/
+ (NSString *)favoritesPath
{
/* get the path for the Documents directory */
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
/* append the path component for the FavoriteUsers.plist */
NSString *favoritesPath = [documentsPath stringByAppendingPathComponent:@"FavoriteUsers.plist"];
return favoritesPath;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3875 次 |
| 最近记录: |