应用程序是否首次运行
2016-06-08 14:41
211 查看
.h文件中定义方法
#import "AppDelegate.h"
@interface AppDelegate (Helper)
// 检测当前版本的应用程序是否首次运行
+ (BOOL)isFirstLaunching;
#import "AppDelegate+Helper.h"
@implementation AppDelegate (Helper)
.m文件中实现方法
/*
是否为版本升级后的第一次打开程序
*/
+ (BOOL)isFirstLaunching
{
//从plist文件中取出版本号
NSString *currentVersion = [[[NSBundle
mainBundle] infoDictionary]
objectForKey:@"CFBundleShortVersionString"];
//取出NSUserDefaults中的版本号
NSUserDefaults *defaults = [NSUserDefaults
standardUserDefaults];
NSString *lastRunVersion = [defaults
objectForKey:LAST_RUN_VERSION_KEY];
CYBLog(@">>>>>pre——Login11-1---lastRunVersion=%@",lastRunVersion);
//应用程序全新安装,返回yes进入引导页面
if (!lastRunVersion) {
[defaults setObject:currentVersion
forKey:LAST_RUN_VERSION_KEY];
[defaults setObject:[NSNumber
numberWithInt:1]
forKey:kAppLaunchTimesKey];
return YES;
}
CYBLog(@">>>>>pre——Login11-2---currentVersion=%@",currentVersion);
//应用程序升级安装
if (![lastRunVersion
isEqualToString:currentVersion]) {
[defaults setObject:currentVersion
forKey:LAST_RUN_VERSION_KEY];
//重置应用程序启动次数计数器以及打分提醒设置
[defaults setObject:[NSNumber
numberWithInt:1]
forKey:kAppLaunchTimesKey];
[defaults synchronize];
return YES;
}
//
应用程序启动次数+1
int appLaunchTimes = [[defaults
objectForKey:kAppLaunchTimesKey]
intValue];
[defaults setObject:[NSNumber
numberWithInt:++appLaunchTimes]
forKey:kAppLaunchTimesKey];
[defaults synchronize];
CYBLog(@">>>>>pre——Login11-3---启动次数%d",appLaunchTimes);
return
NO;
}
AppDelegate.m中使用
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if ([AppDelegate
isFirstLaunching]) {
//引导页
AppGuideViewController *appGuideVc = [[AppGuideViewController
alloc]
initWithNibName:@"AppGuideViewController"
bundle:nil];
UINavigationController * navigationVc = [[UINavigationController
alloc] initWithRootViewController:appGuideVc];
self.window.rootViewController = navigationVc;
return YES;
}
}
#import "AppDelegate.h"
@interface AppDelegate (Helper)
// 检测当前版本的应用程序是否首次运行
+ (BOOL)isFirstLaunching;
#import "AppDelegate+Helper.h"
@implementation AppDelegate (Helper)
.m文件中实现方法
/*
是否为版本升级后的第一次打开程序
*/
+ (BOOL)isFirstLaunching
{
//从plist文件中取出版本号
NSString *currentVersion = [[[NSBundle
mainBundle] infoDictionary]
objectForKey:@"CFBundleShortVersionString"];
//取出NSUserDefaults中的版本号
NSUserDefaults *defaults = [NSUserDefaults
standardUserDefaults];
NSString *lastRunVersion = [defaults
objectForKey:LAST_RUN_VERSION_KEY];
CYBLog(@">>>>>pre——Login11-1---lastRunVersion=%@",lastRunVersion);
//应用程序全新安装,返回yes进入引导页面
if (!lastRunVersion) {
[defaults setObject:currentVersion
forKey:LAST_RUN_VERSION_KEY];
[defaults setObject:[NSNumber
numberWithInt:1]
forKey:kAppLaunchTimesKey];
return YES;
}
CYBLog(@">>>>>pre——Login11-2---currentVersion=%@",currentVersion);
//应用程序升级安装
if (![lastRunVersion
isEqualToString:currentVersion]) {
[defaults setObject:currentVersion
forKey:LAST_RUN_VERSION_KEY];
//重置应用程序启动次数计数器以及打分提醒设置
[defaults setObject:[NSNumber
numberWithInt:1]
forKey:kAppLaunchTimesKey];
[defaults synchronize];
return YES;
}
//
应用程序启动次数+1
int appLaunchTimes = [[defaults
objectForKey:kAppLaunchTimesKey]
intValue];
[defaults setObject:[NSNumber
numberWithInt:++appLaunchTimes]
forKey:kAppLaunchTimesKey];
[defaults synchronize];
CYBLog(@">>>>>pre——Login11-3---启动次数%d",appLaunchTimes);
return
NO;
}
AppDelegate.m中使用
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if ([AppDelegate
isFirstLaunching]) {
//引导页
AppGuideViewController *appGuideVc = [[AppGuideViewController
alloc]
initWithNibName:@"AppGuideViewController"
bundle:nil];
UINavigationController * navigationVc = [[UINavigationController
alloc] initWithRootViewController:appGuideVc];
self.window.rootViewController = navigationVc;
return YES;
}
}
相关文章推荐
- APP空中升级原理
- jenkins打包Built-By的值修改为Administrator
- WIN7下VC6.0无法使用打开文件功能(Unable to register this add-in because its DLLRegisterServer return an error)
- php笔记之GD库图片创建/简单验证码
- golang: Go语言:简介
- 装载问题-算法(回溯法)
- Optimizely - A/B Testing brief intro
- 面向切面(AOP),原理是什么
- php-fpm进程数优化方法
- Linux下安装过程中编译PHP时报错:configure: error: libjpeg.(a|so) not found
- Windows 安装openssl
- Android自定义View:水平带数字百分比的进度条
- JavaWeb系列-JDBC
- JavaWeb系列-JDBC
- JavaWeb系列-JDBC
- android Spinner控件详解
- c# 【MVC】WebApi开发实例
- php框架练习
- C++ STL 基础及应用(7) 函数对象(仿函数)
- ORA-00600: internal error code, arguments: [13013], [5001], [267], [8455677], [0], [8455677], [17],