Skip to content

Instantly share code, notes, and snippets.

@Ingelheim
Last active August 29, 2015 14:26
Show Gist options
  • Save Ingelheim/56a236934ac055bf45b1 to your computer and use it in GitHub Desktop.
Save Ingelheim/56a236934ac055bf45b1 to your computer and use it in GitHub Desktop.
func application(application: UIApplication,
handleWatchKitExtensionRequest userInfo: [NSObject : AnyObject]?, reply: (([NSObject : AnyObject]!) -> Void)!) {
// This needs to be done to keep the app busy, before the process is killed bu the phone
var workaround: UIBackgroundTaskIdentifier?
workaround = UIApplication.sharedApplication().beginBackgroundTaskWithExpirationHandler({
UIApplication.sharedApplication().endBackgroundTask(workaround!)
})
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), {
UIApplication.sharedApplication().endBackgroundTask(workaround!)
})
var realBackgroundTaks: UIBackgroundTaskIdentifier?
realBackgroundTaks = UIApplication.sharedApplication().beginBackgroundTaskWithExpirationHandler({
UIApplication.sharedApplication().endBackgroundTask(realBackgroundTaks!)
})
// Do here what you want to do, e.g. handle the request from the watch
// reply([:])
UIApplication.sharedApplication().endBackgroundTask(realBackgroundTaks!)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment