app中新特性界面和主界面的邏輯關係處理

1 在app開發中,新特性界面的展現時間分爲兩個時間點:app

1) 程序第一次運行時(包括第一次安裝後運行,卸載再安裝後第一次運行);ide

2 )當程序發佈新的版本時ui

處理這個邏輯關係代碼通常寫在AppDelegate.m中的app啓動完成的方法- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions中。spa

常見代碼邏輯以下:開發

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {get

    //建立windowit

    self.window = [[UIWindow alloc] initWithFrame:kScreenSize];io

        //設置window的根控制器object

    self.window.rootViewController = [self pickViewController];select

        //使window可見

    [self.window makeKeyAndVisible];

    //保存當前版本到沙盒中

    [self saveAppVersion];

        return YES;

}

 

#pragma mark 加載新特性頁面和主頁面的邏輯判斷

//得到當前版本號

- (NSString *)loadCurrentAppVersion{

    NSDictionary *infoDict = [NSBundle mainBundle].infoDictionary;

    return infoDict[@"CFBundleShortVersionString"];

}

 

//將當前版本號保存到沙盒中

- (void)saveAppVersion{

    NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];

        NSDictionary *infoDict = [NSBundle mainBundle].infoDictionary;

        [ud setObject:infoDict[@"CFBundleShortVersionString"] forKey:@"appVersion"];

    }

 

//取出沙盒中的版本號

- (NSString *)loadSavedAppVersion{

    NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];

   return [ud objectForKey:@"appVersion"];

}

 

//根據版本號來判斷是否加載新特性界面,只有第一次加載或則版本號變化時才加載新特性界面

- (UIViewController *)pickViewController{

    if ([[self loadSavedAppVersion] isEqualToString:[self loadCurrentAppVersion]]) {

//跳轉到主界面

        return [[MYTabBarController alloc] init];

    }else{

//跳轉到新特性界面

        return [[MYGuideController alloc] init];

    }

}

 

2 通常在新特性界面的最後一頁,在展現完最後一頁新特性頁面時,都會跳轉到主頁面,通常有兩種方式跳轉到主頁面,一種是展現完新特性頁面後直接填轉到主頁面;還有一種是在最後一頁新特性頁面中,建立一個體驗按鈕,經過點擊體驗按鈕而跳轉到主頁面中。絕大多數都是第二種經過一個體驗按鈕而進入主頁面,這種方式的常見處理方式是在建立的button中,添加一個target方法,經過這個方法來跳轉到主頁面,代碼以下:

 [enterBtn addTarget:self action:@selector(enter) forControlEvents:UIControlEventTouchUpInside];

- (void)enter{

    MYTabBarController *tabBarController = [[MYTabBarController alloc] init];

    //切換app的根控制器

    [UIApplication sharedApplication].keyWindow.rootViewController = tabBarController;

}

相關文章
相關標籤/搜索