简体   繁体   English

在 IOS 中未收到 FCM 推送通知。当应用程序在后台或终止时。我使用 FirebaseMessaging 6.0.9 Pub

[英]Not Receive FCM Push notification in IOS.While app in background or terminate.I m use FirebaseMessaging 6.0.9 Pub

I m receive Fcm Push Notification in the foreground only.app not receive a notification while the app in the background and terminate .我仅在前台收到 Fcm 推送通知。应用程序在后台时未收到通知并终止

Swift Code Swift 代码

AppDelegate.swift AppDelegate.swift

import UIKit import Flutter import GoogleMaps import Firebase import FirebaseMessaging import FirebaseInstanceID导入 UIKit 导入 Flutter 导入 GoogleMaps 导入 Firebase 导入 FirebaseMessaging 导入 FirebaseInstanceID

@UIApplicationMain @objc class AppDelegate: FlutterAppDelegate { @UIApplicationMain @objc class AppDelegate: FlutterAppDelegate {

/// didFinishLaunchingWithOptions
override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
    FirebaseApp.configure()
    if #available(iOS 10.0, *) {
        UNUserNotificationCenter.current().delegate = self
        let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
        UNUserNotificationCenter.current().requestAuthorization(
            options: authOptions,
            completionHandler: {_, _ in })
    } else {
        let settings: UIUserNotificationSettings =
            UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
        application.registerUserNotificationSettings(settings)
    }
    let remoteNotif = (launchOptions?[UIApplication.LaunchOptionsKey.remoteNotification] as? [NSObject : AnyObject])
    if remoteNotif != nil {
        self.application(application, didReceiveRemoteNotification: remoteNotif!)
        UIApplication.shared.applicationIconBadgeNumber = 0
        self.window?.makeKeyAndVisible()
        return true
    }
    GMSServices.provideAPIKey("")
    GeneratedPluginRegistrant.register(with: self) //ragister plugin
    application.registerForRemoteNotifications() //register remoteNotifications
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}

 /// didRegisterForRemoteNotificationsWithDeviceToken
override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    Auth.auth().setAPNSToken(deviceToken, type: .unknown)
    Messaging.messaging().apnsToken = deviceToken as Data
}

 /// didReceiveRemoteNotification
override func application(_ application: UIApplication,
                          didReceiveRemoteNotification notification: [AnyHashable : Any],
                          fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    if Auth.auth().canHandleNotification(notification) {
        completionHandler(.noData)
        return
    }
    print(notification)
}
override func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
    print("Unable to register for remote notifications: \(error.localizedDescription)")
}


override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]){
    print("Murtuza")
}
override func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool {
    if Auth.auth().canHandle(url) {
        return true
    }
    return false;
}
// MARK: - UNUserNotificationCenterDelegate Method
override func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
    print(notification)
    completionHandler([.alert])
}


override func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
    print(response)
    completionHandler()
}

} }

Flutter Code Flutter 代码

_initFirebaseMessaging() {
    _firebaseMessaging.configure(
      onMessage: (Map<String, dynamic> message) {
        print('AppPushs onMessage : $message');
        _showNotification(message);
        return;
      },
      onBackgroundMessage: Platform.isIOS ? myBackgroundMessageHandler : myBackgroundMessageHandler,
      onResume: (Map<String, dynamic> message) {
        print('AppPushs onResume : $message');
        if (Platform.isIOS) {
          _showNotification(message);
        }
        return;
      },
      onLaunch: (Map<String, dynamic> message) {
        print('AppPushs onLaunch : $message');
        return;
      },
    );

    _firebaseMessaging.requestNotificationPermissions(
        const IosNotificationSettings(sound: true, badge: true, alert: true));
    _firebaseMessaging.onIosSettingsRegistered.listen((IosNotificationSettings settings) {
      print("Settings registered: $settings");
    });
  }

How can I solve this?我该如何解决这个问题?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 FCM iOS 推送通知收不到任何通知 - FCM iOS Push Notification cannot receive any notification Flutter iOS 应用程序在前台时的 FCM 推送通知 - Flutter FCM push notification for iOS when app is in foreground 设备休眠时 FCM 推送通知重新唤醒应用程序无效 - FCM push notification to reawaken app not effective while device slept FCM iOS 推送通知在应用程序终止时捕获自定义数据? - FCM iOS push notification capture custom data when app is terminated? FCM 推送通知与 angular service worker 不接收 - FCM push notification with angular service worker not does not receive Flutter FCM 推送通知在后台收到两个通知 - Flutter FCM Push Notification getting two notification in background FCM 推送通知 - 图片不推送 - FCM push notification - image not push Swift iOS 当应用处于非活动状态并运行代码时应用接收推送通知 - Swift iOS app receive push notification when app is inactive and run code 在 Kotlin 客户端应用程序中发送 FCM 推送通知 - Firebase 云消息传递 - Sending FCM Push Notification in Kotlin Client App - Firebase Cloud Messaging FCM 推送通知仅在应用程序处于后台时显示 - FCM Push Notifications are only displayed when app is in background
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM