Background Tasks

RSS for tag

Request the system to launch your app in the background to run tasks using Background Tasks.

Posts under Background Tasks tag

129 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Background task with MFi External Accesory device
We are developing an app that is going to be used with hardware that is connected through bluethooth to the iOS device, where we use a device with an MFI external accessory, and we are using the external accessory framework, and this will require some background tasks, we understand that there is a limitation on the use on background capabilities, but we were wondering what is the best approach to gather information from the hardware while the app is running on the background? think of the Oura ring, the app is gathering some information while you are sleeping, not processing, not fully running, only gathering information. Should we doit with the BGProcesingTask? or there is an additional background strategy to this kind of use case? Thanks.
0
0
442
Jul ’23
HKObserverQuery BackgroundDelivery not executed
Hi, before installing iOS 15 our app received HKObserverQuery calls in background, which worked like a charm - the calls have reliably woken up our app in background, enabling it to process new HK data. In iOS 15 the new entitlement com.apple.developer.healthkit.background-delivery was added, being mandatory if HKObserverQuery calls should be delivered in background. Indeed, we added the entitlement to the Entitlements file and the Provisioning Profile of the app. After doing so, registering with enableBackgroundDelivery(for:frequency:withCompletion:) worked again without an error. While testing we observed that the app is not called at all. To debug, we captured system logs of an iPhone with iOS 15 - you can find them attached. syslog It can be seen that HK background delivery tries to fire, but dasd decides to not proceed because of the ApplicationPolicy. After some research we found this might be related to background modes capabilities. Thus we added "Background fetch" and "Background processing". Anyhow, this did not change the behavior. Again, this background delivery perfectly worked on iOS 14 - we did not change anything except adding the new background delivery entitlement (and the background processing entitlements in a second try). Are we missing any (new?) entitlements? Any other news in iOS 15 making further changes necessary? Is HKObserverQuery working for others in background mode? Thanks in advance for considering and best regards, Nils Notes on the logs: App was suspended at all times iPhone was unlocked from the beginning on iPhone was locked at 13:16
20
1
6.6k
Jul ’23
Why must I wrap a call to call to an async/await method in a Task?
Trying to to convert my old URL functionality to SwiftUI with async/await. While the skeleton below works, am puzzled as to why I must place my call to the method within a Task? When I don't use Task I get the error: Cannot pass function of type '() async -> Void' to parameter expecting synchronous function type From the examples I've seen, this wasn't necessary. So I either I've misunderstood something, or I am doing this incorrectly, and am looking for little but of guidance. Thank you Within my SwiftUI view: Button { Task { let request = xFile.makePostRequest(xUser: xUser, script: "requestTicket.pl") var result = await myNewURL.asyncCall(request: request) print("\(result)") } } From a separate class: class MyNewURL: NSObject, ObservableObject { func asyncCall(request: URLRequest) async -> Int { do { let (data, response) = try await URLSession.shared.data(for: request) guard let httpResponse = response as? HTTPURLResponse else { print("error") return -1 } if httpResponse.statusCode == 200 { ... } } catch { return -2 } return 0 } }
1
0
1.8k
Jul ’23
I want to close my app after a while in background mode
I am sorry for my poor English. I know that a callback of timer is not called in background mode. I know that I should add capabilities, permissions and keys into the Info file for doing something in background mode. But I do not need any complicated task in background mode, just need to terminate my app automatically after 30 minutes in background mode. Is there a simple way for that purpose?
4
0
1.1k
Jul ’23
WeatherKit in a background operation?
Sorry if this is a stupid question but I haven't been able to find any information on whether an app can request and receive weatherKit data - the weather - while in the background. My app (AirCompare) makes extensive use of background URL sessions to fetch and process weather data. If certain conditions are met, a notification alert is sent to the user so the user can decide whether to activate the app. For instance if rain is in the forecast, the app alerts the user that they might want to close their windows. Making the app active will execute HomeKit control and accomplish that. Will I be able to replace the background URL session with the appropriate code and be able to fetch weather data in the background?
2
0
869
Jul ’23
How can I tell my app is launched via BGAppRefreshTask/BGProcessTask?
I need to know if my app is launched via BGAppRefreshTask/BGProcessTask in UIApplicationDelegate's application:didFinishLaunchingWithOptions: method, but the launchOptions didn't contain any key about this. A workaround is to check if UIApplication sharedApplication].applicationState == UIApplicationStateBackground in application:didFinishLaunchingWithOptions:, but it cannot tell launch via BGTask part from launch via other methods like silent push.
0
0
304
Jul ’23
Session immediately invalidated when using BLE background mode
Hello everyone, I have encountered an error when trying to enable BLE background mode of the third-party NI example application. I have done that by replacing the configuration = try NINearbyAccessoryConfiguration(data: configData) with configuration = try NINearbyAccessoryConfiguration(accessoryData: configData, bluetoothPeerIdentifier: peerIdentifier) I have additionally expanded the List.plist with Required background modes: App communicates using CoreBluetooth Or rather, central-bluetooth When starting the session, iPhone 12+ Pro Max (iOS 16+) device immediately calls invalidateSession with the error invalidSession. configData is identical for both cases, and implementation on peripheral device has not been changed. Important thing to note here is that for the non-background mode, third-party accessory and iPhone device are able to range just fine. Do you have any recommendations or advice how we can try to solve this, or what might be an issue? Thank you in advance, Aleksa and OBLO Living development team.
1
0
1.4k
Jul ’23
NI session keep timeout when apps running in background
Hi All I can run the nearby interaction even the apps is in background, while there is a distance information in the accessory side, the apps invoke delegate function "didRemove nearbyObject" with timeout periodically. is there any way to disable the timeout when it is running in background? Or anything I did wrong so that the session keep timeout while there is distance measurement in accessory side, please anyone help. Thanks in advance
0
0
564
Jul ’23