1
当应用处于活动状态或背景时,我可以接收FCM。当我的应用程序未运行时,如何处理FCM?
但不能运行时收不到。
应用程序状态未运行时,如何接收FCM?
在didFinishLaunchingWithOptions.There当应用处于活动状态或背景时,我可以接收FCM。当我的应用程序未运行时,如何处理FCM?
但不能运行时收不到。
应用程序状态未运行时,如何接收FCM?
在didFinishLaunchingWithOptions.There是一个参数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)
}
}