有效果的
/**
* 語(yǔ)法: #define 宏名 (變量值)
* 編譯器是使用完全替換的語(yǔ)法來解析
*/
#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" );
//顯示首頁(yè)
ViewController *vCtrl = [[ViewController alloc] init];
self.window.rootViewController = vCtrl;
}else{
//第一次打開
//顯示引導(dǎo)頁(yè)
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) {
//不是第一次打開
//顯示首頁(yè)
ViewController *vCtrl = [[ViewController alloc] init];
self.window.rootViewController = vCtrl;
}else{
//第一次打開
//顯示引導(dǎo)頁(yè)
GuideViewController *guideCtrl = [[GuideViewController alloc] init];
self.window.rootViewController = guideCtrl;
}
return YES;
}