application: didReceiveRemoteNotification: fetchCompletionHandler:
is different from
application: didReceiveRemoteNotification:
How? from the docs:
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. If your app is suspended or not running, the system wakes up or launches your app and puts it into the background running state before calling the method. If the user opens your app from the system-displayed alert, the system calls this method again so that you know which notification the user selected.
My struggle is: I want to know if the method was called by the user tapping an a system-displayed alert from the Notification Center or from a silent push notification that wakes up the device. Currently, as far as I can see, there is no obvious way to differentiate.
- (BOOL)application: didFinishLaunchingWithOptions:
Tracking the launchOptions in the above method is not a solution because it's only called if the app is suspended/not running in background. If it's running in the background it doesn't get called.
What are push notifications? A push notification is a message that pops up on a mobile device, such as a sports score, an invitation to a flash sale or a coupon for downloading. App publishers can send them at any time, since users don't have to be in the app or using their devices to receive them.
Built-in voice Notifications for Android phonesTalkback will read out loud notifications as they arrive along with everything on your screen (not just notifications). However, this changes the way you interact with your phone, which might be a drawback if you are looking for app to only read out loud notifications.
Real-Time Notifications (RTN) are server-to-server push notifications that provide comprehensive data about in-app purchases in real time. You can use this information to monitor purchase state changes associated with your customer's in-app purchasable items.
The Apple docs are a bit confusing
application: didReceiveRemoteNotification: fetchCompletionHandler:
is used if your application supports the remote-notification background mode (ie you're doing BackgroundFetch.)
application: didReceiveRemoteNotification:
is called when the OS receives a RemoteNotification and the app is running (in the background/suspended or in the foreground.)
You can check the UIApplicationState to see if the app was brought to foreground by the user (tapping on notification) or was already running when notification comes in.
- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { UIApplicationState state = [application applicationState]; // user tapped notification while app was in background if (state == UIApplicationStateInactive || state == UIApplicationStateBackground) { // go to screen relevant to Notification content } else { // App is in UIApplicationStateActive (running in foreground) // perhaps show an UIAlertView } }
You could check the UIApplication
's applicationState
to distinguish silent calls from calls made with the application being actively used by the user:
typedef enum : NSInteger { UIApplicationStateActive, UIApplicationStateInactive, UIApplicationStateBackground } UIApplicationState;
Or keep your own flag set on the delegate
's applicationDidEnterBackground:
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With