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