Get push notification resuming app from background - iphone

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.

Related

iOS chat-app: How do I notify the user that the app will not function anymore if the user leaves the app?

I'm developing a chat-app for iOS that must use an existing server API. The way it works is pretty straightforward: the app checks every given interval whether there are new messages on the server and displays them, plus, it sends the server new messages that the user typed.
When the user starts 'multi-tasking' or presses the home button, my app will go to the background and therefore will not be able to check the server for new messages. The server will automatically assume that the user stopped the chat when a certain timeout has been reached.
Often, the user isn't aware of the fact that when the app is put to the background, it is unable to maintain the connection to the server and will stop the chat. I'm looking for a method that will notify the user of this behavior as soon as the app is put to the background.
My current idea is to notify the user when applicationWillResignActive and/or applicationDidEnterBackground is fired, but I wouldn't know in what way. Can it be done in a way that complies with Apple's guidelines?
I'm aware of the fact that the best solution would be a different overall design of the software (e.g., using push notifications and no server-side chat termination by timeouts), but in this case I can't change that.
I would continue running in the background and set an expiration handler block (called by the os when you app is REALLY killed) and there schedule a UILocalNotification
use
- (UIBackgroundTaskIdentifier)beginBackgroundTaskWithExpirationHandler:(void (^)(void))handler

iPhone App that stores data from the web

I'm making an iphone app that uses NSURLConnection to download some data from the web. I need to store this data somewhere, so my app can send out push notifications when the data changes in a particular way. For example, the data being stored is a number and a push notification will be sent out when that number changes by +-10.
I'm new to this, so I'm probably overcomplicating how I think this can be accomplished. I'm thinking I need to create a database and some server-side code that continuously pulls the data. When the data changes to my specifications (ex. +-10), it somehow pushes the data to the app which then sends out a push notification.
Is there an easier way to accomplish staying within xcode dev?
The app doesn't send the push notification. The point of push notifications is your app can be in the background so it can't poll/check for a given condition (like your +-10).
When that interesting even happens server side, it can push a notification to the device. The device can handle that notification by (1) showing text (2) playing a sound or (3) updating a badge on an icon.
So, it's not about your device downloading the data into database (although that has value for offline and occasionally connected scenarios).
So, you'll need a server side component that detects that +-10 change (on data change or polling) and then sends the push to the device. Now, it's possible that devices are sending data to your service (uploading) and when and interesting event happens it could notify other instances of the app.
This link may help clarify push notifications: http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12

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

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.

iPhone - how to be notified of call completion

I'm developing an application that needs to take action on completed phone calls, preferably right after the call ends but minimally once per day.
I've read up on the new CoreTelphony framework, and it seems I can get call events if my app is active, but I don't see how to launch/wake my app when a call ends if my app is not the foreground app. I also don't see how any of the new pseudo-background "modes" would allow my app to listen for these events in the background. Do any of you know how this might be done?
If post-call processing isn't possible, then I'd like to figure out a way to automatically wake my app up once per day, pull all of the call events since the last wakeup, and process them. I know how I might do this with Push or Local notifications, but my understanding is that those require user action to continue; in this case, I just want the processing to happen automatically. Is there a mechanism that would enable this?
Thanks,
Dan
You can't launch your app without user interaction.
Push / Local notifications aren't for this kind of thing, they're for letting the user know about event.
On a non-jailbroken device there is no way to do what you want to do.

a question related to apple push notification service

Friends
In, testing of Apple Push Notification Service ,server sends me response .k that is not the problem
problem is that when server sends response to me ,at that time pop up comes through Operating system(OS).how to handle it
there are 2 questions related to it
1>if pop up comes through OS ,there are 2 options
1>press YES and 2>NO now if i press yes where it will be in my code
2>or u can say how i know if i press yes it will be where in my code .so that i can put NSLog(#"abcdefghijklmnop"); there
There are two situations when a push notification arrives. Either your app is already running and it arrives, or it's not running and it arrives. If it's not running, the O/S has sole control of handling the push notification, and you won't be able to do anything from your app unless the user proceeds.
If your app is already running, you can pretty much do whatever the heck you want. Simply provide an implementation for UIApplicationDelegate's application:didReceiveRemoteNotification: method.
If your app isn't running, the O/S is handling and there is very little that you can learn from arrival. If the user simply dismisses the message, none of your code anywhere will be run. If the user accepts the message, then your application is launched. You can get examine the contents of the launchOptions parameter to application:didFinishLaunchingWithOptions: to see what happened.