Objective c 如何将同一NSString多次写入plist。覆盖iOS

Objective c 如何将同一NSString多次写入plist。覆盖iOS,objective-c,ios,xml,xcode,plist,Objective C,Ios,Xml,Xcode,Plist,我正在为越狱iOS设备编写一个调整,我希望能够将此NSString“bundleID”和在代码中创建的整数写入plist文件。下面的代码可以做到这一点,但是,它只执行一次,不允许我将其写入plist多次。我之所以要这样做,是因为bundleID会发生变化,也应该写入plist。基本上,我想做的是当一个应用程序启动时,该应用程序(com.apple.mobilesafari)的bundle id将作为密钥写入我的plist。然后,每次打开应用程序时,我都会使用代码为值添加1。例如,如果我四次打开m

我正在为越狱iOS设备编写一个调整,我希望能够将此
NSString
“bundleID”和在代码中创建的整数写入plist文件。下面的代码可以做到这一点,但是,它只执行一次,不允许我将其写入plist多次。我之所以要这样做,是因为bundleID会发生变化,也应该写入plist。基本上,我想做的是当一个应用程序启动时,该应用程序(com.apple.mobilesafari)的bundle id将作为密钥写入我的plist。然后,每次打开应用程序时,我都会使用代码为值添加1。例如,如果我四次打开mobile safari,plist应该是这样的

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"          "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.mobilesafari</key>
    <integer>4</integer>
    <key>customText</key>
    <false/>
    <key>enabled</key>
    <false/>
</dict>
</plist>
注:我也在使用多维特的西奥斯来编译我的调整


编辑:意识到我的两个plist是不同的。可能是我的问题。我将在稍后进行测试

同时注意,启动应用程序和仅仅将其置于前台之间可能存在差异。代码确实有效。但是,它不会写入plist多个对象
<key>com.apple.mobilesafari</key> <integer>1</integer>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"  "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.mobilesafari</key>
    <integer>1</integer>
    <key>customText</key>
    <false/>
    <key>enabled</key>
    <false/>
</dict>
<dict>
    <key>com.apple.contacts</key>
    <integer>1</integer>
    <key>customText</key>
    <false/>
    <key>enabled</key>
    <false/>
</dict>
</plist>
%hook SBApplicationIcon
-(void)launch
{
// Return original method
        %orig;

// Get Bundle ID
    NSString* bundleID = [self leafIdentifier];

// Print that badboy!
    NSLog(@"Bundle ID: %@ ",bundleID);


// Set up plist
NSMutableDictionary *launches = [[NSMutableDictionary alloc]     initWithContentsOfFile:@"/var/mobile/Library/Preferences/com.bengerard.ipslider.plist"];

// Check plist exists
NSString *pathToFile = @"/var/mobile/Library/Preferences/com.bengerard.apppop.plist";
BOOL isFile = [[NSFileManager defaultManager] fileExistsAtPath:pathToFile isDirectory:NO];

 if(isFile)
{
// Counting
    int count = [[launches objectForKey:bundleID] intValue];
    count++;



// Write number of launches to plist
    [launches setObject:[NSNumber numberWithInt:count] forKey:bundleID];
//[launches insertObject:[NSNumber numberWithInt:count] forKey:bundleID];
    [launches writeToFile:@"/var/mobile/Library/Preferences/com.bengerard.apppop.plist" atomically:YES];

}
else {
//The file doesn't exit. 
}
// [bundleID release];
// [pathToFile release];
// [launches release];

}
%end