Sending IOS notifications from Firebase (or anothe

2019-06-14 09:26发布

问题:

We are currently able to send notifications to specific Android devices through Firebase and I am trying to do the same to IOS devices.

We use POD and have installed

pod 'Firebase/Core' 
pod ‘Firebase/Messaging'

We've created an account with Firebase.

I have added the functions that correspond to AppDelegate.swift. After executing the app, I can send notifications from Firebase to all iPhones... but no specific ones.

In production, I have the following

  FIRInstanceID.instanceID().setAPNSToken(deviceToken, tape: FIRInstanceIDAPNSTokenType.prod)

Up to here, all good .. but when I try to get the token from a user and then send a notification only to that device... the notification does not arrive

The token is generated without any problems.

if let refreshedToken = FIRInstanceID.instanceID().token() { 
 print(“InstanceID token: \(refreshedToken)”) 
 }

From firebase The notification is sent and does not show errors.. but the notification never arrives to the actual device.

Can this be done with Firebase? Is there any other service that would allow me to do this?

UPDATE

I send message for console

click open image

回答1:

On Android, Firebase has the luxury of using GCM directly. For Apple, FCM messages need to be sent to Apple Push Notifications.

Make sure you have setup the backend by downloading your APN Key and uploading to your Firebase console:

Download: https://firebase.google.com/docs/cloud-messaging/ios/certs

Upload: Open your Firebase console, click on the gear icon in the upper left, click on Project settings and then the Cloud Messaging Tab. Upload your APN key there.

You should be able to grab the FCM device ID from the debug output console when Firebase starts up (when running the app in debug mode).



回答2:

You need to update your Firebase pod and add code from this answer to your iOS Application-

Working Firebase Messaging Code for iOS App