アプリを起動していないときにPUSH通知を受け取り、通知領域をタップしてアプリを起動したときに、画面遷移させたいのですが、現状その方法がわからず困っています。
ログインしているかの情報をデバイスに保存しており、もしログインしていなければログイン画面に遷移
以下のサイトなども参考にしました。
参考
swift
1 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 2 3 //// アプリ起動時処理 4 // 最初の画面を準備 5 self.window = UIWindow(frame: UIScreen.mainScreen().bounds) 6 7 // ログイン判定 8 let defaults = NSUserDefaults.standardUserDefaults() 9 let isLogin: Bool? = defaults.objectForKey("isLogin") as? Bool 10 11 12 // 未ログインの場合 13 if isLogin == nil || !isLogin! { 14 //ログイン画面に遷移 15 let storyboard = UIStoryboard(name: "Login", bundle: nil) 16 self.loginNavigationController = storyboard.instantiateViewControllerWithIdentifier("LoginNavigationController") as! UINavigationController 17 self.window?.rootViewController = self.loginNavigationController 18 self.window?.makeKeyAndVisible() 19 20 } 21 // ログイン中の場合 22 else { 23 //PUSH通知経由でアプリを起動した場合 24 if(launchOptions == nil){ 25 let storyboard = UIStoryboard(name: "Ctab", bundle: nil) 26 self.CtabNavigationController = storyboard.instantiateViewControllerWithIdentifier("CtabNavigationController") as! UINavigationController 27 self.window?.rootViewController = self.CtabNavigationController 28 self.window?.makeKeyAndVisible() 29 }else{ 30 //PUSH通知ではなく、アイコンをタップしてアプリを開いた場合 31 let storyboard = UIStoryboard(name: "TabBarController", bundle: nil) 32 self.tabBarViewController = storyboard.instantiateViewControllerWithIdentifier("TabBarController") as! UITabBarController 33 self.window = UIWindow(frame: UIScreen.mainScreen().bounds) 34 self.window?.rootViewController = self.tabBarViewController 35 self.window?.makeKeyAndVisible() 36 } 37 } 38 39 //省略 40 41 //アイコンバッチを0にする 42 UIApplication.sharedApplication().applicationIconBadgeNumber = 0 43 44 return true 45
なにかありましたら、随時補足させていただきますので、
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/02/13 16:30
2016/02/13 17:28 編集