有效果的
/**
* 语法: #define 宏名 (变量值)
* 编译器是使用完全替换的语法来解析
*/
#define hasLaunch (@"hasLaunch")
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//判断是否第一次打开
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
BOOL flag = [ud objectForKey:hasLaunch];
NSLog(@"%@",flag == YES ? @"YES" : @"NO");
if (flag == YES) {
//不是第一次打开
NSLog(@"%@",flag == YES ? @"YES" : @"NO" );
//显示首页
ViewController *vCtrl = [[ViewController alloc] init];
self.window.rootViewController = vCtrl;
}else{
//第一次打开
//显示引导页
GuideViewController *guideCtrl = [[GuideViewController alloc] init];
self.window.rootViewController = guideCtrl;
[ud setBool:YES forKey:hasLaunch];
}
return YES;
}
没效果的
#define hasLaunch (@"hasLaunch")
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//判断是否第一次打开
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
BOOL flag = [ud objectForKey:hasLaunch];
if (flag == YES) {
//不是第一次打开
//显示首页
ViewController *vCtrl = [[ViewController alloc] init];
self.window.rootViewController = vCtrl;
}else{
//第一次打开
//显示引导页
GuideViewController *guideCtrl = [[GuideViewController alloc] init];
self.window.rootViewController = guideCtrl;
}
return YES;
}