0
我正在iOS中使用Firebase實施推送通知。不幸的是,我遇到了Firebase未收到通知的問題。未在ios 10上收到Firebase通知
這是我得到的輸出中的錯誤:
****[Firebase/Messaging][I-FCM002019] FIRMessaging received data message, but FIRMessagingDelegate's-messaging:didReceiveMessage: not implemented****
請問該如何解決這個問題?我已經在iOS 9.3上測試過它,它工作正常。我使用下面的代碼:
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()
}
無法正常工作。我也實現了這個委託功能,但不顯示通知。 –
請點擊此鏈接: - https://github.com/firebase/quickstart-ios/blob/master/messaging/MessagingExampleSwift/AppDelegate.swift – Pushpendra