简体   繁体   中英

Why push notification directed to specific iOS device from Web API through Firebase FCM does not arrive?

I'm working with a remote web API developer, currently we're working to send push message from the server to iOS and Android device. We send our device token via OAuth API. (For iOS, device token is gotten from registering remote service with APNS service at AppDelegate launch). The weird thing is, Android can get the push notification, but iOS devices don't. But when I tried using the Firebase console -> grow -> notification -> New Message -> and target all the iOS device, all the iOS device registered to the push notification receive the push notification. Can you help me point out where the problem is? The web server is using nodeJs.

Things I have done, which I did according to this tutorial :

  • create new apps in Firebase project.
  • supply the same product bundle id to the app.
  • import google plist to the Xcode project.
  • supply development and production certificate .p12 to the app.
  • install Firebase/Core and Firebase/Messaging through Cocoapods.
  • use this code to register for remote notification (have tried both in target deployment iOS version 9.0 and 10.0, both yields the same result):

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.

    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 })
        // For iOS 10 data message (sent via FCM
        Messaging.messaging().delegate = self
    } else {
        let settings: UIUserNotificationSettings =
            UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
        application.registerUserNotificationSettings(settings)
    }

    application.registerForRemoteNotifications()

    FirebaseApp.configure()

    return true
}

From all this preparation, if I run the app in real iOS device, and then lock it, any message I broadcast to iOS device in the Firebase iOS app will shown in the lock screen notification. But not message from the web API that's directed toward the account logged in the app (which is directed to all the android and iOS device that logged in using that account -- it's shown on the android devices, but not on iOS devices).

I'm new to FCM. I usually use APNS. I probably don't know much about the terms to fix the server side as I don't understand nodeJs much, so if you have some suggestion about the server side, please be elaborate, so I can discuss it with the web API dev. Thanks for your help.

Turns out what I need to send to the server is not APNS token, but Firebase token, found in here:

https://firebase.google.com/docs/cloud-messaging/ios/client#monitor-token-generation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM