1
アプリがアクティブまたはバックグラウンドのときにFCMを受信できます。アプリが動作していないときにFCMを処理するにはどうすればよいですか?
ただし、実行していないときは受信できません。
アプリケーション状態が実行されていないときにFCMを受信する方法を教えてください。 didFinishLaunchingWithOptions.Thereで
アプリがアクティブまたはバックグラウンドのときにFCMを受信できます。アプリが動作していないときにFCMを処理するにはどうすればよいですか?
ただし、実行していないときは受信できません。
アプリケーション状態が実行されていないときにFCMを受信する方法を教えてください。 didFinishLaunchingWithOptions.Thereで
は、データ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)
}
}