2011-12-05 58 views

回答

1

当应用程序处于后台时,不能读取plist,因为您的应用程序在后台状态下运行时间不超过10分钟。只有三个选项可让您的应用程序在后台运行超过10分钟。

如果您要读写plist,请在应用程序进入前台状态时执行此操作。为此,您可以在应用程序中读取和写入您的plist成为活动委托方法。

+0

请不要对“你”和“是”使用“u”和“r”。 Textspeak阅读很痛苦。 –

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 */ 
    } 

希望这可以帮助你!