简体   繁体   中英

How long iOS app is running if Apple Watch wakes it up?

When I call sendmessage on the watch, and send a message to the iPhone app, but the iPhone app is not running then the iPhone app wakes up, it's didfinisihlaunching method is called. As the documentation says: "Calling this method from your WatchKit extension while it is active and running wakes up the corresponding iOS app in the background and makes it reachable."

My question: once it's running it works like as if the user had opened it explicitly, it makes network requests and regularly refreshes its UI. But what happens next? Will the app terminate sometime? Or it keeps on working forever in the background? When I wake up an app in the background for a background fetch I explicitly tell the system that I am finished. But nothing like this happens here.

Sorry if I am missing something here. :)

Generally a background task handler is used in this case which allows app to run for 180 sec only.

__block UIBackgroundTaskIdentifier backgroundTaskIdentifier = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{

    NSLog(@"Background Time:%f",[[UIApplication sharedApplication] backgroundTimeRemaining]);

    [[UIApplication sharedApplication] endBackgroundTask:backgroundTaskIdentifier];

    backgroundTaskIdentifier = UIBackgroundTaskInvalid;
}];

If you want to run the app for more than that time then enable one of the Background modes using plist file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM