iOS push notifications to large number of users - iphone

I saved users' device tokens in database.
At the time to push notifications,I loaded all device tokens from database,then in a loop,I send push message to one user one time.
Now there are about 300 thousands users,I want to know,is there any other better way?
Thanks

There is no better way with Apple. You need to send the same message to each device token. Services like Parse.com will mask this behind the scenes dirty work for you by letting you broadcast to groups of devices, however you still need to subscribe each device token to the group initially...
So, to answer your question, no there is no better way, you must loop and send to all device tokens :(.

Related

How to check if a person in your iPhone contact list has an app installed?

I want to allow people to privately share data with each other using their contacts list to select people to share with. I'm planning on using Push Notifications to notify others that they have been shared with, but how can I handle those that do not have the app installed?
The cases are that I have their phone # and/or email. I can simply send them a message saying "X wants to share Y with you", but how can I determine if I need to send a Push Notification or an email/text?
If you're looking for API then you're out of luck. You can always collect this personal data server-side with agreement of your users. There you can also manage groups and other community relations.
Check here:
https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html
The crux of it though will be that you will need to store a token when the device is registered anyway to be able to send notifications to them, so you can use that.
And using The Feedback Service alluded to in the documentation, you can remove the token, should it fail too often.
But, as rokjarc said, if you're expecting a third-party API to exist, you're pretty much out of luck. Apple ahs done most of the work for you already anyway.
When the app registeres for push notifications you need to pass additional data to your server. The user could input their own email/phone which will be sent to the server so that users can find each other. The email/phone can be stored alongside with the push token. When someone wants to share something, you would search the corresponding push token in the database and send the notification through APNS. Note there can be multiple push tokens for one email or phone i.e. when a user has multiple devices.
The users of your app should be aware of the data which is stored on your server and should have the option to delete it. Also use the APNS feedback service to detect and remove invalid push tokens.

Sending push notification from device to all contacts

I have an app where I would like to select a user in my contacts. If that person has my app installed, then I would like to send some data that is relevant for this app using a notification. The other user gets the notification, and acts on it within this app. Is that possible? I am thinking that if I can identify that users device, I can store this message in a server. When the user connects to the app, it will retrieve and get this users message from the server. But question is can I identify other devices like this, from my contact list. Can I send this notification using phone number instead of device id?
Please help.
Thank you,
Anks
No, you cannot. You have to have the Apple Push Token for a device and the user has to have notifications turned on to be able to receive notifications from Apple Push.
You would need to maintain a server side database linking the APNS Token to a specific user account. There are a lot of dots to connect with this kind of implmentation. Your better bet would be maintaining a "list of contacts" within your App to link contacts to.

"Push notification" - feedback, uninstall application

Apple push notification - Feedback Service
How do you know when the user uninstalls your application? so that you can remove their devicetoken from the push server.
You simply don't know. You can grab device identification string which is presumably identical for the same application token string, and track if a token has changed for the specific device. So you can update the device token with a new one, but there is no way to find out if your app was removed from a device.
Update:
You are correct. You can get this information from the feedback service, however there is a caveat. You need to have at least one push-messaging enabled application installed to maintain persistent feedback connection. I'd mark these customers as potentially non-existant, but I wouldn't remove these folks from a customer DB. Who knows why your push message can be rejected. Your device may be in inconsistent state and you remove your subscriber forever. If you have 10k zombie clients it is a pocket change for a DB. If you lost 100k clients you have much serious problems than that.

Push Notification Alternatives

I heard that push notification is not reliable. What could be the alternative for this?
The use case I am trying to handle is:
1. I have a app which will be shared by three kind of groups. Each group contains certain set of persons.
2. A request is submitted by first kind of group and it will be serviced by second kind of group. So, all persons who are part of second group should be notified and no one apart from them should get the notification.
3. Similarly, A request is submitted by first kind of group and it will be serviced by third kind of group. So, all persons who are part of third group should be notified and no one apart from them should get the notification.
4. Even second group persons can submit a request to third group.
Please provide your thoughts as how should I handle these scenarios.
Push notifications rely on the network (3G/WiFi) presence to deliver the notification. Also, there is no response back from the Apple Push Notification Server which guarantee the delivery of the notification. Having said all these things... iPod touch is higly unreliable for delivery of notification because one, it do not have 3G; second, for saving battery its notifications are internally turned off for some time....
One Alternative to this is to keep polling the server in a background thread for any modification. But this will work only when app is running.
Another Alternative can be writing our own APNS kinda infrastructure.
you're right to say Push Notifications are not reliable.
For one thing, if the device is not connected to the internet, APNs only keeps one push notification to be sent when the device connects again (the last notification sent from the provider). Since there's no way to determine if a notification has been already sent or not after your servers sent them to APNS, you can't even try to queue the notifications on your end.
Other than that if your app depends on PN the user can easily break it's functionality by turning notifications off.
So you're absolutely right, if the data you want to send is critical, then you shouldn't use Push Notification. But I believe there's really no solution to your problem. you simply can't rely on them for your app to work.
I think the best approach would be like the email app for example, where you can download your emails when you start the app wether you have PN turned on or not, and the PN just notify you of new email, even though it's not guaranteed you'll get it at all.
There is no alternative, since Apple does some very low level communication. You would need to work together with the mobile providers to build something like the notification services.
That said, I don't think the service is not reliable. Maybe you should check your implementation.
You are right that APNs does not guarantee delivery: From their docs, they say that:
Important: Because delivery is not guaranteed, you should not depend
on the remote-notifications facility for delivering critical data to
an application via the payload. And never include sensitive data in
the payload. You should use it only to notify the user that new data
is available.

do i need to maintain a database for using push notification on my web server?

how we can maintain push notification for hundreds of devices? do we need to maintain a database on server or apple will maintain this,we just need to send payload.also i'm confusing in this matter that how do i cancel already sent payload...does someone knows about it?
You need to maintain your own database. The payload that you send to Apple includes the device token of the iphone you are sending the message to. Your table could contain as simple as an id for the user (auto-generated id, or email, or whatever you need), mapped to the iphone deviceToken, along with other columns and tables that you need for your book-keeping. The device token can be stored as String for simplicity, but it's really a 32-byte BLOB.
Once you send a payload, you cannot cancel or check its status. Once you send it, it's out of your hands.
I'd head on over to Urban Airship and play around with their implementation of Apple Push Notifications. They have a sample PHP application you can extend to fit your need and great step-by-step documentation on how to get your sample application up and running.
No, there is no way of canceling sent payload.