Retrieving latest Push Notification if app was not launched by hitting the 'View' button - iphone

I'm wondering if there is any way of retrieving the last-received push notification if the app is launched from the home screen instead of by pressing the 'View' button on the notification.
The app we're writing is for dealing with sensitive data, and it's important to be able for the central server to be able to remotely disable a client at will, without having the requirement that the app needs an internet connection to launch.
The basic idea I came up for this would be to send a push notification with a custom payload letting the app know to disable itself until it can properly sync its data.
This would work if the user pressed View on the notification, but not if they cancelled it and then launched the app separately.
I'd love to know if this is possible, or otherwise if there's a better way to implement this functionality.

It's not possible. Your app would have to connect to the server on launch and get its latest status from there. If your use case is that sensitive, push notifications are probably not reliable enough anyway because Apple does not guarantee that a push notification will actually be delivered.

Like Ole said, not possible.
Note that you shouldn't be relying on push notifications for anything like this. From Apple's push notifications programming guide:
Remember that delivery of notifications is “best effort” and is not guaranteed.

Related

Can I use local notifications for newsstand app subscriptions?

I have a newsstand app that will offer a free subscription that updates daily.
I would like to use push notifications to download the issues in the background.
At first I was considering use UrbanAirship to manage the list of scribers and send out push notifications every day at the same time. Of course this is costly.
Instead would Apple allow me to send local notifications to the app each day at the scheduled time and then the app could go and download the issue in the background, thus avoiding the need for a server to send push notifications or manage a list of scribers or worry about security and certificates etc.
I am not sure about Apple's guideline for this. But I strongly recommend to not try out something like that.
In case your app is not running (not in background) the local notification will not start the download automatically. The Newsstand push notification include the content-available property (with a value of 1) in the JSON payload. Due to this iOS launch your application in background (if not in background) and you can add your content in Newsstand queue for download in background. Once download is complete iOS will close your application. There is no notification alert or any other thing comes which require user to take any action. I think this you cannot achieve through Local Notification.
Other challenges
- How do you make sure the new content is always available when local notification is received .
- How do you figure out what content to download.
Also check out my answer to this question.

Get push notification resuming app from background

Consider this scenario:
1) Launch the app
2) Put the app in background (pressing Home button)
3) Server send a PUSH notification to client
4) The user resume the app clicking on its icon from menu
In this case didReceiveRemoteNotification and didFinishLaunchingWithOptions are not called, so how do I get notifications ?
Simple answer: In this scenario you cannot get it.
If the push notification contains important payload then it should not contain it because you should not rely on it for anything important because:
notifications are not guaranteed to be delivered to the device in the first place
the user can turn off notifications
they could ignore them
if the device is turned off when it is due to be displayed then it will be lost
If you need to know if the server has sent a notification then make a connection home when you become active and ask it if it did so.
You should check in the applicationWillEnterForeground: method.
I think the app will not see anything if the user chooses to ignore the push notification. The workaround that comes into mind first would be to offer a way of checking the server if anything worth a push notification has happened since the last time the app was opened and correlating that with the local data.
I think the idea behind this system is to separate actual functionality from push notifications and making sure the notifications are used for only one purpose - notifying of new data/event/etc, thus leaving the downloading and processing of data to the app once it's fully in the foreground. I.e everything should be duplicated in the launching sequence to make sure the app is always up-to-date, even if the notifications during downtime were not received/ignored.
application:didReceiveRemoteNotification: is therefore meant for not transferring the data and updating the model, but reacting to the event and starting the necessary procedures. Although most of the time, the data may be so small that it fits in the notification and therefore the application can proceed without downloading any further content.

How to use Push Notifications

Regarding push notifications. How do I get the provision from APNS to implement push notifications in to my application. Help me guys.
start from these series
http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12
iOS developers love to imagine users of their awesome app using the app all day, every day. Unfortunately, the cold hard truth is that users will sometimes have to close the app and perform other activities. Laundry doesn’t fold itself, you know :]
Happily, push notifications allow developers to reach users and perform small tasks even when users aren’t actively using an app!
Push notifications have become more and more powerful since they were first introduced. In iOS 9, push notifications can:
Display a short text message
Play a notification sound
Set a badge number on the app’s icon
Provide actions the user can take without opening the app
Be silent, allowing the app to wake up in the background and perform a task
This push notifications tutorial will go over how push notifications work, and let you try out their features...
I followed the steps mentioned in raywenderlich tutorial. It's some what easy to send Push notifications to my iPhone app by using my system as the temporary server(ie, sending the message by running the PHP code from the Terminal window).
But, while going for production and dynamic messages for different users at different time, it's very tough for me to set the service in a server.
So, I go with third party server to send Push Notifications. - Parse.com
Tutorial for how to use that API.
Documentation about the installations of the application.
Here, we have a tag parse.com for questions about this process.

iPhone real time notification from a server, without using Apple push notification

I'm looking for a way to get real time notification from a server in an iPhone App. I don't want to use Apple Push Notification as I have many notifications. My web service is coded in PHP, and I haven't figured out an easy way to implement this functionnality. Any idea what should I do?
Thx a lot for your help!
EDIT : I'm looking for a way to get notification only when the app is launched (otherwise, the only option IS Apple Push not.).
If the app is running you can open an http connection from the app to the server and have the server hold it open, pushing data through it when you want. This is basically how COMET works.
This will only work while your app is running. If you need the notification to happen even if the user has closed the app then Apple Push Notifications are your only option.
You must use Apple Push Notification for achieving push notifications cycle on Apple's mobile devices.

Can I use Push Notification for this

My app should post some message to Twitter at the end of each day at the time X. App might not be running at this time X, but it still has to post that message. I don't want to bother user by everyday asking to do this task.
Can I use Push Notification to silently (without any alert view popup, sound or anything else) do some task in my app in some constant time everyday even if it's not running?
thx
There are three 'notification' mechanisms you can send via push: alerts, sounds, and badge values. The way the push notification works is that on the phone it launches the app and hands over the 'push payload' to it with those values. Even if you turn off all three mechanisms, the OS will still have to launch your app each time, which means the user will get interrupted.
In short, you can't have a push happen silently. I doubt, from a user-experience point of view that Apple will allow things to happen on the phone without the user getting notified somehow.
No.
You can't schedule things to be run by your app on a non-jailbroken iPhone.
The only solution is to have a separately hosted service somewhere to which you push details from your app and that runs the scheduled updates on your behalf.
To do so silently is not up to you. The iPhone device has a configuration in which each app with a Push mechanism has settings where one can specify if they want alerts or not. If set to yes, the text of the alert is displayed as well.
sounds like you are trying to "wake up" your app at a specific time each day to perform some type of task. from what i understand about the iPhone this is not possible. you cannot create a cron job or something that will fire on a time you specify. you can run this on the server side and then push a notification to the user telling them that the message has been posted to twitter.
if you are on a jailbroken phone i feel confident that there is some way to do this.
Given that push notification requires that your server send a notification, why not skip a step and have the server just send the update directly to Twitter on the user's behalf? You can't use push notification to trigger an automatic task on the iPhone like you're asking - the user must take the step of accepting the notification for anything to happen.
if you really want to do it from the phone, you can just declare a "long term" background task should be covered around here (iphone app programing guide) some where..., that way you never go sleep, and you can do what ever you like... :)