Send remote push notification to specific user - ios

I created a code to send remote notification using APNs, I created a development certificate, ssl, etc. The code worked very well, when I call my php script on my server, the script send a notification and my app on my iPhone show the notification.
But I have a doubt, this is a generic code, so this code will send a nofication to all iphones that has my app, but if I need to send a notification to a specific user? Like whatsapp for example? How can I inform to APNs what user that should receive the notification?

You will need either a new table to handle the user_id and its device token or add a column to the user table for device token. When you send a push notification, you can then send directly to the user device token which alert the user.
Some steps that you need to prepare will be a api endpoint to allow user to PUT or POST its device token to its account. Maybe something like api/v1/user/11/token. In your iOS side, you will then just call this endpoint to send the device token to the endpoint when the permission is accept.
I would suggest a separate table to handle the token because some user have different device like android and iOS. So if you want to alert both devices, is will be a lot easier to manage.

Get device token while registering for push notification, send that device token via API to server, then using that device token you would be able to target push notificaion to particular devices only.
Refer - Device Token not received when registering for remote notifications in Swift

Related

Get Device Registration Token iPhone before registering

Is it possible to get the device token (the one that is set in DidRegisterForRemoteNotifications) of an iPhone Device before you call registerForRemoteNotifications? If so, how can you do this?
I want to get this token and send it to my server. I may need to get this token before the push notification actually happens, in case the person doesn't allow push notifications at that time.
Thanks
No, you can't get the token before you request it. That is the purpose of the registration process.
You can't send push notifications until the user has allowed your application to receive them. The user may also withdraw permission for your application to show notifications at any time.
Calling -registerForRemoteNotifications is how you get the device token in the first place; . In fact, -application:didRegisterForRemoteNotificationsWithDeviceToken: is called in response to invoking -registerForRemoteNotifications. You generally do this inside of your -application:didFinishLaunchingWithOptions:, and no notifications will be delivered to the device until it has registered.
For reference, see https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW2.
Register your app’s supported interaction types as described in Registering Your iOS App's Supported User Interaction Types.
Call the registerForRemoteNotifications method to register your app for remote notifications. (In OS X, you use the registerForRemoteNotificationTypes: method to register your app’s interaction types and register for remote notifications in one step.)
Use your app delegate’s application:didRegisterForRemoteNotificationsWithDeviceToken: method to receive the device token needed to deliver remote notifications. Use the application:didFailToRegisterForRemoteNotificationsWithError: method to process errors.
If registration was successful, send the device token to the server you use to generate remote notifications.

Can provider send phone number along with device token to APNs server for push notification ?

iOS Device Token for the push notification is an opaque identifier of a device.
The provider can't get any device related information from the device token.
Based on Apple Push Notification programming guide, the provider needs to provide device token and payload to APNs server for the push notification.
Can provider send phone number OR bundle id OR advertising identifier OR vendor identifier to the APNs Server when the provider send token and payload to APNs server during push notification ?
So, the APNs server will not send the message to device if the device token is not associated with any device properties (like phone number or advertising identifier or vendor id).
I think you answered your own question:
Based on Apple Push Notification programming guide, the provider needs to provide device token and payload to APNs server for the push notification.
If you could provide the phone number, for example, you could simply use harvested phone numbers and spam people with push notifications. The token is not only for identifying the phone; you only get one if the user explicitly said "Yes, I want push notifications."
The only properties that determine if a push notification is delivered to an iOS application on a given device are the push certificate used to establish the connection with APNS (which determines the destination application) and the device token (which determines the destination device). Any other parameters you choose to include in your payload will have no effect on the delivery of the message.
The solution that we implemented (and it works very well), is:
have the device token sent to the server upon registration
server stores that in a 'user_device' table (which ties the user to the device - once you get the info.... at this time you only have the token, so the userId is 0)
the user continues with their login info.....
as the user completes their login (going to the server for verification), include the token and match that up in the database (note that you could also just send it at this point, but we like to send the token in #2 so we could see how many people register devices but not log in...)
Now, you have a match-up from the user data to their deviceId and can then match up various USER properties (or even the device properties if you have gotten them from other means - like when the user signed in and completed their profile) and send the appropriate push notice.

geo push notifications depending on where client downloads app from

I have successfully set up push notifications which are sending and being received too all dev ices, However i want to now add the option of the push notification to only be sent to certain clients.
for example I would want to send clients who downloaded the application in spain a certain notification and then people who are in the uk a different notification.
Is there a way that i can add anything to my code to be able to figure this out?
I'm not to sure what to google either? Any answers better then what i already know.
When your app transmits the device token to your server, you could also send the customer's location. On your server, resolve this location to a country and store it with the device token. Then when you need to send a notification, you can look up the country for the specific device token.

Unsubscribe from Apple Push Notification service

I'm developing an iOS app that enables the user to observe technical devices and be notified if there are problems.
What I know so far:
My app requests a token from the APNs.
My app sends this token to my server.
My server notifies the APNs in case of an event.
The APNs pushes a message onto the device.
What I want to know:
I read the token may change, therefor I need to request it on every app launch. Is this true?
If I get a new token from time to time I have to register at my server from time to time to make sure it uses the current token. Do I have to store and manually send the old token with the new one if the token changes to allow my server to delete the old one?
How can I detect that a user removed the app to remove his device on the server?
Highest priority in my case is for the server to know which devices are registered with the service. Old devices (old tokens that is) need to be removed immediately.
Thanks for your help.
You should register for the remote notification on every app launch and send the token to your server.
To check if the user removed the app or disabled notifications you have to check the feedback service. Look for it on this page:
https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/BinaryProviderAPI.html#//apple_ref/doc/uid/TP40008194-CH13-SW1
Note: APNs monitors providers for their diligence in checking the feedback service and refraining from sending push notifications to nonexistent applications on devices.

Sending device token in Apple push notification

The tutorials that I have come across for push notification manages the sending of device token along with the data that user sends for web service requests. My app too uses webservices but for my application, when a record is added to the website, it has to be notified on my app. So when and how do I send my device token from my iphone app? Please help.
I'm sending the device tokken to the server every time the user logs in. I'm making a http-request (on wich i add the device tokken) to check the password & email. If the entered data is ok, i save the tokken in the database.

Resources