简体   繁体   English

更新后首次启动iOS

[英]iOS first launch after update

Upon the first launch of my app, i have used NSUser defaults to show an intro of my app. 在我的应用程序首次启动时,我使用了NSUser默认值来显示我的应用程序简介。

However, once an update has been issued and installed, i want to show a whats new page on the first launch after update. 但是,一旦发布并安装了更新,我想在更新后的首次启动时显示一个新页面。 My issue is that NS user defaults does not reset and everyone will have different launch counts. 我的问题是NS用户默认设置不会重置,并且每个人的启动计数都不同。

I could use this code to work out the software version... 我可以使用此代码来计算软件版本...

if ([[NSString stringWithFormat:@"Version %@",[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]]isEqualToString:@"Version 1.0"])
{
// first launch code here
} 

...but how could i then only get the whats new page to appear on the first launch after update rather than every launch? ...但是我怎么才能让whats新页面显示在更新后的第一次启动而不是每次启动时?

If any code is required, it would need to be in Objective C as I have not yet begun developing in swift. 如果需要任何代码,则它必须位于目标C中,因为我尚未开始迅速开发。 Thanks in advance for any assistance. 在此先感谢您的协助。

Use NSUserDefaults to store a boolean value like "hasShowedUpatePopupForVersionXX" . 使用NSUserDefaults存储一个布尔值,例如"hasShowedUpatePopupForVersionXX" Don't forget to set it to YES in case of new installs 如果有新安装,请不要忘记将其设置为YES

//check if popup has been shown 
 if (![[NSUserDefaults standardUserDefaults] valueForKey:@"hasShowedUpatePopupForVersionXX"]) {
     // Set the value to YES   
     [[NSUserDefaults standardUserDefaults] setValue:@YES forKey:@"hasShowedUpatePopupForVersionXX"];
}

Do a version check of your app and store the current version in NSUserDefaults. 对您的应用进行版本检查,并将当前版本存储在NSUserDefaults中。 Then on launch check to make sure that value matches the current value. 然后在启动时检查以确保该值与当前值匹配。 If it doesn't, display the content you wish to display then save the NSUserDefaults key to the new value. 如果没有,请显示您想要显示的内容,然后将NSUserDefaults键保存为新值。 I wouldn't store a Bool value and would rather store the current version of your app. 我不会存储Bool值,而是会存储您的应用程序的当前版本。

How to get the current version 如何获取当前版本

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

Using the above codes, I have created a fully working section of code which finds the App version. 使用上面的代码,我创建了一个可以正常工作的代码部分,用于查找App版本。

If the app version in the NSUserdefaults is not the same, it will complete the segue and update the NSUserdefaults so that it does not run again until the app Updates. 如果NSUserdefaults中的应用程序版本不同,它将完成设置并更新NSUserdefaults,以便在应用程序更新之前不会再次运行。

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

NSLog(@"App Version is %@",version);

if ([[NSString stringWithFormat:@"Version %@",[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]]isEqualToString:@"Version 1.0"])
{
    //check if popup has been shown
    if (![[[NSUserDefaults standardUserDefaults] valueForKey:@"appVersion"] isEqualToString:version]) {
                    [self performSegueWithIdentifier:@"showUpdate" sender:self];
        // Set the value to YES
        [[NSUserDefaults standardUserDefaults] setValue:version forKey:@"appVersion"];
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM