Ich implementiere Push-Benachrichtigungen in iOS mit Firebase. Leider habe ich ein Problem, bei dem Firebase die Benachrichtigung nicht erhält.Firebase-Benachrichtigung nicht erhalten auf iOS 10
Dies ist der Fehler, den ich bin auf der Ausgabe bekommen:
****[Firebase/Messaging][I-FCM002019] FIRMessaging received data message, but FIRMessagingDelegate's-messaging:didReceiveMessage: not implemented****
Wie löse ich dieses Problem? Ich habe es auf iOS 9.3 getestet und es funktioniert gut. Ich verwende den folgenden Code:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
{
FirebaseApp.configure()
if #available(iOS 10.0, *) {
// 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 })
}
else
{
let settings: UIUserNotificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
application.registerForRemoteNotifications()
// Add observer for InstanceID token refresh callback.
NotificationCenter.default
.addObserver(self, selector: #selector(AppDelegate.tokenRefreshNotification),
name: NSNotification.Name.InstanceIDTokenRefresh, object: nil)
return true
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any])
{
print(userInfo)
}
func tokenRefreshNotification(_ notification: UIViewController)
{
if let refreshedToken = InstanceID.instanceID().token()
{
print("InstanceID token: \(refreshedToken)")
UserDefaults.standard.set(refreshedToken, forKey: "Device_token")
UserDefaults.standard.synchronize()
}
// Connect to FCM since connection may have failed when attempted before having a token.
connectToFcm()
}
// [START connect_to_fcm]
func connectToFcm()
{
Messaging.messaging().shouldEstablishDirectChannel = true
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)
{
//Tricky line
Messaging.messaging().apnsToken = deviceToken
//InstanceID.instanceID().setAPNSToken(deviceToken, type: InstanceIDAPNSTokenType.unknown)
print("Device Token:", tokenString)
}
func applicationDidBecomeActive(_ application: UIApplication) {
print("applicationDidBecomeActive ")
connectToFcm()
}
funktioniert nicht. Ich implementiere auch diese Delegiertenfunktion, zeige aber die Benachrichtigung nicht an. –
folgen Sie diesem Link: - https://github.com/firebase/quickstart-ios/blob/master/messaging/MessagingExampleSwift/AppDelegate.swift – Pushpendra