Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get data from push notification when app is closed in iOS and app not running in background

When receive a push notification and my application is totally closed, how can handle this info?

Only can get data from NSDictionary on this method didFinishLaunchingWithOptions: or

didReceiveRemoteNotification:

for example: when the user open the application how get data from the push notification?, and not when the user open the push notification directly.

Is there a method that responds and detect if a notification has not been read?

like image 478
Fabio Avatar asked Dec 12 '14 16:12

Fabio


People also ask

Do push notifications work when app is closed iOS?

Apple does not offer a way to handle a notification that arrives when your app is closed (i.e. when the user has fully quit the application or the OS had decided to kill it while it is in the background). If this happens, the only way to handle the notification is to wait until it is opened by the user.

Do push notifications work when app is closed?

Let's start with Android. The Android OS is designed to listen for push messages and upon receiving one, wake up the appropriate Android app to handle the push message, regardless of whether the app is closed or not.

How do I view push notifications history on iPhone?

Notification Center shows your notifications history, allowing you to scroll back and see what you've missed. There are two ways to see your alerts from the Notification Center: From the Lock Screen, swipe up from the middle of the screen. From any other screen, swipe down from the center of the top of your screen.

Will iOS awake my app when I receive silent push notification?

Yes. It will. When you click on that. Yeah its ok but being push notification is silent,you are not able to view any alert and cant click.


1 Answers

You'll want to implement

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler

This will launch your app if needed, then you'll want to save the data somewhere so when the user next's starts the app you grab the data and do something with it.

From Apples Doc's:

Discussion

Use this method to process incoming remote notifications for your app. Unlike the application:didReceiveRemoteNotification: method, which is called only when your app is running in the foreground, the system calls this method when your app is running in the foreground or background. In addition, if you enabled the remote notifications background mode, the system launches your app (or wakes it from the suspended state) and puts it in the background state when a push notification arrives. However, the system does not automatically launch your app if the user has force-quit it. In that situation, the user must relaunch your app or restart the device before the system attempts to launch your app automatically again.

Just look into the method and I'm certain you'll figure it out :)

I did a quick google, these look like they will help:

SO example: didReceiveRemoteNotification: fetchCompletionHandler: open from icon vs push notification

The first tutorial i saw on it: http://hayageek.com/ios-background-fetch/

like image 111
BooRanger Avatar answered Sep 21 '22 06:09

BooRanger