Reputation:
Is there any way to find if watch app is in frontmost (from iPhone or not)? The problem is that when the watch app is in frontmost state, it accesses both the
applicationWillResignActive()
and applicationDidEnterBackground()
extensionDelegate methods.
So how to check if the watch app is in frontmost state or not?
Upvotes: 2
Views: 2304
Reputation: 54706
According to the documentation of WKExtension, there is no built in method to check whether an app is the frontmost app or not. Even the WKApplicationState
enum doesn't have a case for determining whether your app is the frontmost app or not.
Moreover, when an app becomes the foremost app (right after the user lowers their wrist when the app is running in the foreground), the app briefly goes to background mode, then becomes suspended by design. So it is the expected behaviour that the system functions applicationWillResignActive()
and applicationDidEnterBackground()
are called, since the application actually goes to the background mode.
In watchOS3
, the foreground app has no benefits that developers could take advantage of other than the fact that the system resumes app state automatically for the foreground app.
In watchOS 4, the frontmost app gains the following additional advantages:
performExpiringActivity(withReason:using:)
method to complete tasks in the background.Upvotes: 1
Reputation: 2074
On iPhone, you can check isReachable
value of WCSession
.
According to WCSession documentation, isReachable
is true when:
A paired and active Apple Watch is in range, the corresponding WatchKit extension is running, and the WatchKit extension’s isReachable property is true.
Upvotes: 1