8

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??

Atulkumar V. Jain
  • 5,102
  • 9
  • 44
  • 61
user1273189
  • 201
  • 1
  • 3
  • 4

5 Answers5

6

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.

Lem
  • 283
  • 2
  • 11
2

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.

Moshe
  • 57,511
  • 78
  • 272
  • 425
  • yaa but if I sleep in the night and I get push notification? I need to open the app when I get the push notification......any option to get event in foreground (without jailbreck) and without the user open the app with the push notification? – user1273189 Mar 16 '12 at 17:49
2

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.

jonkroll
  • 15,682
  • 4
  • 50
  • 43
  • I know, the main problem is when the app is close/foreground or the iphone not have internet/3g. and the user not open the app with the push notification....I alredy did the didReceiveRemoteNotification.... – user1273189 Mar 16 '12 at 17:48
1

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

Atulkumar V. Jain
  • 5,102
  • 9
  • 44
  • 61
  • yaa but if I sleep in the night and I get push notification? I need to open the app when I get the push notification......any option to get event in foreground (without jailbreck) and without the user open the app with the push notification? – user1273189 Mar 16 '12 at 17:50
  • I found something intresthing....I take 2 Iphone with WhatsApp I Open in the first iphone the WhatsApp and exit for the app (the WhatsApp is in the background), now with the secend iphone I send watsapp massage to the first iphone. – user1273189 Mar 16 '12 at 21:06
  • now when the push notification of WahtsApp get to the first Iphone I see two "V" (symbol) near to the massage (and I don't open the Push notification), after this I close the Internter & 3G in the first Iphone and again send WhatsApp massage with the secend iphone to the first Iphone, And I see only one "V" near to the massage (not read), now after I enable the internet on the first iphone and after I get the push notification I see two "V" (I don't open the push notification) how it's work? how WhatsApp know if the iphone get the push notification or not? – user1273189 Mar 16 '12 at 21:25
  • 1
    This is handled by the WhatsApp server. When the user opens the app using the push notification, the app might have sent a request to the sever stating that the msg has been read by the user. So the server is updated with this info. & next time when a new msg is send using APNS the sever knows thats the previous msg was read by the user. – Atulkumar V. Jain Mar 19 '12 at 06:26
-1

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...
    }
 } 
kalyanbk
  • 153
  • 1
  • 7
  • 1
    This is checking the successful sending of the notification, but this does not ensure that the notification is delivered to the end user. Delivery of notifications is not guaranteed. – danielbeard Mar 22 '13 at 00:15
  • @danielbeard Does it guarantee that the notification has reached to the apple server?? – Shahzad Ahamad Feb 12 '19 at 11:13
  • @Shahzad Depends on the implementation of that specific library. But it doesn't matter since apple doesn't guarantee the delivery anyway. – danielbeard Feb 12 '19 at 19:32