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
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?
- Custom iOS push notification sound
- dyld: dyld_sim not compatible mach-o
- Algorithm to always sum sliders to 100% failing due to zeroes
- How to initialize a custom prototype style table cell in iOS 5 storyboards?
- Empty while loop hangs in iPhone release build
- NSCache Doesn't work with all images when loading for the first time
Solutions Collect From Internet About “get data from push notification when app is closed in iOS and app not running in background”
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:
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/
- ios swift: UIPickerView best practice?
- Resize UITableView Header AND containing UITextView (iOS7 + AutoLayout)
- Calling Function from another class swift
- Objective C Equivalent of PHP's “Variable Variables”
- View controller is not showing on whole screen for iphone-6 and iPhone 6 plus (in Swift and Objective-c both)
- Objective-C RabbitMQ client not publishing messages to queue
- How does NSDictionary handle NIL objects?
- AVPlayer : How to handle network interruptions
- Check whether or not the current thread is the main thread
- Prevent iOS mobile safari from going idle / auto-locking / sleeping?
- How can I resolve a red (moved) file in Xcode 5?
- Adding a copy of an NSTabViewItem from an NSTabView into the same NSTabView
- How to do transforms on a CALayer?
- How can I build in XCode 4, for an iOS 3.1 deployment target, using libSystem.B?
- How to save a struct to realm in swift?