Flutter FCM iOS Issue



APNS设备令牌在检索发件人ID"的FCM令牌之前未设置。此FCM令牌的通知将不会通过APNS传递。请确保在设置APNS设备令牌后重新检索FCM令牌。

我遇到此错误。我不知道该怎么解决。你能帮我吗?

谢谢。

尝试在真实设备上运行

试试这个:

AppDelegate.swift

import UIKit
import Flutter
import Firebase
import FirebaseMessaging
import UserNotifications
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
var firebaseToken : String = "";
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
Messaging.messaging().delegate = self;
FirebaseApp.configure()
GeneratedPluginRegistrant.register(with: self)
Messaging.messaging().isAutoInitEnabled = true;
self.registerForFirebaseNotification(application: application);
return true;
// GeneratedPluginRegistrant.register(with: self)

}
override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken : Data){
print("X__APNS: (String(describing: deviceToken))")
Messaging.messaging().apnsToken = deviceToken;
//Messaging.messaging().setAPNSToken(deviceToken, type:MessagingAPNSTokenType.prod )
}

override func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("X_ERR",error);
}

func registerForFirebaseNotification(application : UIApplication){
//    Messaging.messaging().delegate     = self;
if #available(iOS 10.0, *) {
//UNUserNotificationCenter.current().delegate = self ;
let authOpt : UNAuthorizationOptions = [.alert, .badge, .sound];
UNUserNotificationCenter.current().requestAuthorization(options: authOpt, completionHandler: {_, _ in})
UNUserNotificationCenter.current().delegate = self ;
}else{
let settings : UIUserNotificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)                
application.registerUserNotificationSettings(settings);
}
application.registerForRemoteNotifications();
}
}
extension AppDelegate : MessagingDelegate{
func messaging(_messagin : Messaging, didRecieveRegistrationToken fcmToken : String){
self.firebaseToken = fcmToken;
print("X__FCM: (String(describing: fcmToken))")
}
func messaging(_messagin : Messaging, didRecieve remoteMessage : Any){
//self.firebaseToken = fcmToken;
print("REMOTE__MSG: (remoteMessage)")
}
func application(_ application : UIApplication,didRecieveRemoteNotification uinfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void){
print("WITH__APN: (uinfo)")
}
}

podfile

target 'Runner' do
use_frameworks!
use_modular_headers!
#  pod 'FirebaseFirestore', :git => 'https://github.com/invertase/firestore-ios-sdk-frameworks.git', :tag => '7.11.0'
pod 'Firebase/Auth'
pod 'Firebase/Analytics'
pod 'FBSDKLoginKit'
pod 'Firebase/Messaging'
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

pubspec.yaml

cloud_firestore: ^2.0.0
firebase_auth: ^1.1.2
firebase_core: ^1.1.0
firebase_messaging: ^9.1.3
flutter_local_notifications: ^5.0.0+3

最新更新