Reputation: 8484
We are having some trouble with our push services here.. Our app has been on AppStore for a while, and we wanted to try out our Push for the first time. Not to send to everyone, just to my device.
We followed this guide for setting everything up, and it worked perfectly during development. Later, we did the same thing with distribution when the app went live on AppStore. (perhaps not in that order)
Anyway, we never really tested the push after it went live (our service is kind of a news-service, and is supposed to send a notification to ALL devices when we choose to). I ran a debug to register my device's token in a different sql-table than the rest, and re-downloaded out app directly from appstore. I do not get prompted for registering for notifications, but I know I did this the first time, and I can even see it in Settings.
I used our .php website to send a message to 'all' devices in the table (currently only my device), and I go nothing. I downloaded the same app on my iPad, and the token was added to the database, sent a new message, and none of them received it.
We added my colleague's token to the same database, he downloaded the app from AppStore, sent the message to all devices in the new table(now three devices), and only HE got the message.
His phone might contain some of the earlier important profiles, but this is all in production, and that shouldn't have anything to say, right?
I now have NO clue what to do. I figure either both my iPhone and my iPad are broken or ignored by the push service, OR my colleague's phone is the only device that will ever receive a notification from this service..?
When I use .php-code to fwrite
and send the notification to gateway.push.apple.com, it returns that it successfully sends the message to all devices (but this is also the case even if the app has been deleted from the device.)
I made the .pem file myself, from a newly created request/key/profile etc. from my machine.
Is there a reason why our push service does not send to my devices? Or so far only to his? Could it have anything to do with certificates, provisioning profiles, keys etc?
EDIT
We have now been trying a whole buch of stuff, and it kind of works now
, but I have NO IDEA what happened, and how it works now.
What we did: My colleague opened his XCode-project, and set everything to Release, and pressed Build. He sent me the AppName.app, and I dragged this to iTunes, and told it to install that app. (The only difference between the AppStore-version and the Xcode-version now, is that DeviceTokens should be registered in another table, as I mentioned earlier). When I launched the app, I noticed that a fourth Token was registered. What I mean by that is that the deviceToken of my device had changed. I know that this happens from time to time, but it shouldn't be a problem. When I tried sending a notification with the new app and the new token registered, I received it. If I UNINSTALL the version he sent me, and re-download the AppStore-version, and send a notification to the NEW device-token, I now receive it.
How?
If I cross check the device tokens in the new with the old table, they are both on both. The method I used to get a hold of my Device Token in the first place was to build my project with a different url somewhere in it, and I had to delete the AppStore-version first. When running this 'new' xcode-version, it spit out a new token that was never registered with the AppStore-version, so when I tried to reinstall the AppStore-version and send a notification to only that token, it never came through - because the 'current' deviceToken was hidden in the original table, and not in the new one.
The new question:
Why would my deviceToken change from one build to another?
To make a clearer image of what I think happened:
1. AppStore-app launch - Table.regDeviceToken = 111;
2. AppStore-app launch2- Tabke.regDeviceToken = 222; //(it updated itself)
3. Xcode launch - Table2.regDeviceToken = 111; //This is the Token I found and used
4. AppStore-app lauch4 - Table1.regDeviceToken = 222 //This is hidden from me, I thought it would be 111.
5. Send push to Table2.DeviceToken=111; //Which does not work
6. Send push to Table.DeviceToken = 222; //Which works
So, when launching the app in Xcode, I got the OLD DeviceToken. Why would this happen?
Upvotes: 2
Views: 839
Reputation: 8484
Okay, after a lot of headaches due to this problem I have finally found the answer. Our service has functioned properly this whole time.
When I was acquiring my device Token using my Xcode-project, I got a device token made for Development. When I then tried to send a push-notification to this token using our AppStore-app, it did not come through.
When I got the AppName.app file from my colleague, it obviously was in Production/Release-mode, and thus giving the database a DIFFERENT deviceToken.
Bottom line: An application gives different deviceTokens for Debug vs Release.
Upvotes: 1