1

I am trying to migrate an existing app to use FCM. I took the APNS token and sent it to the "batchImport" service, using curl:

curl -H "Authorization: key=<auth key>" -H "Content-Type: application/json" -X POST -d "{\"application\": \"com.myco.myapp\", \"sandbox\": false, \"apns_tokens\": [\"410564ffd0aaf91dd06e8ab7b8362238e2c7f1bbd5a520d6afaff38c9b670a90\"] }" https://iid.googleapis.com/iid/v1:batchImport

I receive a "registration_token" in response. When I then try to use that token to request a push notification, it does not arrive on the device. Here's the curl from that:

curl -H "Authorization: key=<Auth key>" -H "Content-Type: application/json" -d "{\"to\":\"<registration_token_from_above>\", \"notification\":{\"body\":\"First\", \"title\":\"Num 1\"}}" -X POST https://fcm.googleapis.com/fcm/send

I am also unable to send from the "Notification" tool in the Firebase console.

I created a second project from scratch from the example here: https://github.com/firebase/quickstart-ios.git . This one works from both the Firebase console and curl.

Is there something magical happening in the Firebase client code that doesn't happen when I use the batchImport service? If so, how in the world would you migrate from a different service to FCM?

  • Tokens generated from batch import should work as all other tokens, when you use curl to send to the token from batchImport what is the response you get? – Arthur Thompson Jun 27 '16 at 16:40
  • Here was the response `{"results":[{"registration_token":"cpy8GQmQSFE:APA91bFcOVrbT88MUEhWCTs5E9","apns_token":"410564ffd0aaf91dd06e8ab7b8362238e2c7f1bbd5a520d6afaff38c9b670a90","status":"OK"}]}` – HammondSuisse Jun 27 '16 at 19:22
  • Sorry I meant the response you get when you use the registration_token to send a downstream message to the device. – Arthur Thompson Jun 27 '16 at 20:03
  • It's all smiles when requesting a notification to the device: `{"multicast_id":6605894166055572393,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1467040269913059%c6939f07c6939f07"}]}` – HammondSuisse Jun 27 '16 at 21:02
  • In that case I don't think the issue is with the registration_token, but either with FCM mapping the token to the appropriate APNs token (unlikely but possible) or there is an issue with how the client is set up to receive the notification. Could you add your request to send and your code to receive the notification to the question? – Arthur Thompson Jun 27 '16 at 21:25
  • I'm requesting to send via the second `curl` command above. To receive, I am using the native iOS events. This is a working app that receives notifications now. I chose this one as an example of how I might be able to migrate to FCM, and to avoid silly mistakes of mine when trying to code up a test app! – HammondSuisse Jun 28 '16 at 16:10
  • This particular app has no notification-handling code - it's just supposed to open when the user taps on the notification. I don't see these notifications appearing when sent through FCM. – HammondSuisse Jun 28 '16 at 16:19
  • FCM does require some code to setup notifications on iOS, see the github sample you tried for registerForRemoteNotifications in the AppDelegate. – Arthur Thompson Jun 28 '16 at 16:22
  • @HammondSuisse could you fix the issue? I am having the same problem. – MatayoshiMariano Dec 20 '16 at 18:46
  • MM, see the below comment about using the priority attribute. This was the solution for me. – HammondSuisse Dec 22 '16 at 14:04
  • @HammondSuisse - in your batchimport curl, where do I find auth key? I mean which key is that? – kragekjaer Oct 04 '19 at 22:57

3 Answers3

1

Add "priority":"high" in your downstream curl command; Please also note "title" is not supported on iOS devices.

Robbert
  • 26
  • 1
  • This was exactly the issue. When supplying priority:high, this started working. Does anyone else think this should be the default??? In the iOS world, the equivalent priority setting defaults to high (10): [link](https://developer.apple.com/library/prerelease/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html) – HammondSuisse Dec 10 '16 at 22:34
1

Another possible problem sending notifications using tokens created with batchImport: be careful to set the sandbox parameter correctly. My notifications were being rejected with all kinds of strange errors—invalid token, token not registered, invalid APNS credentials—until I set sandbox: true.

Tom K
  • 430
  • 5
  • 22
  • Apple uses two servers for Push Notifications- Sandbox & Production. If you run the app using Xcode while development it always creates a development build(sandbox). If you create an IPA with Apple Store/AdHoc option it creates a production build while the Enterprise/Development option creates development build. You can check the aps-environment flag in the IPA summary while building IPA to confirm if APNS is pointing to development (sandbox) or production. This took me almost 3 days of troubleshooting to realize this. – KPS250 Nov 29 '19 at 07:56
0

How does it work?

Found this on the Firebase docs:

An FCM implementation includes an app server in your environment that interacts with FCM via HTTP or XMPP protocol, and a client app. Additionally, FCM includes the Notifications console, which you can use to send notifications to client apps.

Firebase Notifications is built on Firebase Cloud Messaging and shares the same FCM SDK for client development. For testing or for sending marketing or engagement messages with powerful built-in targeting and analytics, you can use Notifications. For deployments with more complex messaging requirements, FCM is the right choice.

How in the world would you migrate from a different service to FCM?

There's a full Migration Guide for iOS in the docs.

Import your GCM project as a Firebase project

1.In the Firebase console, select Import Google Project.

2.Select your GCM project from the list of existing projects and select Add Firebase.

3.In the Firebase welcome screen, select Add Firebase to your iOS App.

4.Provide your bundle name and optional App store ID, and select Add App. A new GoogleServices-info.plist file for your Firebase app is downloaded.

5.Select Continue and follow the detailed instructions for creating an xcworkspace file for your app and connecting to Firebase on startup.

Community
  • 1
  • 1
ReyAnthonyRenacia
  • 17,219
  • 5
  • 37
  • 56
  • Thanks, but my question about migration is around the handling of tokens. I am using `curl` to simulate the role of the server before I go and build a real server. So, if I have an existing app that has registered its APNS tokens in our on-prem database for our existing solution, it looks as though I'm supposed to use the batchImport service call to translate those into registration tokens. However, when I test, I don't see that those tokens work for sending notifications. So, is it mandatory in some way to also use the client API on the client **and** batchImport from the server? – HammondSuisse Jun 27 '16 at 14:31
  • I'm not totally familiar with your procedure. But you can always give [GCM iOS](https://developers.google.com/cloud-messaging/ios/client) a look, handling of registration tokens is mentioned in detail :) – ReyAnthonyRenacia Jun 28 '16 at 01:24