I would like to build an app which retrieves images from my server.
My problem is that I want it to work in the background and only when there is a 'new image' to load.
It seems like what I need is very similar to PUSH notifications:
Work in the background
Only when there is 'something new' to load.
I guess what I want became possible with the new iOS4.
Please tell me if this is feasible.
Any links for how to even start thinking about it would be great.
Thanks.
It depends on what background you mean.
If you mean that your application is running and you have some thread to get the image in the background thread, it is possible.
If you mean that your application is suspended and you still want to use PUSH notification and get the image. I am afraid that it is impossible. When your application is in the background, it has very limited amount of time that it can run to finish its current task. When that time is out, your application cannot do anything.
You can receive some push notification and local notification like GPS, server notification when your application is suspended, but you can only receive the server notification and cannot download the new image. Here is the instruction from Apple Dev documentation:
When the operating system delivers a
local or push notification and the
target application is not running in
the foreground, it presents the
notification (alert, icon badge
number, sound). If there is a
notification alert and the user taps
the action button (or moves the action
slider), the application launches and
calls the UIApplicationDelegate method
application:didFinishLaunchingWithOptions:,
passing in the local-notification
object or remote-notification payload.
If the application is running in the
foreground when the notification is
delivered, the
application:didReceiveRemoteNotification:
or
application:didReceiveLocalNotification:
method of the application delegate is
invoked.
More here
Related
I'm using local and silent remote notifications in the app I'm working at work. I need to launch some methods according to events received from our servers or from the app itself via silent remote and local notifications respectively. I have no problem with remote notifications with the app in foreground, background or with the notification touched but I can't get the scheduled local notifications to be noticed by AppDelegate if the app is running in background (I mean, without user tapping the banner).
Is this even possible? If yes, which parameter should I add to the notification or what method is supposed to be called when it arrives?
I don't think it's possible to send a local notification that runs silently and starts your app. The normal way to do things like this is Background App Refresh:
https://developer.apple.com/documentation/uikit/app_and_environment/scenes/preparing_your_ui_to_run_in_the_background/updating_your_app_with_background_app_refresh
You have no control of the time. iOS will periodically give you short slices of time
I've been trying to find something about this problem for a few days, but without any useful results. I'm working on a VoIP app for iOS (using an iPhone 4 running iOS 6.0) in Objective-c which uses remote notifications to notify the user about calls when the client is in background.
My issue is quite strange: When the app is in background and the screen is locked, notifications arrive and work perfectly - they ring, and open the app when opened. But when the application is in background, and the screen is unlocked - for example, we're on the home screen - notifications simply fail to appear, not giving any sign that something happened.
Anybody got any ideas where to look around? The app code handles push notifications correctly when they appear, so that shouldn't be an issue. The notifications get out of our server, so I'm starting to think that there is something about the device's settings. The app is set to a "banner" alert style, and its notifications are enabled.
When the app is running in the background, the notification does not appear. You need to catch it in the App Delegate application:didReceiveRemoteNotification:.
Implement this method and put a UIAlert to see when the notification arrives.
I am writing an alarm clock app for iphone, and I want it to turn on the phone(from standby mode) approx 1hr before the alarm is supposed to go off.
Then I want the app to be active, so I can stream content live without the user having to put the phone in an active-mode.
Any way for an app to switch out of standby?
Without using private api an application can only present alertview (via local or push notification).
And only when user taps "view" button this application can be activated. You can see that in the link you provided - (second to last screenshot)
True, you can always add sound to this notifications - so alarm app can work (and there are many out there) but it can't send itself in the foreground.
Nope that cant be done, once the app went to the background state you lose control on it, and cannot bring it back
There might be a way using notifications. Check this SO question for more info:
Alarm Even Application Closed in 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.
I would like to send data to my app, when it is runs in the background. I know its possible to let the iphone do some background tasks, but is it also possible receive data from a server when the iPhone is in the background. So that when the iPhone receives this data, i can change the behaviour of the 'background' app.
I am also aware of push notification, but what i mean is that the user wont be notified.
No this is not possible, there are 3 background apps allowed by apple. Those are VOIP, audio and location based apps.
There is no other way to push data to an app other then push notifitcaions. but your app only receive the notification when the opens the notification.
The only other thing you can do is poll if the server has any new data for your app, but you can't really do this while in the background.