web-dev-qa-db-ja.com

Firebase Messaging iOS 14.

私はしばらくの間私のアプリでFirebase Cloud Messaging Setupを持っていました。私は最近私のデバイスの1つをiOS 14に更新し、そのデバイス上でそれらを受け取るのをやめました。 IOS 13との異なる装置はまだそれらを受け取る。これがダムスワハであるならば申し訳ありませんが、ここに私のApp Delegateがあります:


let appDelegate : AppDelegate = UIApplication.shared.delegate as! AppDelegate


@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, MessagingDelegate {
    
    var customerId = ""



    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {


    application.registerForRemoteNotifications()

        FirebaseApp.configure()
        
        // Update this to your stripe PUBLISHABLE KEY
        STPPaymentConfiguration.shared().publishableKey = "private"
        
        let apiToken = "private"
        EasyPostApi.sharedInstance.setCredentials(apiToken, baseUrl: "https://api.easypost.com/v2/")
        STPTheme.default().accentColor = .red
        
        Messaging.messaging().delegate = self
        
        return true
    }

    // MARK: UISceneSession Lifecycle
    func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
        // Called when a new scene session is being created.
        // Use this method to select a configuration to create the new scene with.
        return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
    }

    func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
        // Called when the user discards a scene session.
        // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
        // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
    }
    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
      Messaging.messaging().apnsToken = deviceToken
        
    }
    
    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
      print(userInfo)
    print("test")
    }

    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
                     fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        print(userInfo)
        print("test")

      completionHandler(UIBackgroundFetchResult.newData)
    }
    
    func registerForPushNotifications() {
        // For iOS 10 display notification (sent via APNS)
        UNUserNotificationCenter.current().delegate = self
        let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
        UNUserNotificationCenter.current().requestAuthorization(
            options: authOptions,
            completionHandler: {_, _ in })
        // For iOS 10 data message (sent via FCM
        Messaging.messaging().delegate = self
        InstanceID.instanceID().instanceID { (result, error) in
          if let error = error {
            print("Error fetching remote instance ID: \(error)")
          } else if let result = result {
            print("Remote instance ID token: \(result.token)")
          }
        }
        
    }

}
 _

FireBaseコンソールの「テスト」ボタンの両方を使用してメッセージを送信しようとし、通常のようなメッセージを公開しました。通知に適切に登録され、設定を確認しても正しく表示されます。

10
Max S.

私は同じ正確な問題を持っていました。私が見つけた修正プログラムは、メソッドスリズリングを無効にすることでした。

  • IOSアプリinfo.plistに、FirebaseAppDelegateProxyEnabledを追加してfalseに設定します(ブール値0)

didRegisterForRemoteNotificationsWithDeviceToken設定がすでにあるように見えます。

お役に立てれば!

1
m179