Apple push notification one app more subdomains - ios

How can i set apple push notification when i connect to sub1.domain.com my server will send messages for that APP_ID, and when connect to sub2.domain.com i will receive messages only from that subdomain.
Like in GCM, i have 5 apps for 5 subdomains and my ios app connect to another app_id and get token for that app(subdomain).
Is that possible in apple push notifications?

iOS remote push notification just requests a device token, and APNs just send message to device via device token. The device token is unique to iDevice.
For your purpose, you can save both device token and a "token channel" to database, e.g. INSERT INTO device_tokens (channel, token) VALUES ('subdomain1', 'xxxxxxxxx'), when sending message, queue device token with channel, e.g. SELECT token FROM device_tokens WHERE channel = 'subdomain1'

Related

iOS APN Push Notification - Device Token

When working with push notifications via the Apple's APN service, when my app is installed and the user opts into receiving push notifications a device token is generated.
Is this device token unique to every single device or is there a global device token I can use to send push notification messages?
I am guessing if the device token is unique, I would have to save it up to a DB.
Well, Device token is unique but it become change when you reinstall it from appstore. You have to store that Token in database to send notification through that token. It should automatically register in database after installing with first time opening the app, It always hit but your database code should not reinsert it if same device token string found in the database.
NOTE: Device Token, UDID and UUID all are different and unique with some different usage purposes.

Send remote push notification to specific user

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

Push notification device tokens and their validity

I have a general question to device tokens for push notifications.
this is a part of the apple documentation:
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
I understood that each app on a device get an unique token.
For example, the token of a app on my device is XYZ
With this token I can send from my server an push notification to XYZ and I will received it on my device.
According to Apple, the device token can change after an OS update
but what happens if the device token of my device changes and I don't start the app for a few days, so that the new device token isn't in my token table in my database?
What will be happen with the notification, which I will send to the old device token?

send notification like push notification without APNS server in ios,

I want to send push notification without any APNS server and device token,like android there is NO local and push notifications but they can send device to device with out google permissions.
You can NOT send a push notification without using APNs. Why? first you need to understand how the technology works:
You need a certificate for a handshake.
You need a device token to be identified by APNs.
In your app, you have to register to APNs.
The app requests the certificate from APNs (handshake).
The server sends back its certificate.
The app will establish a connection to the server and send the PN certificate to the APN server.
The server will validate that you are a trusted app.
The app requests to create a token.
The server creates a token and sends it back.
In your app you save the token (to do e.g. push notifications to a specific user instead of a broadcast).
End.
So, as you see, you need to establish a trusted connection, the APNs is responsible for creating a token to identify your device within the network, and will be responsible for sending notifications.
For more info you could see:
Apple PNs

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.

Resources