UIBackgroundFetch and Remote notification relation - iphone

I want didReceivePushNotification to gets call when app receive the push notification in background. For that do I need to enable background fetch in background mode ? is there any relationship between Push Notification and background fetch of Background Mode capability.?

Related

Parse iOS background notifications without clicking on them

When my app is in the background state and I receive a notification; I want to parse the payload of the notification without clicking on the notification.
Is it possible to get notified when a background notification arrives?
If you've truly sent a background notification via the content-available payload key being set to a value of 1, then your app delegate will call application(_:didReceiveRemoteNotification:fetchCompletionHandler)

How to invoke different screens based on push notification received in iPhone?

My iPhone application has different view controllers and I would like to invoke them based on the push notification received from backend. For example if I have view controllers "A" and "B", I would launch "A" when user receives a message regarding some activity in "A" (e.g. Please complete the activity in "A") and
would launch screen "B" if user receives "Please complete the activity in "B").
Can anybody tell me if this is possible in iPhone and if so how?
Sure. Your app delegate is notified of a push notification either through the application:didReceiveRemoteNotification: method (if the notification arrives while the app is active in the foreground of if the app is in the background and the user brings it to the foreground by acting on the push notification) or application:didFinishLaunchingWithOptions: (if the app was neither in the background nor in the foreground and the user launches it by acting on the push notification).
In both cases, the dictionary that is passed to you as a parameter of either method contains the notification's payload/contents. You can use it to identify which type of notification your app received and then act accordingly by displaying the appropriate view controller.

Showing Push notifications

I set my application for push notification and all is running fine. But i want that push notification should also show when my application is running. I do-not want to show an alert or pop in my application
There's nothing built-in to iOS that will make push notification popup appears if the app for the notification is currently in the foreground. You need to look at the data you get in the notification and create a UIAlertView by hand.

Get custom payload of push notification while app is running background

Hey can anybody tell how to get custom payload of push notification when app is in background?
If your app is in the background and you receive a push notification and the user taps app "View", the application is launched and application:didFinishLaunchingWithOptions: would get called. In this case we can access custom notification payload via UIApplicationLaunchOptionsRemoteNotificationKey from userInfo dictionary.
If your app is in the background and you receive a push notification and the user taps app icon, it brings the application to the foreground.
When that happens, only applicationDidEnterForeground: is called, and there is no way to access the payload of the push notification.
My requirement is to register for Badge only, no alert so no 'View' button to launch app when user receives notification in background. When user receives notification and application is in background, user taps app icon applicationDidEnterForeground: is called. So we have no way to access launchOptions dictionary or userInfo dictionary from where we can get notification payload.
Am I missing something here?
application:didReceiveRemoteNotification: is called when the user taps on the notification in the statusbar drop down if your app is running in the background. The link you referred to in your answer explains how to use it.

Push Notification with a timer - iPhone

I would like to send a push notification to the user but I want it to appear only for few seconds and not to stay on the screen. Can I set a timer to close the received notification?
No you can not. The display of push notifications is handled at the system level and unfortunately you don't have any control over them other than to enable or disable them entirely.