I have an app that needs to perform some actions based on a TTimer.
When the app becomes inactive (in background), the timer stops working.
I could not find any relevant options for UIBackgroundModes.
How can I make a timer keeps running?
iOS pauses your app automatically shortly after it goes into the background. You need to let iOS know that you are going to continue operating in the background.
In Project > Options > Version Info you can add to the array key UIBackgroundModes the string values for the services that require to continue running in the background. This gets added to the info.plist for your project on iOS.
You can consult Apple's documentation on what these values do . . .
Value - Description
audio - The app plays audible content in the
background.
location - The app provides location-based information to
the user and requires the use of the standard location services (as
opposed to the significant change location service) to implement this
feature.
voip - The app provides Voice-over-IP services. Apps with this
key are automatically launched after system boot so that the app can
reestablish VoIP services. Apps with this key are also allowed to
play background audio.
fetch - The app requires new content from the
network on a regular basis. When it is convenient to do so, the
system launches or resumes the app in the background and gives it a
small amount of time to download any new content. This value is
supported in iOS 7.0 and later.
remote-notification - The app uses
remote notifications as a signal that there is new content available
for download. When a remote notification arrives, the system launches
or resumes the app in the background and gives it a small amount of
time to download the new content. This value is supported in iOS 7.0
and later.
newsstand-content - The app processes content that was
recently downloaded in the background using the Newsstand Kit
framework, so that the content is ready when the user wants it. This
value is supported in iOS 5.0 and later.
external-accessory - The app
communicates with an accessory that delivers data at regular
intervals. This value is supported in iOS 5.0 and later.
bluetooth-central - The app uses the CoreBluetooth framework to
communicate with a Bluetooth accessory while in the background. This
value is supported in iOS 5.0 and later.
bluetooth-peripheral - The app
uses the CoreBluetooth framework to communicate in peripheral mode
with a Bluetooth accessory. The system will alert the user to the
potential privacy implications of apps with this key set. See Best
Practices for Maintaining User Privacy for more information on
privacy. This value is supported in iOS 6.0 and later.
Notice you need to actually select the mode that matches what you are doing. You can't just select fetch when really all you are doing is background processing.
Related
I am developing an app in Xamarin Forms which will show thing live position of the user on a map and all the users having the app can track other users movement.
Right now the app is working fine in android. But in the iOS foreground, android background it stops after some time. It is not at all running in ios background when I put the app in the background it stops showing the location and stops fully.
Please share some idea to keep the app live in background and foreground mode for the whole day.
Generally speaking, mobile OSs will stop your apps, when they are in the background for some time. How strict the OSs are depends on the OS and the version. iOS has "always" been very strict about it, Android has been a bit more loose in older versions, but is quite restrictive in newer versions. Anyway, getting the location in background is quite a common use case and OSs are providing you options to do it nevertheless, if you ask them politely.
iOS
As of iOS 11, there is a distinction between updating the location when in use and when in background. The user can choose which one to grant and you'll have to handle it appropriately.
According to this guide you'll have to add the NSLocationAlways key to your Info.plist to contimue getting the location when in background.
Android
From the Android developer guide
In an effort to reduce power consumption, Android 8.0 (API level 26) limits how frequently background apps can retrieve the user's current location. Apps can receive location updates only a few times each hour.
Anyway
The system distinguishes between foreground and background apps.
An app is considered to be in the foreground if any of the following is true:
It has a visible activity, whether the activity is started or paused.
It has a foreground service.
...
According to this, you can create a foreground service, see here more about it
For this reason, foreground services must show a status bar notification with a priority of PRIORITY_LOW or higher, which helps ensure that the user is aware of what your app is doing.
So if you are starting a foreground service that is shown in notification bar, you should be able to retrieve updates, even if your apps main Activity is not in foreground.
I know iOS allows background tasks to run and, for example, continue to receive location updates, but is it possible to do this in a watch app?
In Xcode 9.3, I have configured my app for "background modes" and selected location, and that has created for the WatchKitExtension's an Info.plist, an entry for "Required background modes" of "App registers for location updates".
But my watch app still suspends when the screen turns off, and when it is in the dock.
The App Programming Guide for watchOS, however seems to exclude the possibility of running in the background to receive location updates as it only allows background processing for four classes of activity:
Background App Refresh Tasks. Use a WKApplicationRefreshBackgroundTask object to ...
Background Snapshot Refresh Tasks. Use a WKSnapshotRefreshBackgroundTask object to update ...
Background Watch Connectivity Tasks. Use a WKWatchConnectivityRefreshBackgroundTask object to receive data sent by your iOS app ...
Background NSURLSession Tasks. ...
Other posts to SO indicate it's not possible, but proving a negative is difficult, so I'm asking again:
Am I "flogging a dead horse" by trying to keep the watch App operating in the background for receiving location updates, or is Xcode is making promises that WatchOS won't deliver.
I'm delighted to be able to report that the horse I have been flogging for the past two weeks was not dead after all!
I have discovered an additional state in which my watch app will continue to run in the Background which does not require HKWorkoutSession.
These settings did the trick:
locationManager.allowsBackgroundLocationUpdates = true
and in watchKitExtension info.plist:
set UIBackgroundModes (Required background modes) to location (App registers for location updates)
And I repeat: I am NOT using healthKit
Now my app continues to run even when the screen is off and when the app is out of the Dock.
No, it is not possible.
As the WatchKit Programming Guide clearly states, WatchKit apps cannot use background execution except for 3 use cases:
Network operations using URLSession
Playing audio using WKAudioFilePlayer or WKAudioFileQueuePlayer
Run a workout using HKWorkoutSession
You cannot receive location updates in the background, according to the WatchKit Programming Guide, that should be done in the iOS app that is connected to your watchOS application.
I have a bunch of iPads that are all supervised, and that are enrolled into a MDM server (Mavericks Server). I've added the app to the specific device group, but when I go to the profile settings and Single App Mode the only apps I can select are the builtin ones.
Is there no way to use a third party (enterprise) app as the app for Single App Mode?
EDIT: If you use Apple Configurator and add the app there you can set Single App Mode to use that app, I would imagine that would be possible when doing the same in Apple's Profile Manager, but it doesn't seem to be working here.
EDIT2: Looking at Apple's documentation it does indeed seem to be possible to select a third party app for single app mode using their Profile Manager, so why isn't the app showing in the list for me?
http://images.apple.com/education/docs/assessment_with_ipad_mar2013_v2.pdf
Go to the Device Group, after installing the app (that you want to show in Single App Mode dropdown and lock it to) do "Update Info" (small icon in bottom-middle-left of screen) on all the devices in that group. Wait a bit, then go to Single App Mode screen again, the app should start appearing.Works for me. The "Update Info" thing also works for Single Device as well and you can lock to any new app installed from Profile Manger, doesn't matter if the app was installed while supervising through Configurator or not.
So interestingly enough in the new update for Server (3.1.1) this seems to be working. The Enterprise app is now listed in the dropdown box.
However there also is about 10 empty items in the box with no text description. So it's clearly still a bit buggy.
I am developing a windows phone app that uses users current location, I am making the app in 7 OS. My question is, Can I track the location in background, that is when the screen is locked?
I know this is a possibility in wp8 as it provides us with GeoLocator class, but can I achieve this in wp7? I am basically making a runtracker app hence I would like my app to track the location even when its in background, is it really feasible?
Your help is always appreciated!!
It is possible to keep the app running under lock screen, as it does, for example, Endomondo app.
Using Idle Detection, you can keep the app on, although screen is locked, and you can keep on tracking the location. Actually, it is not running in background, but in the foreground. Just the screen is locked. So, be careful not to drain user's battery.
You have to set the PhoneApplicationService.ApplicationIdleDetectionMode property to Disabled, for example in InitializePhoneApplication() method in App.xaml.cs:
PhoneApplicationService.Current.ApplicationIdleDetectionMode = IdleDetectionMode.Disabled;
Note that there are special certification requirements for this type of apps. Refer to section 6.3 (Apps running under a locked screen) of the following page:
Additional requirements for specific app types for Windows Phone
I got the same problem in one on my apps..
I don't think it' s feasible for wp7..
Bt if you want to do it with wp8 you can refer following link.
http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj681691%28v=vs.105%29.aspx
And to know about background supported and unsupported API's http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202942%28v=vs.105%29.aspx/css
GeoCoordinateWatcher Class exists in WP7, but here is the documentation from MSDN -
This API, used for obtaining the geographic coordinates of the device,
is supported for use in background agents, but it uses a cached
location value instead of real-time data. The cached location value is
updated by the device every 15 minutes.
More Info : http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202962%28v=vs.105%29.aspx/css
I want to use a timer in a windows mobile app. Of course, this is not the problem.
The problem: the timer needs to be called even during standby and sleep mode.
Simply switching off the sleep mode is not really an option, since the app needs to comply to windows marketplace for mobiles requirements, and regarding to requirement 5.2 a marketplace app "shall not modify power management options".
Is there a system timer, which could be used to get an event called (like CeSetUserNotificationEx can be used to get an app started)?
Or how would I create a persistent timer?
CeRunAppAtTime can be used to set a named system event (not just to run an app). If the device is in sleep mode when that time arrives, it will wake.