2017-08-15 3 views

答えて

0

は、データnotification.Storeプッシュが含まれているパラメータlaunchOptionsあるとfirstViewControllerでそれを処理しますopen.Iは私がswiftyJsonを使用し、1にシングルトンクラスでuserPushを取るappDelegateにこれらの行を書き込むことによって、それをやった:

guard let pushNotification = launchOptions? 
[UIApplicationLaunchOptionsKey.remoteNotification] else { return true } 
    print(pushNotification) 
    let data = JSON(pushNotification) 

    UserDataSingleton.sharedInstance.notificationData = data 
    UserDataSingleton.sharedInstance.userPush = 1 

は今私のsplashViewControllerに私がやった:

01:

override func viewDidAppear(_ animated: Bool) { 
    super.viewDidAppear(true) 

    if (UserDataSingleton.sharedInstance.userPush == 1){ 

     UserDataSingleton.sharedInstance.userPush = 0 
     let appDelegate = UIApplication.shared.delegate as! AppDelegate 

     appDelegate.handlePushNavigation(userInfo: UserDataSingleton.sharedInstance.notificationData!) 

    } 
    else{ 

    } 

} 

handlePushNotification iはAppDelegate内のすべての3例のために書かれているFUNCです

//MARK: - HAndle Push Notification Methods 

extension AppDelegate{ 

func handlePush(userInfo : JSON){ 

    handlePushNavigation(userInfo: userInfo) 
} 

func handlePushNavigation(userInfo : JSON){ 

    let storybard = UIStoryboard(name: "Main", bundle: nil) 

    switch userInfo["type"].intValue { 
    case 1: 

     guard let VC = storybard.instantiateViewController(withIdentifier: "ChatViewController") as? ChatViewController else{return} 

     navigateToVc(vc: VC) 

    default:break 

    } 

} 

func navigateToVc(vc:UIViewController){ 

    ez.topMostVC?.presentVC(vc) 

} 

}

関連する問題