Handling Push Notification While App is Open - iphone

I have my Push Notification running. It works. I receive a notification and use
application:didReceiveRemoteNotification:
to get the incoming data and then send the user to the necessary screen.
Problem is, if you are using the App and a notification is received, it jumps to the destination screen without giving any alert/sound/anything.
I could put an alert in application:didReceiveRemoteNotification:, but then that alert would appear every time, not just when the app is running.
Ideas about how to handle this?

I would recommend checking the applicationState property in UIApplication to determine if the app is running in the background or not.

Related

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.

What happens when user does not respond to Push Notification?

Lets assume a user receives a notification. The user did not respond to notification. what happens? will it automatically get closed? if yes, what is the duration for the expiry of notification on the device? Thanks in advance.
The notification will not automatically get closed, but if another one comes in—be it a text message, a voicemail, or even a notification from another app—then your notification will effectively vanish. If the notification payload includes a badge number for your app, then that will get updated; aside from that, though, once another notification supersedes it, yours is gone.
To your app the behaviour will be the same as if he tapped the close button.
If the user doesn't respond, your app will never know. The push message will remain on the screen until the phone is unlocked or some other message is received (SMS or other push notification)

how to receive push notification when app is turned off?

I am implementing a push notification functionality for my app and everything is running smoothly except for one case.
The situation is this:
When the app is off (not running in background either) and the user receives a push notification. The user hits "Close" and then later on decides to go to the app. I would like my app delegate to know the push notification that was received earlier however, I don't know how to check that. I know that I can have a function call in my didLaunch... but that works when the user decides to hit the "View" button instead of "Close".
Any hints?
Thanks!
Really, the answer is don't bother. You can never guarantee that the alert was received, so unfortunately you'll run into problems later if you rely on this. apns doesn't guarantee a device will receive a payload.

iOS - Handling pushed notifications with APNS

Considering that I receive a pushed notification on my iPhone.
What happens:
If the application is started: is there a way to get the payload? Do I see the notification on my screen?
If the application is not started, is there a way to get the payload?
Thx for your answers
First of all push notifications are not “strong”, if you simply let a notification sit for long enough (e.g. phone turned off for many days) it will get discarded. You need to do some custom back-end processing to persist the content sent in notifications.
In the UIApplicationDelegate protocol there’s application:didFinishLaunchingWithOptions:. If your app is launched by the user tapping the right button in an alert of a push notification, the launchOptions dictionary bound to the method call will contain information regarding that notification; if your app is already running then application:didReceiveRemoteNotification: (also in the delegate protocol) will get called instead.
So,
If the application is started, and you implement application:didReceiveRemoteNotification: then yes you get the payload. Otherwise, nothing happens.
If the application is not started at the time the notification is sent, then the user taps on the alert of the notification and launches your app, your app gets the payload if it implements application:didFinishLaunchingWithOptions:. Otherwise, you get nothing.

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.