1

我正在为越狱的 iOS 设备编写一个调整,我希望能够将这个NSString“bundleID”和在我的代码中创建的整数写入一个 plist 文件。下面的代码可以执行此操作,但是,它只执行一次,并且不允许我将其多次写入 plist。我想这样做是因为 bundleID 发生了变化,也应该写入 plist。基本上我想要做的是当一个应用程序启动时,该应用程序的捆绑ID(com.apple.mobilesafari)被写为我的plist中的键。然后,我有代码可以在每次打开应用程序时将值加 1。例如,如果我打开移动 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>

但是,当我四次启动移动 Safari 时,它仍然...

<key>com.apple.mobilesafari</key> <integer>1</integer>

我还希望为每个应用程序保存 bundleID。因此,如果我打开 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>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>

这是我的objective-c代码...

%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

PS:我也在使用 DHowett 的 theos 来编译我的调整。

编辑:意识到我的两个 plist 是不同的。可能导致我的问题。我稍后会测试

4

0 回答 0