Background Tasks

RSS for tag

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

Background Tasks Documentation

Pinned Posts

Posts under Background Tasks tag

164 Posts
Sort by:
Post not yet marked as solved
1 Replies
242 Views
I am using background mode for downloading data from the server and storing it in Realm. I am getting weird crash reports from my users. I attached an example crash log. 2022-06-11_09-48-00.9830_+0300-c163f7d73500cb2d0cff0a66c7684b6e7009adcd.crash My code:    private func addParseReportToDb(serverResponses: [AddNewParseReportResponse], trackedProfileRecordId: String) {     let trackedProfile = TrackedProfile.getByPrimaryKey(recordId: trackedProfileRecordId)!     for serverResponse in serverResponses {               let parseReport = ParseReport()       parseReport.biograph = serverResponse.biography               let realm = try! Realm()       try! realm.write({         realm.add(parseReport)       })               createUserFeedWithLatestReports(trackedProfile: trackedProfile)     }   } Above method is calling from below method:    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {           let realm = try! Realm()           let tst = Test()     tst.type = "silent"           try! realm.write({       realm.add(tst)     })           let parseService = InstaParseService()     parseService.downloadLatestReports {       parseService.getUsersForFetch { status in         completionHandler(.newData)       }     }   } parse.downloadLatestReports method calls the addParseReportToDb method. The crash point is realm.add(parseReport) As you can see actually I can add another object before adding the parseReport without any problem. Don't know why but that part crashes sometimes.
Posted
by
Post not yet marked as solved
0 Replies
225 Views
Hello, We are a company working on Ultra Wideband solutions and, hence, using Apple's NearbyInteraction framework to establish UWB Ranging sessions with our UWB-enabled third-party accessory. This week we were excited about the new background UWB Ranging session possibility, which opens new use cases. The wwdc2022 10008 video that provides the technical details for this feature indicates that the third-party accessory is responsible to expose the Nearby Interaction GATT Server. We don't manage to get full details about what needs to be implemented to by compliant with Apple's framework. The URL below indicates that full BLE details should be explained in the "Nearby Interaction Accessory Protocol Specification" but we don't see any info there. https://developer.apple.com/documentation/nearbyinteraction/ninearbyaccessoryconfiguration https://developer.apple.com/nearby-interaction/specification/ Can someone indicate us where the find full details for this background Nearby Interaction feature? Thanks in advance. Regards.
Posted
by
Post not yet marked as solved
0 Replies
108 Views
General: DevForums tag: Background Tasks Background Tasks framework documentation UIApplication background tasks documentation ProcessInfo expiring activity documentation watchOS background execution documentation WWDC 2020 Session 10063 Background execution demystified — This is critical resource. Watch it! WWDC 2022 Session 10142 Efficiency awaits: Background tasks in SwiftUI iOS Background Execution Limits DevForums post UIApplication Background Task Notes DevForums post Share and Enjoy — Quinn “The Eskimo!” @ Developer Technical Support @ Apple let myEmail = "eskimo" + "1" + "@" + "apple.com"
Posted
by
Post not yet marked as solved
0 Replies
101 Views
Hello everybody, I know, that an app can request additionally time in background by calling beginBackgroundTask. But as documentation and many other posts says, it is only designed to finish a possible longer running task. (I tried to extend background execution beyond that by calling beginBackgroundTask with a timer, but that does not seem to reliably work and seems not the way it should be used.) As I am a developer of a fitness app, I am interested in keeping the app running in the background for a longer time (> 30min), if the user decides to turn off the device or to have another app in the front to watch a stream during the training. There should be a way to make this work, since running apps work in the background for multiple hours without being terminated. I even have a simple HitSet-timer-app, that works in the background, while a streaming app is in the foreground. Can anyone help me with that or point me in the right direction? Thank you in advance!
Posted
by
Post not yet marked as solved
1 Replies
215 Views
Hi Apple Team, I have to do some such functionality in my applications that when application is in background, I have to upload the entire gallery assets of the iphone to a server (if the user has given permission to upload). I have come to a point where my background processing is not running for more than 28-30 seconds. And my process is such that I pick up the asset one by one from the gallery and process it and put it in a single task for uploading to the background thread. All this happens in a loop and photos are uploaded one after the other untill 28-30 seconds(in background). As I have also got my app registered for background processing and also coding is running from all standard process according to apple documentation. So I have to ask you something about background processing, my questions are as follows: 1: What is the maximum duration for background processing and background uploading? What if I want to increase the duration of background processing in my app? 2: Does Apple extend the background processing time for certain category of apps, if it does, then please mention those categories(Or share some links). 3: As my application is built for a particular organization(they upload their all photos), I need maximum background upload limit, is there any way Apple provides for that? if yes, could you please share sample code base or links. 4: Some applications like Google Photos etc. upload in the background for more than 30 seconds, is there a standard procedure that I can achieve as well? 5: If there is any framework provided by Apple to do this work then please mention it. Thanks, I am waiting for your kind reply.
Posted
by
Post marked as solved
3 Replies
323 Views
My program is shown in following. I want to get the dataTask session's error code working in background, but I haven't achieved it. let config:URLSessionConfiguration = URLSessionConfiguration.background(withIdentifier: "abcd") self.session = URLSession(configuration: config, delegate: nil, delegateQueue: nil) let task: URLSessionDataTask = session!.dataTask(with: myRequest as URLRequest) task.resume() In the program above, there isn't any parameter with error information, so I rewrite it as following. But when I run the following program, the exception error happens. By the way, about the following program, it can be run successfully when URLSession is configured as normal session, but when URLSession is configured as background session as following, the exception error happens when it's run. Anyone can give me some advice? Thanks a lot! let config:URLSessionConfiguration = URLSessionConfiguration.background(withIdentifier: "abcd") self.session = URLSession(configuration: config, delegate: nil, delegateQueue: nil) let task: URLSessionDataTask = session!.dataTask(with: myRequest as URLRequest) { (data, response, error) in             if let response = response as? HTTPURLResponse {                     NSLog("response.statusCode = \(response.statusCode)")             }        } task.resume()
Posted
by
Post not yet marked as solved
2 Replies
278 Views
I want to create a hands-free application (e.g. smart lock)using the Nearby Interaction framework. Nearby Interaction sessions can only be active when the app is in the foreground, however, it can't be a complete hands-free application. Does anyone have any good ideas?
Posted
by
Post not yet marked as solved
1 Replies
168 Views
I want to send the data from iphone to server periodly in background. I use URLSession (dataTask) to try it , and when my program is changed into background: sometimes, the communication can be kept for several hours without any problem sometimes, the dataTask will be stopped and after several minutes, it will be restarted automatically Is there any method to keep the communication between the iphone and server continuously?
Posted
by
Post marked as solved
9 Replies
753 Views
I am working on some study in sending the data from iphone to server, and I want to keep the communication even when my program is working on the background mode. For the details, when my program monitors the beacon' signal with special UUID by Corelocation( in other words, the iphone is taken into the beacon'region), then in Corelocation's handling function, the dataTask of URLSession will be excuted to forward the BLE signal's information to server. Because the beacon sends the BLE signal periodically and continuously, I think the data will be sent from iphone to sever with my program continuously. But now, my experiment result is, when I change the application into background: -sometimes, the dataTask can be kept for several hours or one or two days without any problem -sometimes, the dataTask will be stopped and after several minutes, it will be restarted automatically (really confusing). And in this case, I find the BLE monitoring program is kept to work, only the dataTask communication has been stopped I want to know the reason and the dataTask's action condition of the above phenomenon such as keeping or stoping or restarting the communication. Is there any method to keep the communication between the iphone and server without any interruption? Thanks a lot!
Posted
by
Post not yet marked as solved
1 Replies
173 Views
I was wondering that how to get pasteboard content when app was in background. It showed that: "retrieving pasteboard named com.apple.UIKit.pboard.general failed with error: Error Domain=PBErrorDomain Code=10 "Pasteboard com.apple.UIKit.pboard.general is not available at this time." And it returned null . how to deal with it ?
Posted
by
Post marked as solved
1 Replies
205 Views
I have a downchannel half-connection to the Amazon Alexa cloud https://developer.amazon.com/en-US/docs/alexa/alexa-voice-service/manage-http2-connection.html#create Now, if the APP enters the background, my connection will be broken. Even if I put it in the backgroundTask, I cannot maintain the connection through ping, How do I maintain this HTTP persistent connection when the APP is in the background, plz。
Posted
by
Post not yet marked as solved
1 Replies
186 Views
Hi dear , I am a beginner developer I have an application idea , and I think its great idea 😎 I think the application needs to use Device activity frame work , and UIScreen class , even if the app is in background or terminated , the problem is I don't know how to use these classes and frameworks 🤷🏻‍♂️ the questions are : can I detect UITouch event on UIScreen object even if the app is in background or terminated How to get the current activity name of the device
Posted
by
Post not yet marked as solved
0 Replies
143 Views
Hi, i'm quite new to iOS Development and i'm looking for some useful informations for my project. The phone connects to a device via BLE and receives data from it at an high rate ( 4x hundreds data points per seconds) [--> Thread 1 ] and this data need to be analyzed in real time [--> Thread 2]. The app has to work for between 1 to 8 hours and all of this needs to work both when the phone is in the foreground and when is in the background (Background Task). Can you help me with any useful tips / information on how to accomplish this? Thank you
Posted
by
Post not yet marked as solved
0 Replies
138 Views
Hi, I have implemented iCloud Sync using NSPersistentCloudKitContainer. However, I have a lot of data to sync in my use case which can take quite some time (minutes) especially when starting with a new device (10's of minutes). I was wondering if there is a way to make good use of BGProcessingTaskRequest (ie long running task over night, potentially with requiresExternalPower). The idea is to let the device catch up with the remote store during such a long running background task over night/during charge. I already tried to hack my way into this by trying to just listen to sync events during the task and not finish the task until sync events have stopped but it seems the sync processor does have its own awareness of the app moving to the background and therefore might not even wake up during the background task. Any idea how I can help the CloudKitContainer to catch up in the background with very large workloads? Thanks!
Posted
by
Post not yet marked as solved
1 Replies
301 Views
This is happening on all iOS 15 apps. I am running on an iPhone 12 mini (iOS 15.4.1) Open any app Close the app and quickly reopen. This will cause the app to crash if you do it fast enough. It seems to work as expected if you wait at least one second before reopening. To resolve this issue close ALL background apps so the "recent apps" are empty. When you do this, the problem in step 2 does not happen. To "re-activate" the crash, open 5 to 10 apps and put them in the background. All apps will then continue to crash when re-opening. All of our crash reports have been for devices running iOS 15. We believe some of the packages we use are having trouble initializing correctly when the app state changes. None of our crashes have been on iOS 14. https://drive.google.com/file/d/1Gg00d9N1_N94yxkHpyfVAqiCEiTX9c1M/view?usp=sharing
Posted
by