Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Cloud Messaging with Xcode 7 and iOS 9

I've managed to use GCM with Android devices, but now I'm trying to implement on an iOS app.

I think I followed all the necessary steps to be able to use the GCM service. I've followed the https://developers.google.com/cloud-messaging/ios/client?configured=true to add the service to an existing app.

I think that everything is configured correct but I'm not able to receive any notification. I have the APN certificates and the GoogleService-info.plist file, on the console this is the output:

2016-01-05 13:47:53.864: GCM | Invalid key in checkin plist: GMSInstanceIDDeviceDataVersion Connected to GCM 2016-01-05 13:47:57.501: GGLInstanceID | Invalid last checkin timestamp in future. 2016-01-05 13:47:57.501 TerneraGallega[1014:444977] Checkin successful with authId: 4958686017822257121, digest: KSJNg+Aj82uavBXrFeOAfA==, lastCheckinTimestamp: 1451998077000 Registration Token: nC-dd9fCvFs:APA91bHMfbvLczxSPLQsLeEJASU_RfV4wvVuPs2u4VJDtpC8oB2cm1AKr6cH_LFeLsQzb94Kk9iwez8fsOvgzNns_9DU3i8Ema1oCKIwcNFzenNpAhViyGHah4E7-RkQlg1durYSEQRD Already subscribed to /topics/global

As soon as I receive this if I made a POST request with:

{ "to" : "nC-dd9fCvFs:APA91bHMfbvLczxSPLQsLeEJASU_RfV4wvVuPs2u4VJDtpC8oB2cm1AKr6cH_LFeLsQzb94Kk9iwez8fsOvgzNns_9DU3i8Ema1oCKIwcNFzenNpAhViyGHah4E7-RkQlg1durYSEQRD", "content_available" : true, "notification" : { "body" : "great match!", "title" : "Portugal vs. Denmark" } }

The first attempt it returns a success message but no log nor notification is shown in the device (with the application on the foreground)

After a few minutes, on another try of the POST request now it returns a failure with

{ "multicast_id": 7256343774952522277, "success": 0, "failure": 1, "canonical_ids": 0, "results": [ { "error": "NotRegistered" } ] }

Now, I downloaded the GCM Example from the Google page, configured the APN and also got the GoogleService-info.plist, when launching the GCM Example Swift file as soon as it opens on the device it says:

Registration Succesful! Check the xcode debug console fot the registration token that you can use...

After this, if you set a POST Request with

{ "to" : "mVEtHyTXEOg:APA91bGvK_Uf2ZKgpguWUOto3CXQzIT1z22uJ446mYkNqMwL9VLDYdGtdm_4vS8rcl3T9OeqEC1UWbdKAOyuoweW1GiU0mv0cDSPW03y4XGx19JcR6rxsiWRNUjtADX6iNAW8wM8UBJl", "content_available" : true, "notification" : { "body" : "great match!", "title" : "Portugal vs. Denmark" } }

it again returns a

{ "multicast_id": 7435981433811133310, "success": 0, "failure": 1, "canonical_ids": 0, "results": [ { "error": "NotRegistered" } ] }

Can someone who has implemented GCM on an app could point me what I'm missing?

-------EDIT-------

Finally I've made it work by using a distribution certificate instead of a development certificate... it seems that I have all good configured but I'm missing something with the development certificate.

PS: In the APN Profile page under ID I have enabled both Push notification certificates (that's why I thought that everything was good configured)

But I'll leave this question open because I'm unable to use this under development circumstances

like image 417
neteot Avatar asked Jan 05 '16 13:01

neteot


1 Answers

I was able to do effectively the same thing as the fix in your edit without messing with the certificates. Obviously this won't work if you already have everything setup, and are using both the development and production environments, but if you're just in the development stage it's easy enough to change.

In the Gcm example project (for objective-c) in application: didRegisterForRemoteNotificationsWithDeviceToken I simply changed the code from:

    _registrationOptions = @{kGGLInstanceIDRegisterAPNSOption:deviceToken,
                             kGGLInstanceIDAPNSServerTypeSandboxOption:@YES};

To

    _registrationOptions = @{kGGLInstanceIDRegisterAPNSOption:deviceToken,
                             kGGLInstanceIDAPNSServerTypeSandboxOption:@NO};

I understand this isn't exactly a real fix, but it at least made it work without changing any certificates (as long as the production certificate is setup.

like image 95
jrobe Avatar answered Nov 09 '22 09:11

jrobe