I had this problem before, and the reason is that you did not register a long background operation, and the system killed it. Here is how I sorted it, please see Comments for an explanation, this is all in the AppDelegate file, and it’s quick, but you can easily transfer it to Objective-c:
private var backgroundTask: UIBackgroundTaskIdentifier = UIBackgroundTaskInvalid
func registerBackgroundTask() {
backgroundTask = UIApplication.sharedApplication().beginBackgroundTaskWithExpirationHandler {
[unowned self] in
self.endBackgroundTask()
}
assert(backgroundTask != UIBackgroundTaskInvalid)
}
func endBackgroundTask() {
UIApplication.sharedApplication().endBackgroundTask(backgroundTask)
backgroundTask = UIBackgroundTaskInvalid
}
func application(application: UIApplication, handleWatchKitExtensionRequest userInfo: [NSObject : AnyObject]?, reply: (([NSObject : AnyObject]!) -> Void)!) {
registerBackgroundTask()
reply(nil)
if self.backgroundTask != UIBackgroundTaskInvalid {
self.endBackgroundTask()
}
}
source
share