当应用程序处于后台状态时,是否可以读取或写入plist?
答案 0 :(得分:1)
当您的应用程序在后台时,无法读取您的plist,因为您的应用程序在后台状态下的运行时间不超过10分钟。只有三个选项可以让您的应用程序在后台运行超过10分钟。
如果要读取和编写plist,请在应用程序进入前台状态时执行此操作。为此,您可以在应用程序中读取和写入您的plist成为活动委托方法。
答案 1 :(得分:1)
试试这个......
- (void)readPlist
{
NSString *filePath = @"/System/Library/CoreServices/SystemVersion.plist";
NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
NSString *value;
value = [plistDict objectForKey:@"ProductVersion"];
/* You could now call the string "value" from somewhere to return the value of the string in the .plist specified, for the specified key. */
}
- (void)writeToPlist
{
NSString *filePath = @"/System/Library/CoreServices/SystemVersion.plist";
NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
[plistDict setValue:@"1.1.1" forKey:@"ProductVersion"];
[plistDict writeToFile:filePath atomically: YES];
/* This would change the firmware version in the plist to 1.1.1 by initing the NSDictionary with the plist, then changing the value of the string in the key "ProductVersion" to what you specified */
}
希望这能帮到你!