Does iOS distribution push notification need device token - ios

I've used the following tutorial to implement push notification in my app.
http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1
And it works for development version. But I had include a device token in the payload (php) file.
Does this need to be the same for distribution as well. Do I need to gather all the device tokens from active users and send distribution push notifications, one by one?
I thought I would be able to do a broadcast without keeping track of all active device tokens. Is this not the case?
App is already on app store by the way.
Thanks.

Yes, you have to keep track of their device tokens. Also keep in mind that the device token might change for a single device, even though that doesn't happen frequently.
If you think that's too much trouble, you can use some service like Parse.com to do that for you, using their SDK.

Related

Send message from php/mysql to iPhones

i am building a website which needs to send reminder messages to iOS (and Android) devices at certain times/dates. So not to a specific app on an iPhone, but to the iPhone itself.
like in the way the reminders app on the iPhone works: even when the app isn't active, reminders pop up.
For the last two days i've been googling on-and-off and reading about apns and firebase etc., but every script and tutorial understandably mentions tokens and id's that you need to receive from Apple and/or Android to get it to work.
One thing i can't find on google is: do i need to have an developer ID or something for this? I'm no xcode or swift programmer, i mainly work with php and query etc. and hopefully can avoid paying yearly for a developer license with Apple or Google.
Hopefully someone can point me in the right direction?
And surely any pointers to a good service or script to use is also very helpful. In the mean time i'll keep digging.
Thanks in advance for any help!
If you want to be able to run your app on an actual device you need to be registered developer, to be able to create certificates and provisioning profiles to sign your app with. You also need to be able to create certificates to be able to send push notifications.
You write that you want to send notifications directly to the phone. This isn't possible. All push notifications must be sent to an app. It doesn't matter if the app is running or not. Which makes sense. Otherwise you would be able to send push notifications to any iOS device out there...

iPhone act as Provider to APNs (Apple Push Notifications without third party server)

So my client wants an app that works like this:
one user presses a button on his device
other user(s) get a push notification
no third party server
So I have been looking into the Apple Push Notification Service but I don't want to have a third party "provider" server. Would it be possible for an iPhone to act as a "provider"?
I have already looked at this question which sounds like what I want to do but I am not satisfied with the answer. More specifically:
Would encrypting the APNs key with another key hardcoded into the app be secure enough? Any other ideas for dealing with that issue?
The tokens will always stay the same for a given app for a given device, right? If that's the case, I can deal with creating the token database. If that's not the case, my app won't work.
Will Apple accept such an app?
Would encrypting the APNs key with another key hardcoded into the app be secure enough?
I believe the main issue is you'll need to deliver APNS certificate and private key with your app, and renew it when needed (on all devices). Regardless of it being encrypted or not, if it is available for your app, it might become available for attacker (by dumping its plaintext representation from memory, or by disassembling your decryption code) and make it possible to impersonate your app. So no, it is not secure.
The tokens will always stay the same for a given app for a given device, right?
Not really. Documentation claims that a device token is not a unique ID that you can use to identify a device. Device tokens can change after updating the operating system on a device. As a result, apps should send their device token.
Will Apple accept such an app?
I believe there were no precedents because of the reasons above.

is there a way to check two device tokens are belongs to same device?

I want to get the device token of the device and want to send it to a server.Sometimes if I uninstall the app and install it again,Then the new device token which I got is different than previous.So,In my server there are two device tokens which are belong to same device.Can we avoid that?(In my service,I want to keep only one device token per one device)
Thank you.
If you doing this for push notification, you can use the feedback service from apple to detect if a device is deleted.
You can store a generated UUID and store it in the keychain like this. If you set it up right, it will persist between app deletes and reinstalls on the same device, but not across multiple devices via a restore from backup (unless you want that).

Same APNS token returned by two different applications

How can same APNS token be returned for two different applications installed using profiles created from two completely different apple enterprise accounts?
However the notifications are properly received by the respective applications! just curious to know how apple manages to map with correct device and the right application.
All apps on the same device get the same device token. Apple knows which app should receive the notification because the certificate you use to send the notification is unique for each app.
Seem like up to iOS 6, the token was the same for all apps on the same device, the way to difference them, it was the certificate.
From iOS 7+, the token is unique for each app and device. So every app on the same devices will get a different APNS token.

APNs duplicate tokens

We have a push notification server which holds the data (device tokens) for several different applications. With Apple wanting to stop people using the UDID as identifier, I was looking into changing this server so that it does not rely on UDIDs to identify devices any longer.
I understand that the tokens returned by APNs are not globally unique, but rather unique per device. However, when going through our database, I noticed that there are several cases (a few hundred on 750k+ registrations) where the same token is used for different devices.
So I'm trying to figure out what's causing this. At this point, I see 2 possibilities:
There is an obscure bug in our server registration handling somewhere
Apple recycles these device tokens (perhaps after a device reset?). We always store the last time a certain device registered, and I noticed that there are always at least several days between registrations of different devices with the same token. As far as I can tell, there are no tokens that are concurrently used by different devices.
I would really appreciate it if someone could shed some light on this.
What we know is that Apple tells us to use the Device Token to push notifications to a device. So, as long as you are:
Querying the APNs for a new device token every time the application is launching and registering it in your database
Querying the Feedback service for inactive devices and purging them from your database
... you are doing what Apple is expecting you to do.
However, I do suspect that there may be a bug in your registration code because 100/750k is a pretty high conflict rate. Considering these device tokens are used to push notifications, a lot of people would be complaining about receiving notifications that don't belong to them...

Resources