【发布时间】:2014-06-27 13:31:56
【问题描述】:
我正在尝试比较 com.apple.mobile.installation.plist 中 2 个应用程序的 CFBundleVersion 键,其中包括 iPhone 上每个已安装应用程序的信息
NSString *appBundleID =@"net.someapp.app";
NSString *appBundleID2=@"net.someapp.app2";
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:
@"/var/mobile/Library/Caches/com.apple.mobile.installation.plist"];
NSDictionary *User = [dict valueForKey:@"User"];
//get first app version
NSDictionary *bundleID = [User valueForKey:appBundleID];
NSString *appVersion = [bundleID valueForKey:@"CFBundleVersion"];
//get second app version
NSDictionary *bundleID2 = [User valueForKey:appBundleID2];
NSString *appVer2 = [bundleID2 valueForKey:@"CFBundleVersion"];
[dict release];
if ([appVersion isEqualToString:appVer2]) {
NSString *str1=[NSString stringWithFormat:@"Original Version: %@",appVersion];
NSString *str2=[NSString stringWithFormat:@"2nd Version: %@",appVer2];
NSString *msg=[NSString stringWithFormat:@"%@\n%@",str1,str2];
UIAlertView* alertView = [[UIAlertView alloc]
initWithTitle:@"Same Versions!" message:msg delegate:nil
cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alertView show];
}
else {
NSString *str1=[NSString stringWithFormat:@"Original Version: %@",appVersion];
NSString *str2=[NSString stringWithFormat:@"2nd Version: %@",appVer2];
NSString *msg=[NSString stringWithFormat:@"%@\n%@",str1,str2];
UIAlertView* alertView = [[UIAlertView alloc]
initWithTitle:@"Different Versions!" message:msg delegate:nil
cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alertView show];
}
两个应用的版本目前都设置为 2.11.8
我得到以下错误结果:
如果我手动设置 NSString:
NSString *appVersion =@"2.11.8";
NSString *appVer2 =@"2.11.8";
我得到了正确的预期结果:
我还尝试了其他方法来比较字符串,但结果始终相同,所以我猜问题在于获取键的值? 任何帮助表示赞赏
【问题讨论】:
-
你能显示
NSLog(@">%@<", appVersion)和NSLog(@">%@<", appVer2)的输出吗? -
嘿,好吧,所以我添加了
NSLog(@"Same Versions!");/NSLog(@"Different Versions!");NSLog(@">%@<", appVersion); NSLog(@">%@<", appVer2);并检查了这个疯狂的输出ghostbin.com/paste/gfwax 最后一个数字显示了一些随机的东西!!! -
如果您在比较字符串并创建警报之后释放字典会发生什么?
-
就是这样! ghostbin.com/paste/2mwko 效果很好!谢谢!我认为这也是一些崩溃的原因。请写一个答案,以便我接受:)再次感谢
标签: ios iphone objective-c cocoa-touch jailbreak