which method is fired when notification turned off by user - iphone - iphone

when a user chooses to allow push notifications then the following method gets invoked:
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
but if s/he choose not to allow the notification which method is called?
also if a user decided to allow notification and after a while to turned them off - which method is called?

When application generates a pop up to ask user for permissions to receive push notification, on success device receives access token and goes to method didRegisterForRemoteNotification.But if user disallow then device fails to get device token and goes to method.
- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error

Related

How to get the device token in iOS 10 if user does not accept to receive Push Notifications?

I had my app for iOS 9 implementing application(_:didRegisterForRemoteNotificationsWithDeviceToken:) that gets invoked whether or not user accepts to receive Push Notifications, hence I get and store on the remote server the device token in both cases.
Now with iOS 10 this delegate method never gets called if user does not accept to receive Push Notifications... Is there any other way to get the device token in such a case?
You can't. If user doesn't accept notifications, you can't get any token for this.
This is the fact when user not accept to receive notification then application will not generate device token or sometime by mistake click on don't allow option, so whenever you want to need app required Push notification need to show any popup(Alert view) message there for why you need push notification access inside app then second time give some tutorial/advice/guidance for how user enable manually push notification service from iOS device Setting option.

iPhone Push Notifications

I have a iPhone app that uses Push Notifications. My understanding of how this works is I need the "Device Token" of each iPhone before I can send a notification.
Using the test iPhones I have, I can obtain the Device Token from the xcode interface and store them in a data table which the Push Notification PHP script uses to send the notifications.
How do I send the Push Notifications to iPhones that install the app of which I do not know the Device Token ID.
I think my question is; do I need the Device Tokens before I can sent a notification to a iPhone.
If I do require the Device Token, how do I obtain it from iPhones using my app.
You can't receive any Push Notification with the Simulator.
You don't directly send a notification. You said to Apple's servers that there is a notification for this Device Token. Then iPhones themselves will ask automatically to receive push notifications is some are available.
To answer to your question : Yes you do. Without the Device Token you can't register your notification to Apple's server. Then you have to implement this register the device to get the DeviceToken:
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken
Here is you should look up == Push Notification Programming Guide
- (void)applicationDidFinishLaunching:(UIApplication *)app {
// other setup tasks here....
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
}
// Delegation methods
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
const void *devTokenBytes = [devToken bytes];
self.registered = YES;
[self sendProviderDeviceToken:devTokenBytes]; // custom method
}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
NSLog(#"Error in registration. Error: %#", err);
}
See the code from apple Local and Push Notification Programming Guide, first you have to call registerForRemoteNotificationTypes in your app, and then in two delegates, you can get dev token or not, this token is from APNS, so when you get it, you will send it to your service to store it. And you can't get a device token from simulator.
Your push notification service will have to use the device token to send notification to your app, so you will definitely need it. In additional, you will have to get SSL certificates from apple dev center, that requires an valid paid developer ID of iOS.
For more information, please check Push Notification Programming Guide, and it's a great help.
Furthermore, I tried this PHP library to test push notification service, and it's good, you can just find its unit test, and paste the device token there, and run it, you will get message from it.
sly/notification-pusher

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...
}
}

Apple Push Notification Service on user response

Is there a way to track user response (the choice between the 'View' and 'Close') when the message has been push into the user device?
Thank you.
Your app is not notified if the user clicks "Close"; but if the user clicks "View", your app is launched, and you can detect that it was launched from a notification -- the notification's payload is passed to application:didFinishLaunchingWithOptions:.
Also, don't forget about the case where your app might already be running when the notification comes in. In that case, your application:didReceiveRemoteNotification: function will be called.
Full details are here.
My strategy would be:
Keep a record of the user's device token when your server fires a APNs notification.
Implement the didFinishLaunchingWithOptions and didReceiveRemoteNotification methods accordingly, so that whenever the user's device becomes active due to your APNs notification, it sends a request to let your server know. This request should contain the device token.
Your server does a look-up and match process, once such a request is received.

iOS - Handling pushed notifications with APNS

Considering that I receive a pushed notification on my iPhone.
What happens:
If the application is started: is there a way to get the payload? Do I see the notification on my screen?
If the application is not started, is there a way to get the payload?
Thx for your answers
First of all push notifications are not “strong”, if you simply let a notification sit for long enough (e.g. phone turned off for many days) it will get discarded. You need to do some custom back-end processing to persist the content sent in notifications.
In the UIApplicationDelegate protocol there’s application:didFinishLaunchingWithOptions:. If your app is launched by the user tapping the right button in an alert of a push notification, the launchOptions dictionary bound to the method call will contain information regarding that notification; if your app is already running then application:didReceiveRemoteNotification: (also in the delegate protocol) will get called instead.
So,
If the application is started, and you implement application:didReceiveRemoteNotification: then yes you get the payload. Otherwise, nothing happens.
If the application is not started at the time the notification is sent, then the user taps on the alert of the notification and launches your app, your app gets the payload if it implements application:didFinishLaunchingWithOptions:. Otherwise, you get nothing.