How to send push notifications to users' devices, not just my own - iphone

I want to ask about what I need to make a Push Notification, I reed a lot of things and Succeeded send a push from my mac to my devices that exists in the organizer (using PushMeBaby source code). but also I'm confused about make it for other devices (all who has my app) and How I get their Token Device number ?
Just in Big title tell me what I need.
Thanks

Use UIApplication's
- (void)registerForRemoteNotificationTypes:(UIRemoteNotificationType)types
The device token will be returned via callback:
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
Then you have to send deviceToken to your server. Note: deviceToken can change from time to time. So you have to check it every time and resubmit to your server if it changes.
Make sure that port 2195 is opened on your router. You should also register your application for remote notifications on Provisioning portal.

Not to promote other peoples stuff but there is an easy way to send notifications with premade code by xtify and Parse google them they are both free.

Related

TVOS remote notification replacement

I am building a TVOS app for the new Apple TV that needs to get notifications from a server to update it's display. Remote notifications are not allowed with TVOS, and it actually displays an error when you try to register the app for remote notifications.
With this being said, are there any alternatives to what I need?
To clarify:
- The app stays running indefinitely, showing a display.
- When the user adds content to the display, I want to notify any apps that are logged in to the same user to update the display.
- I cannot use remote notifications.
Please let me know if this makes sense, and thank you in advance for your help!
What part of the registration errors out for you? Notification dialogs and banners may not really make sense on tvOS, but can you send a silent push notification? All you need to do to register for these is
[application registerForRemoteNotifications];
You do not need to display the request dialog to the user for permission for silent notifications (you do need to have the remote notifications entitlement though.)
According to Apple's documents here, they allow CloudKit. CloudKit subscriptions rely on silent push notifications that I would assume would work on tvOS (without them it would severely cripple CloudKit)
If that still does't work, then you could create your own long polling connection (essentially, you would be making your own custom push notifications). It would only be able to send messages to devices that have the app opened however.
I guess you can have the app poll a web server at a given interval to check if any updates have been made...

any option to know if apple app get the push notification?

I build xcode app that get push notification, the main problem is that the push notification is very critical for me.
so I want to check if the push notification is delivered to the device with the app installed, I understand that if the iphone dosn't have internet connecction / 3G the push notification is not getting to the device.
how can I check if the device get the notification or not?
how can I check if the APNS successful to deliver the push notification?
I want to send sms if the push notification is not deliver to the device so I think about the idea to get the notification event when it's open by the push notification, and to send request to my server so i can know if the push notification is successful deliver or not. the main problem is that the user need to open the app every time he get the notification and in the night it's a problem. so this option is not good for me.
I check the feedback server push notification but i don't find any info that I can get if the push notification is delivered or not
any idea??
With iOS7 you have a new method called
application:didReceiveRemoteNotification:fetchCompletionHandler:
which you probably could use for your task. From Apple's Docs:
Implement this method if your app supports the remote-notification background mode.
...
When a push notification arrives, the system displays the notification to the user and
launches the app in the background (if needed) so that it can call this method. Use this
method to download any data related to the push notification. When your method is done,
call the block in the handler parameter.
Unlike the application:didReceiveRemoteNotification: method, which is called only when
your app is running, the system calls this method regardless of the state of your app.
The short answer, you can't, since APNS is one way. However, since an app can execute arbitrary code upon receipt of a notification, you can use this to say, send an http request to your own server when the notification is recieved.
There are any number of reason why push notifications might not get delivered to your user, or might not be delivered in a timely manner. Apple does not provide any mechanism for you to query the status of a push notification that you have sent.
If your app is currently running on the user's device and the user is accepting notifications for your app, you can implement the following method in your app delegate. It would be called whenever a push notification is received and in this method you could send a request back to your server to indicate the message was received. However this will only work while the user is running your app.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
In general though, it sounds like you'e relying on push notifications for something you shouldn't. From Apple's Local and Push Notification Programming Guide:
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.
There is no way to find out whether the notification was delivered to the device or no. APNS is a one way service. If there is no internet connection on the device then the APNS server will hold the last notification for some period of time which is no specified by Apple. If a new notification is sent to APNS for delivery then the old notification data is lost and replaced by the new data if its undelivered. If the notification is delivered then also the old notification data is deleted on the APNS server.
Please go through the following link : Apple Push Notification
Hope this helps you...........
If you are using JAVAPNS to send the APNS notification, you can use the below:
List<PushedNotification> notifications =
Push.combined("alert", badge, "default", "cert.p12", "certpassword", true, deviceToken);
for (PushedNotification notification : notifications) {
if (notification.isSuccessful()) {
//Push is successful. Do your thing...
}
else {
//Push is not successful. Do your thing...
}
}

