Now Parse has decided to stop their remote push notification service, I'm looking for an alternative.
Of course I can move to Kinvey, which has a similar service, but you never know how long Kinvey will last (as a free service).
So, I was looking to implement my own independent and free solution for my app (both android and ios).
For android it seems pretty easy. I've just set up gcm for my project at https://developers.google.com/cloud-messaging/, and I received my GCM Sender Id and API key.
In my android app I can now easily register my android device for a device token with:
{$IFDEF ANDROID} PushService := TPushServiceManager.Instance.GetServiceByName(TPushService.TServiceNames.GCM); // Google Cloud Messaging PushService.AppProps[TPushService.TAppPropNames.GCMAppID] := <>; {$ENDIF} {$IFDEF IOS} PushService := TPushServiceManager.Instance.GetServiceByName(TPushService.TServiceNames.APS); // Apple Push Service {$ENDIF} PushServiceConnection := TPushServiceConnection.Create(PushService); PushServiceConnection.Active := True; DeviceToken = PushService.DeviceTokenValue[TPushService.TDeviceTokenNames.DeviceToken];
And from my php server I can now send a downstream message with:
$Request = curl_init(); try { curl_setopt($Request, CURLOPT_URL, 'https://gcm-http.googleapis.com/gcm/send'); curl_setopt($Request, CURLOPT_POST, 1); curl_setopt($Request, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization:key=' . <>)); curl_setopt($Request, CURLOPT_POSTFIELDS, {"registration_ids" : ["' . < > . '"],"data":{"message":"My message","title":"My title"}}); curl_setopt($Request, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($Request, CURLOPT_RETURNTRANSFER, true); $Response = curl_exec($Request); } finally { curl_close($Request); }
It all works (i.e. for Android)! The message is received in the PushServiceConnection.OnReceiveNotification event if the app is active or in the android's notification center if the app is inactive.
But howabout iOS? With the Delphi code above I actually get an APN device token, but how do I "translate" this to a GCM device token? Or what php code do I need to send a downstream message to APN?
Google gives some information at https://developers.google.com/cloud-messaging/ios/client, but this explanation is based on XCode and C++ and not Delphi. Has someone a Delphi explanation?
Note. I've already created a APN developer and production certificate.