2017-08-15 66 views

回答

0

是一个参数launchOptions包含推notification.Store数据和处理它在firstViewController你open.I通过的appDelegate写这行做了我所用swiftyJson并采取userPush在单例类为1:

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

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

现在在我的splashViewController我所做的:

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是FUNC我对所有3例AppDelegate中写道:

//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) 

} 

}

相关问题