How to determine Push notification status programmatically?

In my app, for first time push notification registration, I call didRegisterForRemoteNotificationsWithDeviceToken and save the device token in persistence as well as update my server list for device token. Now afterwards if somebody turns the push notification settings off from iPhone Settings how can I determine it from my app so that I can remove the device token from server as well. I know APNS provides a feedback list, but other than that is there a way to determine it in App programmatically? Thanks for any help!
I believe you do not want to manage tokens this way.
Your app should always be asking Apple for an APNs token. You should always then send that token to your own server, likely associating the token with your user (if you have one). You do this because the token could change, so you want to make sure you always have up-to-date tokens.
The Feedback service will tell you (actually, you poll it at some interval of your choosing) which tokens have become invalid. At this point, you remove the tokens from your server-side database. To be clear, you need a server-side process that polls Apple's feedback service and then updates your server-side database.
You will not receive feedback about invalid tokens until you try to send a notification using the token. The notification will (I believe) be accepted by Apple when you send it, but when Apple discovers it's for an invalid token, the message is dropped, and the token is added to your feedback.
Now, if the user of your app accepts push notifications when your app first asks about it, but later turns off notifications via the Settings app for your app, you will not get any feedback about it. What happens, near as I can tell, is that any notification you send to that device will be sent to the device, but the OS drops it, honoring the user's ultimate choice in the Settings app for your app and notifications.
Finally, there is an API you can call in your app to get a bitmask of which kinds of notifications are enabled for your app on the device. Here's a method I wrote for this purpose; adjust as needed:
+(BOOL)acceptsPushNotifications
{
UIRemoteNotificationType mask = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
return (mask & UIRemoteNotificationTypeAlert) == UIRemoteNotificationTypeAlert;
}
But I would not recommend using this to decide if you app should tell your server to delete the token from your database. That's not how the whole APNs system is intended to work... I believe.

How do push notifications on the iPhone determine which users are notified?

I'm just trying to understand push notification more.
Let's say I have a web service that my app connects to that needs a user to sign in with a username and password. And this all works fine when running the app.
Now... how does the web service determine which user to send the push notification to?
I'm really unsure on how it works with users with usernames and passwords. It would be great if someone could enlighten me to this. A better understanding could improve my apps in the future. Thanks!
I'll give a brief over view of how push notifications work:
First, your app will call the registerForRemoteNotificationTypes: method. This will check that your app is allowed to send and receive the types of notifications you requested, and contact Apple's servers to register your device. You will get back a special token used to uniquely identify the device.
Your app needs to send this token to your server along with the details of the account that the user is logged in with, so your server can associate that token with the user.
When you want to send a push notification to a user, you lookup the token you received previously for that user and use that when sending the notification to Apple's server. This will forward the notification to the appropriate device.
It's probably a good idea if you read the Apple documentation here: Apple Push Notification Service. This will give you a clearer understand of how it all works.
Here is the wonderful tutorial explains in detail, http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12
For login procedures, you don't even need push notifications. If you need a general introduction, you will find one here
Below I have mentioned 2 links.
https://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html
http://mobiforge.com/developing/story/programming-apple-push-notification-services
Now coming to your question, push notification is pushed from a server. Now for a particular user the server side should maintain the database such that whatever changes made to a specific user should be pushed to that device id.
Hope this help.
Push notification is awesome feature of iOS apps. It works like your application needs to register for Push notification as
//Your application registeres for push notification using following line
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
This will tells you application to handle generation of device token failure/success by delegate methods
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
//Your application registered for push notification i.e. allowed by user.
//You need to take device token and pass it to your webservice and store it in database.
}
- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
//Your application registered for push notification i.e. not allowed by user.
}
So, Now what after you have device token ? .. Its simple now use it for sending push notification. You can find different code for that using PHP as well as .Net. Search around and you will get plenty of them.

How do I get device token information from all my users for push notifications?

I don't see how http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction/Introduction.html#//apple_ref/doc/uid/TP40008194-CH1-SW1 tells me how to get device tokens for Push. I've read a couple of books, but they are of no help.
I want to develop my own system to keep track of them via feedback and via a dictionary. I want to send broadcast messages.
To be clear, I want to get the device tokens from my users' devices to my Push server.
I feel I am missing something obvious. Please help me.
When the user accepts push notification the didRegisterForRemoteNotificationsWithDeviceToken: method will be called with an NSData object with the info:
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
devToken = ...
}
The app is responsible for sending it to your Push Server. You have to define your own method to do this, e.g. HTTP POST or some other proprietary protocol.
For example, Urban Airship's iOS library makes an HTTP request to its server. See the registerDeviceTokenWithExtraInfo method in the UAirship.m file.