在看了一堆关于检测这是否是全新安装的SO帖子之后,我假设我想要做的事情是不可能的,但我会问以防万一有一个技巧我是不确定。
我正在构建一个集成到应用程序中的SDK,我希望能够告诉SDK何时初始化为第一次,如果它来自全新安装,或者来自应用更新,其中包括我们的SDK。
我可以让集成商调用类似[MySDK initializeIsNewInstall:YES/NO]
的东西并强制它们找出它是什么(使用NSDefaults或其他),但我宁愿能够以某种方式自动解决它。
如果有人有任何想法,那就太棒了。
答案 0 :(得分:0)
我想通过使用[NSUserDefaults standardUserDefaults]
这样做,
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if([[NSUserDefaults standardUserDefaults] boolForKey:@"isApplicationUpdated"]){
// application was updated//
// make another userDefaults to store version number and confirm if it is updated here.
}
else{
[[NSUserDefaults standardUserDefaults] setBookForKey:@"isApplicationUpdated"]
// as for the first time application would not find this key and you can use it after you have updated the app do stuff here
}
答案 1 :(得分:0)
在您的案例中,检测您的应用是否已更新或新安装的唯一方法是检查您的持久性是否应该来自之前的版本。对于将来的检查,您可以将自己的标记添加到持久性中。