gpt4 book ai didi

iphone - 应用程序更新问题

转载 作者:行者123 更新时间:2023-11-29 04:31:24 24 4
gpt4 key购买 nike

大家好,我的应用程序遇到问题。我需要确定我的应用程序是否已更新到某个点。我发现用这种方法如何获取当前版本

 NSString *first = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];

NSString *second = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];

如果应用程序是从itunes更新的,那么谁的var被更改来确定我的应用程序已更新,因为我通过在Targets>Summary>Version中的xcode修改来证明。第一个var更改,但第二个var不变。

我必须选择第一个还是第二个,以及如何证明这一点?

最佳答案

我不确定这是否是您正在寻找的内容,但此代码可以通过在 NSUserDefaults 中存储版本信息来告诉您您的应用是否已更新。

- (BOOL)wasUpdated {
// access NSUserDefaults
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

// get previous version number from defaults
NSString *previousVersion = [defaults stringForKey:@"previousVersion"];

// get current version number from info plist
NSString *currentVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];

// check against previousVersion being nil
if (!previousVersion) {
// set current version to previous version
[defaults setObject:currentVersion forKey:@"previousVersion"];

// previousVersion didn't exist and can't be checked, return NO
return NO;
}

// return YES if the versions are not the same
if (NSOrderedSame != [previousVersion compare:currentVersion]) return YES;

// return NO if they are the same
return NO;
}

希望这就是您所需要的。如果我不明白你的意思,请告诉我。

关于iphone - 应用程序更新问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11697914/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com