iosswiftwatchkitcore-motion

is there anyway to keep my WatchKit app running in the background?


I'm a newbie on swift and WatchKit framework.I'm studying this from only a month.Now my question is:is possible running an app in background mode on the apple watch?I read from the documentation that the WatchKit extensions do not support background execution modes.But if this thing is true how to work apps like health app?I mean,on the watch there is an app called health that takes at each instant of time your hearth rate even if the app is not in foreground.I would do the same thing more or less.In my app I would detect the user acceleration only when the user move the watch even if the app is not in foreground.How can I do? Please to post me the necessary documentation to do so.Thanks a lot!

Ps. sorry for my english!


Solution

  • Yes, you can. There are several ways:

    1. Start a workout using HKWorkoutSession - the most powerful way, however you need to use HealthKit and only 1 app on the Apple Watch can run this way.
    2. Play audio in the background using WKAudioFilePlayer - only for audio.
    3. WKURLSessionRefreshBackgroundTask suitable for short background refreshes.
    4. There are other background tasks, such as WKSnapshotRefreshBackgroundTask or WKURLSessionRefreshBackgroundTask. They are listed in Background Tasks section of this article.
    5. performExpiringActivity(withReason:using:) can be used to shortly prolong life of the app when it goes to the background.

    Also, read Leveraging iOS Technologies.