判断App是否首次启动

作者: xuguoxing 分类: Code Snippet, IOS 发布时间: 2012-06-03 10:14 ė 6没有评论

现在的APP中流行在程序第一次启动时显示一些新手引导页面,下面的代码可用于判断此APP是否第一次启动,或升级后的第一次启动。


#define LAST_RUN_VERSION_KEY        @"last_run_version_of_application"
- (BOOL) isFirstLoad{
     NSString *currentVersion = [[[NSBundle mainBundle] infoDictionary]
         objectForKey:@"CFBundleShortVersionString"];    

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    NSString *lastRunVersion = [defaults objectForKey:LAST_RUN_VERSION_KEY];

    if (!lastRunVersion) {
         [defaults setObject:currentVersion forKey:LAST_RUN_VERSION_KEY];
         return YES;
        // App is being run for first time
    }
    else if (![lastRunVersion isEqualToString:currentVersion]) {
        [defaults setObject:currentVersion forKey:LAST_RUN_VERSION_KEY];
        return YES;
        // App has been updated since last run
    }
    return NO;
}

参考:
Check for first use
app 新手引导设计
Top 6 Help Design Patterns for iPhone Apps

本文出自 清风徐来,水波不兴 的博客,转载时请注明出处及相应链接。

本文永久链接: http://www.winddisk.com/2012/06/03/check_first_load/

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Protected by WP Anti Spam
Ɣ回顶部