Apple Push Notification API Not Throwing Error With Bad Device Token - php

I'm currently setting up an apple push notification server for my app and I have a question regarding apple's responses. It's my understanding that the new push notification api (http2) allows you to receive instant feedback for each message sent through the service, and for the most part that seems to be true. However, I'm running into the issue that when I go into my iPhone's settings and remove the app's ability to send notifications apple still returns a '200' http2 response code, not the error '410' like it should. What would be a reason why it would still give the '200' response?

Related

Migrating GCM to FCM, should/could I keep my current GCM server side of code?

I've been using GCM service to send notification to my existing App, in PHP server, as per https://stackoverflow.com/a/11253231/3286489.
Now I'm thinking of migrating to FCM. As per noted https://stackoverflow.com/a/37517339/3286489, the notification service URL "https://android.googleapis.com/gcm/send" has been changed to "https://fcm.googleapis.com/fcm/send"
As I'm still newly explore the FCM, I hope my question is not dump. I have two questions here.
1.) Once migrated to FCM in my client, can I still use back the same PHP code that send my GCM as per https://stackoverflow.com/a/11253231/3286489? Or could I just change the API URL (to fcm.googleapis.com) but retain all PHP code the same? (i.e. is 'https://fcm.googleapis.com/fcm/send' backward compatible with 'https://android.googleapis.com/gcm/send'?)
2.) Upon migrated to FCM (on the server push), and even when after I have upgraded my App to use FCM instead of GCM, I believe there will still be some user that's stick to the older App for a while using GCM. When I send push notification out, do I need to send to both FCM and GCM separately (i.e. I need to keep the old GCM server code for a while)? or I just need to send the FCM, and my old App (with only GCM) will still receive it?
I hope the answer is yes for both, but feel like not likely it's yes. So write to confirm my understanding.
The answer to both is Yes.
For #1, my post that you linked pretty much answers it. So just to confirm, using the FCM endpoint to send towards your GCM users should be fine. It's still compatible.
For #2, no need to send separate payload for GCM users. As I said above, it is backwards compatible.

Getting "InvalidTokenFormat, Error 400" from Firebase Cloud Messaging

I am using Firebase Cloud Messaging for my android development with PHP as server side language. Right now, i'm able to :
Receive push notification sending using Firebase Console either both real apps and emulator.
Got it working when testing it out from terminal(curl)
So then, i tried sending from apps server(using php curl) instead of Firebase Console. And right now, encountered this weird message InvalidTokenFormat, Error 400 every time i'm request the POST request. Any thought?
Here is the link for Firebase Api were made : FirebaseApi Class
Feel free to ask for any inputs from meif above use case didn't clear enough. Thanks.
My mistake. The url should be(without slash at the end) :
https://fcm.googleapis.com/fcm/send
you need to send request to the firebase from your server with message of the notification and the token of the users then firebase will accept the request and broadcast the message to all the users (tokens that we provide) in form of a notification .
Firebase and device works on poll model, hence only firebase can send notification on your device , you can setup your poll with the device but google does not allow that because if each and every app starts to make a poll tunnel with the device , it will take up whole lot of resources.
Can you Post the raw request curl sends to the server? Normally curl does provide a printout for that, not sure about the php version.
CURLOPT_POSTFIELDS does not want a JSON. if you want to send a application/x-www-form-urlencoded request, use http_build_query($message) , or if you want to send a multipart/form-data request, give it the $message array directly.

Apple Pushnotification Feedback service

I have a problem with IOS push notification. I am using php(Zend) as a provider. I have tested the notification in below scenarios:
1) Installed app in my iPhone and sends the device token to server and it is successfully stored in database. Then i have fired a notification, and i have received notification.
2) Then i have uninstalled the app from device and fired a notification. In this scenario APNS doesn't returned any error message. Feedback service also not gave any invalid tokens (Device has other apps which has push notification enabled).
3) Installed app again then send the notification. Now, The notification is successfully sent.
So my question is, why apns not returned invalid token when app is uninstalled from the device. Why feedback service not returned any invalid tokens?
Thanks in advance
When you uninstall an application, it does not get de-registered from the push server. So, this is normal behaviour. You won't get any invalid token error.

Push Notification using GCM - PHP

I am trying to implement Push Notification using GCM,
Besically i am trying to send Notification to the GCM using my PHP server which will deliver it to my android application.
I have used code at androidhive!
The device is getting registered successfully but i am not receiving any notification at my device nor anything is visible at Google console.
I am not receiving any response from the link used https://android.googleapis.com/gcm/send or https://android.googleapis.com
Is there anything wrong in this approach?
Can anyone suggest me any authentic source for this?
Realizing that some people are facing issues implementing GCM. I have decided to post solution.
The example on AndroidHive is working perfectly. Its just the matter of correct configuration.
Replace project ID in Android app. (You can get project ID from you google's console link i.e google.com/apis/console/#project:xxxxxxxxxxxx:access)
Replace Server API Key on PHP Server(config.php)
Key for server apps (with IP locking).
You can get your IP from WhatIsMyIP.
Key for browser apps (with referers) will not work.

C2DM and PHP Server

I'm trying to write the server side of my android app that uses C2DM. I'm going to write it in php. I basically am just doing tests right now. I copied the chrome to phone example for the actual android app and modified it to my liking. Right now my biggest question is the registration.
Let me get everything straightened out.
When registering the device for the first time, the app talks directly to my server. The server grabs the deviceid and responds back with a 200. Right?
So, on the php side of things, I grab the device id like $deviceid = $_POST['deviceId'] Right?
add it to my database. then respond back to the app.. How exactly do I send a particular response back? I assume in the header? I'm unsure how to do that.
Please confirm or deny that I'm on the right track and clear up any confusion.
Thanks for the help.
You don't respond back to the app. You must register your server with google's servers to get a server authentication token. You then use that server token and the device token in a post request to google's C2DM service to have google's servers send a push notification to the phone. Your app and your server never directly communicate when a push notification is sent in C2DM, it is all done through google, yet you need to implement a mechanism for your server to know the device id of the device it wants to send a message to.
This is a pretty detailed guide, though the server code is in Java:
www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html
Make sure you have really gotten the IDs before sending to the server. If you are using an emulator for testing, you could do an echo over at the php script so the message will appear in your logcat.
Google refreshes expired registration IDs so your application should be able to pick up new notifications/ids from google and handle the message by sending to the database.

Categories