I'm realy confused about this subject, my question is simple: when the application: didReceiveRemoteNotification: fetchCompletionHandler: will be called?
if the application is running and in foreground ? i test and the response is yes for iOS 7 and no in iOS 6 as described in the function comment.
if the application is in background and running ? response: same as 1.
if the application is in background but suspended by the system ?
most importent point: if the application is killed (not in the "multitask view")?
how i activate/handel the notification :
add the remote motif in xcode capabilities section (in info.plist).
ask to register :
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeNewsstandContentAvailability]
3 . implement the delegate method. (add inside completionHandler(UIBackgroundFetchResultNewData);)
when i send a notification (with the content-available key==1) :
if the app is in foreground/background and running the function is triggered and the code inside is performed (i download an image and save it in documents folder).
if the app is killed, the image is not downloaded.
second question : have you any easy why to debug remote notification background mode?
[edit] after tests, if the app is suspended (we add a loop to log date) it receive the notification and try to trigger code, but the app is stopped after 1 seconde, have we miss a parameter to encase duration ? (as i read the maximum is 30 secondes).
Sorry to answer my own question,
to be simple the remote notification is only handled when the application is in background(active/suspended).
[EDIT]: if you want to have a push notification that awake the app even if it is killed take a look at PushKit but this only possible if you have VOiP feature in your app.
Related
I am using Expo to build an app that will pop up a notification with custom sound and vibration when triggered remotely. The alarm/vibration would play until its dismissed by the user or it times out (say after 1-2 mins) .
Example use case would be when a partner needs my immediate help with baby, they can press a button the app and that would send signal to backend server which would then trigger the notification with alarm on the app at the other end. When the notification is dismissed, an acknowledgement message is sent with Yes or No type message. If the notification times out, then another message is sent like "no response".
Key point to note is that when the app is fully closed, the notification should still be able to pop up.
From my limited understanding , expo notification or push notifications in general cannot achieve this as they don't allow us to create notifications that directly open the app. Even a solution which works like phone or video calling apps (which open when someone calls you ) could work.
Any help would be much appreciated.
Many Thanks!
I looked up expo push notifications but they are limited in terms of customising the notifications.
From this link below, it seems that your app can still get event when app is switched to background. But it seems it is used only for location based app. Can normal app do that? I had tried to declare ID_CAP_LOCATION but still Application_RunningInBackground not get called when switch to background.
http://msdn.microsoft.com/en-us/library/windowsphone/develop/microsoft.phone.shell.phoneapplicationservice.runninginbackground(v=vs.105).aspx
The app doesn't execute in background, unless it is continously tracking the location.
This section lists the conditions under which the operating system
will deactivate an app running in the background....
The app stops actively tracking location. An app stops tracking location by removing event handlers for the PositionChanged and
StatusChanged events of the Geolocator class or by calling the Stop()
method of the GeoCoordinateWatcher class.
Source: Running location-tracking apps in the background for Windows Phone 8
You will find complete info of how to run apps in background here:
How to run location-tracking apps in the background for Windows Phone 8
I'd like to know if is possible to send asynchronous connections when an app is in background. The reason for this is because I need to send the user's location (get from Core Location) to update a database in a remote server everytime the location changes, even if the app is not in foreground.
Do I have to set any permission for this? Does Apple rejects apps processing connections when app is in background?
Thanks in advance!!
iOS provides multitasking API's i.e. even if your app is in background, some of its API's can be accessed. These services are -
Local Notifications
Background Audio
Background Tasks
Background Location
So you can definitely send location updates using CoreLocation when the app is not in foreground.
This link - iOS multitasking has code to start your service when app in background. Step by step instructions
Specify location background mode
Use an NSTimer in the background by using UIApplication:beginBackgroundTaskWithExpirationHandler:
In case x time is smaller than UIApplication:backgroundTimeRemaining it does works just fine, in case x is larger, the location manager should be enabled (and disabled) again before there is no time remaining to avoid the background task being killed. This does work since location is one of the three allowed types of background execution.
SOURCE - How do I get a background location update every n minutes in my iOS application?
Here, from the apple documentation (http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html#//apple_ref/doc/uid/TP40007072-CH4-SW47)
There are several ways to track the user’s location in the background, most of which do not actually require your app to run continuously in the background:
-The significant-change location service (Recommended)
-Foreground-only location services
-Background location services
But you cannot send request, as the only possible things to do are :
-audio
-location
-voip
-newsstand
-Accessories & blutooth connection
So I guess you could store all your location, and send it with NSURLConnection once the app goes to foreground again
I have an iPad app in the App Store whose logic relies largely on local notifications. In other words, much that happens inside the app is triggered by the delegate method application didReceiveLocalNotification.
With today's release of iOS 5, I see that apps can be placed (via Settings) either "In Notification Center" or "Not In Notification Center." I haven't found anything in the new documentation so far, but I'm hoping there is a way to have my app "In Notification Center" by default, (and possibly even set Sounds active and the notification type to Alert) which would save me having to explicitly explain to new users that after they download & install my app, they will have to manually go and elect for the app to be "In Notification Center."
Anyone know if this is possible? Seems that since an app can register a local notification, it should be able to receive it, by default (whether it displays an alert or an item in the new Notification Center, or not). Thanks in advance.
I've encountered the same problem. The only clue I saw in documentation is that the new Notification Center handles both local and remote notifications. Therefor I assumed that the app should register for local as it would for remote notification. Added this piece of code -
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
and after my app scheduled a local notification it appeared at the "In Notification Center".
BUT it seems to have no affect if my app already appears in "Not In Notification Center".. So have all of my customers that ran the app before the next update got screwed?
Currently it seems not.
I'm in a similar situation. I'd love to be wrong about this but I've found no mention of any such API (for specifying that a local-notification using app should appear in notification center by default) in any of the places I'd expect it to be:
Local and Push Notification guide
UIApplication class reference
UIKit Info PList keys
UIApplicationDelegate Protocol reference
I want to register my app for push notification when my application terminates so i think if i delay my app quitting time it could be possible.Does someone knows how to delay application quitting time? I think this method
[self performSelector:(SEL)aSelector onThread:(NSThread *)thr withObject:(id)arg waitUntilDone:(BOOL)wait];
will do my job but i don't know how to use this method if someone knows please tell.I need to send some data to a server along with registering for Push Notification when my app quits.
I can't imagine why you would want to do this. If it were even possible it would be extremely annoying for a user to tap the home button and the app to take x amount of time to shut down. This time 'x' being dependent on the server connection creates even more user headache.
Apple have the home button exit apps immediately for a reason.
If you want to register the Push Notifications like you suggest, do it while the app is running. If your worrying that they won't be properly set if the user exits prematurely... don't.
As users, we all know there are sometimes consequences of exiting a program without giving it time to save your settings.
For push notification it is better to register when the app first starts and then send the push token to your server in the background. However, if you have a good reason why you need to do the registration just as the app terminates, I believe you can do this if you are using iOS 4. iOS 4 has a new feature called "task finishing" that allows an app to stay running for a few minutes after the user closes it so that it may finish up any tasks it was in the middle of (such as saving data).