I receive PushNotification as badge as well as alert and are displayed as badges on the app icon.
I receive the payload successfully when I click on alert, which appears at top area of the screen.
But, if the notification is received and I click on the application icon i don't get the payload in any of below mentioned the methods.
application:didFinishLaunchingWithOptions:
application:didReceiveRemoteNotification:
So, what could be the problem or have I missed something in handling such case.
That would be expected behavior. You don't want to show the push notification for the user if he himself did not actively chose to to tap on the alert. If user is in your app while receiving notification you can ask the user if he wants to view it or dismiss it.
Related
My app is receiving a notification and my problem is that when I received one or more notifications in the background and when i click the app icon to bring me in my app foreground then the notification message(s) doesn't able to display in the foreground it will only works if I click the pop up message in notification center not the icon.
You will not get remote push notification data on launch of app after tapping icon. You can only parse push notification body only on tap of notification alert.
So if you want to do any MUST NEED operation for such notifications there is only way is to introduce server in between. So you can use any web service for it and this will be called every time your app launches or comes to foreground. Call that API on background and do the needful you want.
The iOS app I'm working on for a client currently only uses Apple Watch for notifications.
When a local notification fires while the user's phone is locked, it displays the notification on the phone. The user can dismiss the notification or click on one of the action buttons on it.
In either case, I want to dismiss the watch app and go back to whatever state it was in (back to the watch desktop, or springboard, or whatever it's called.) I don't want to present the UI for the watch app, since there isn't one, at least not yet. I don't know if my client is going to define a watch app UI or not.
As it is now, once the user clicks the dismiss button or an action button on the notification, the user is left with a stupid-looking placeholder watch app that simply has a button called "button" (which I added for testing.)
I'm afraid that you cannot change this. iOS decides which device the notification is shown on and you have no control over this.
If the iPhone is locked then iOS assumes that you are using your watch and will deliver the notification to it, however if your iPhone is unlocked it tends to deliver to notification to the iPhone.
I use a phone gap plugin and xcode 5.
Lets see the example of the problem:
The application is in background or closed.
I send the notification.
User sees the notification pop up, without clicking on it.
I send another notification.
If user open notification bar it will see two notification actually i want
to delete the previous some how and present to user only the second notification.
The eqvivalent in java is NotificationManage.cancelAll();
For now each/all notification i send are shown when user open notifications bar.
Any help appreciated.
You have (the app has) no control over that.
The user controls how many notifications they see in notification center. Notifications can be removed by the user and will be removed when acted upon (the app is opened from the notification).
You can do this by [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
in the method didReceiveRemoteNotification. In this way notification center will be cleared.
I cannot seem to find a way to detect when a notification comes in. For example, if my app is open and the user gets a Facebook push notification\, is there any UIApplication notification or something else that will tell me that the app is no longer in the foreground and the Facebook alert is on top? Preferably something that is fired if the notification is a banner or an alert
You cannot detect a push notification sent to another app.
If you want to detect whether your app is not in foreground anymore, you can use the applicationWillResignActive: method of UIApplicationDelegate or register for the UIApplicationWillResignActiveNotification notification.
However, when the notification banner appears on top, your application is still in foreground. When the notification is prompted as an alert instead (the user can set this in the preferences), the application loses the focus and it won't be in foreground anymore.
The notification banner at the top is a window displayed by SpringBoard (another process) which does not become key until the user touches it. If the user slides the notification down and the notification center opens, your app becomes inactive and your app delegate hears about this. If the user taps on the notification, your app goes to the background and the other is open. If the user has elected to see alerts instead of banners, once the alert is displayed, your app will resign active. You can listen to UIApplicationWillResignActiveNotification notifications to know when the app resigns active.
Consider this scenario:
An application is currently not in the foreground but it is in the background in an unsuspended state (appDidEnterbackground: was called)
The device receives 3 APNs for the application, and the user has the alert style set as "Alerts"
The user clicks Launch on the topmost (4th alert) showing notification alert
didReceiveRemoteNotification: is called and the app can get the payload of that particular notification
The app is now in the foreground with the alert dialog (for the other 3 notifications) displayed on top of it
The user clicks Launch on the notification alert (the 3rd alert) - nothing happens
The user clicks Lunch on the notification alert again (the 2nd alert) - still nothing happens
The user clicks Launch on the last notification alert (which was the 1st one received by the device) - applicationDidBecomeActive: is called.
So my question is how can the application get the payload for the 1st, 2nd, and 3rd notifications?
I can reproduce this 100%, I've noticed that didReceiveRemoteNotification: gets called for the last notification that the device received, and applicationDidBecomeActive get's called for the 1st, with nothing happening for any in the middle.
i.e. if 7 notifications are sent to the device, then didReceiveRemoteNotification: would get called for the 7th, then when the user clicks on Launch for the 6th, 5th, 4th, 3rd, and 2nd alert dialogs nothing would happen, then when they click on Launch for the last dialog (which was for the first notification received) then applicationDidBecomeActive: is called.
I agree with other answers. The best way to store it on the server and read it from there.
Just one more reference to the very similar question/answers:
Handle APNS Remote Notifications while in Background
You can't get this payload. You might also consider, that APNs don't have a guaranteed delivery so you must get infos from the server anyway. The push data is for stuff like showing the user a specific view of your app. In the logic part of your app, the push should only trigger a force update with your server's data.