When push notification comes, if the user click the app icon instead of clicking the notification to open this app - iphone

When push notification comes, it the user click the app icon instead of clicking the notification to open this app.
Then how can I get the notification payload?

As others have mentioned, you can't.
You can only get the payload when launching from Notification Center because it means the user is interested in that specific notification. If you choose to ignore the notification and open the app by pushing the icon, you won't be able to get the push payload.
They have seemingly designed the architecture in such a way as to prevent the processing of piled up push payloads (say that 10 times).
This is proven because they really only allow you to process a push payload (when the app is closed or in the background) by going through individual notifications. If this wasn't the case, they would have to allow push payload processing code to run for all apps even when they were closed or in the background state.

Related

Can we cancel a push notification from application on iOS5?

On iOS5, the push notification shows on the top bar and not block user. When the push notification is showing and user click our application but not the push bar, our app will launch normally. However, we want to cancel the push notification at that time. Is it possible ? Thanks a lot!
Short answer: No. There is no way you can manipulate sent notifications as far as I know.
Slightly longer answer:
Once a push request has been sent to the Apple Push Notification servers, thats it. It disappears into their system and they will then try to deliver it on a 'best effort' basis. You receive no feedback about its status or any ability to change/delete it.
The only form of feedback you can get is about which devices do not wish to receive push notifications that you tried to send to.
If you want to send delayed notifications which can be cancelled/modified at later data, either write you own solution, or use some pre-existing solution (e.g Urban Airship).

How to tell user about what are recently received push notifications

Is it possible to tell user what were about recently received push notifications ? I mean, if user clicks cancel when push was received, there is a badge on the icon of my application, but that's all. I think this is not user friendly and such notifications have no sense. When user opens an application, he knows that there is something new in it, but don't know exactly what. Do I need to make some requests to my web server to have information about my last pushes or I'm missing something and there is another way ?
From the implementations of push notifications I've worked with so far, you'll need to make a call to your server when the app actually starts up in order for the app to know what the new information is. I don't believe there's any way to store received push notifications unless your app is opened and handling them in the app delegate. Otherwise if push notification is closed it's discarded.
In all the apps I've worked with that utilized push notifications there was a place in the app where all the recent notifications were displayed after a call to the server was made to get the whole list.

Push Notifications not opening app "With Options" if its not clicked immediately when its presented

I am running into a problem here. I am able to receive, capture and save an APNS message just fine if I do it while my app is running or if I click "View" when it comes in if the app is closed.
The problem I am running into is.. If the app is NOT running and I receive a APNS message and chose to look at it later by selecting "Close"... the next time I open the app, the app is not opening "with options". Therefor, the APNS message is lost. The same thing happens if the screen lock comes on before "viewing" the APNS message.
How do I handle this?
Thanks in advance!
Don’t assume that push notifications will make it to your app—their delivery isn’t guaranteed, even if the user doesn’t “close” the alert a notification brings up. Your server should have the authoritative state of whatever notifications your app needs to display when it launches, and the app should check that state regardless of whether it’s launched from a notification or not; one reason for this is that if your app receives multiple notifications while in the background, only one of those notifications will get delivered to the app when the user chooses to view it.

Is is possible for an application to handle the response from a push notification?

Is it possible to get the user's response from a push notification and create a notification reply? i.e. if a user clicks the view button and views the app, can we take that action and let the sender of the notification know that the receiver has viewed / opened the app?
Short answer, Yes.
When the application starts due to a user electing to from a notification (local or remote) the application is started in a special way so that the application can process the notification. At this point it can do whatever you want, like send a message back to your service.
See Handling Local and Remote Notifications for details.

Can push notification be sent without an alert for certain actions?

I know you can register to have alerts or not when you call the push notification API. However my problem is that I want a certain class of actions to have an alert notification while no alert notification for other class of action?
So for example, an alert should be shown when we send the notification "Heart rate dropping alert!". But no alert should be shown when we send the notification "downloading updated patient data", the app should just take the notification as an instruction to being download if it is launched. And simply ignore it if it is not launched.
How to implement this?
Check Silent Push Notifications for iOS 7.In the WWDC 2013's "What's New with Multitasking" presentation, there is a section about Silent Push Notifications.
You can embed custom JSON data in the push notification, look at The Notification Payload in the Apple docs.
Update: I don't think that quite answers your question. You can send a blank notification that has the effect of cancelling any previous push notification (including those from other applications). I'm not sure if the app gets notified of that when it is actually running. If it does you might be able to do that in conjunction with a custom JSON payload to achieve what you want?
{"aps": {"badge": 0}}
You probably know this already - you can't use a push notification to launch the app on the iPhone without the user seeing a popup (apps can never run in the background on the iPhone).
However, you can display a different popup message and include different JSON data in the notification. Then if the user presses the button to launch the app ("Start", or whatever you call the button on the right) that JSON data is passed into the app. Your app can then carry out a different action based on that data.
Not possible. Push notifications cannot initiate tasks - nothing can cause an app to execute without user action. Similar question to Can I use Push Notification for this. You can trigger a sound, a text alert, or a badge value. That's it.