0

I have properly registered for the push notification. Implemented following method to receive notification.

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject])

Also used UIApplicationLaunchOptionsRemoteNotificationKey from func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool.

I'm able to receive notification when the app is active. I'm also able to see the notification if I open the app from the notification by selecting it from banner or alert.

But if app is not active, it could be alive or killed and if a notification arrives at that point. And I ignore the notification and open the app by directly selecting the app icon from the home screen, I'm not getting the notification information in the UIApplicationLaunchOptionsRemoteNotificationKey from func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool.

So what is the right way to handle this scenario? Should the app call server and get the recent messages it sent? Any help is much appreciated.

Daniel Casserly
  • 3,552
  • 2
  • 29
  • 60
SDTDMT
  • 221
  • 2
  • 7

3 Answers3

1

If the user will open you app directly from it's home screen, you would not get access to the push notification dictionary.

If you need the data sent in the push notification, so the proper way will be a server request as you suggested.

Asaf
  • 2,158
  • 2
  • 25
  • 40
  • Server requests refers to getting the last sent push messages from application's own server. Is it right? Or is there a way to get last sent notification from APNS or notification center? Is the answer explained here still valid? http://stackoverflow.com/questions/11290661/how-to-get-all-the-pending-push-notifications-from-ios-notification-center-after – SDTDMT Apr 14 '15 at 14:06
  • No, unfortunately there is no way for that and your app server should do that. – Asaf Apr 14 '15 at 14:08
0

If user enter the app by click the icon or launch from the background, the push notification message can't deliver to you, the message is cached by system, the only way to get it is from notification center

Ian
  • 3
  • 5
  • I did not find a way to get messages from notification center if user did not select the notification. http://stackoverflow.com/questions/11290661/how-to-get-all-the-pending-push-notifications-from-ios-notification-center-after also explains the same. If you know a procedure to get notification from notification center even if the user did not select it could you please share how it can be achieved? – SDTDMT Apr 14 '15 at 14:13
  • so sorry, there is no way to achieved. But in [link]stackoverflow.com/questions/11290661/… there is a answer means to check applicationIconBadgeNumber, I don't know if it is satisfy your needs. – Ian Apr 14 '15 at 15:45
  • I see your new answer, but this silent push notification is not exactly received by user, it depends on many circumstances, like user use phone habit, open your app time, current memory status etc. – Ian Apr 16 '15 at 05:10
  • I have checked the scenario when app is active and is in the background. Both times it seemed to be working. Did you find the information you are mentioning in any documentation. Can you please share it? – SDTDMT Apr 16 '15 at 15:16
  • I was mistake about this, user always can received silent notification,but maybe not launch app at background. You can see the WWDC2014's "What's New in iOS Notifications" section, push Mentioned in the video – Ian Apr 17 '15 at 05:46
0

Answering my question:

It is possible for the app in the background to receive push notification.

To do so send content-available in the aps dictionary of push notification. Enable background mode of the app from the Background modes section of the Capabilities tab in your Xcode project. Implement application:didReceiveRemoteNotification:fetchCompletionHandler: in the app delegate.

References: See section 'Notification Payload' in https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html

See section 'Using Push Notifications to Initiate a Download' in https://developer.apple.com/library/prerelease/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html

However if app is killed then the appdelegate's application:didReceiveRemoteNotification:fetchCompletionHandler: is not getting called.

According to Will iOS launch my app into the background if it was force-quit by the user? post on iOS8.0 it is possible to do it using PushKit. But I have not tested it. And also if VOIP is not used then I dont know if it is possible for app to receive push notification information if it is killed.

Community
  • 1
  • 1
SDTDMT
  • 221
  • 2
  • 7