Reputation: 1203
I'm working in a view where I should customize it regarding if there is a Watch Version of the app.
I know that I can use:
[[WCSession defaultSession] isWatchAppInstalled]
(but that is not what I want because the user can uninstall the app in the Apple Watch but the iOS app will still have the Watch Version available to install)
also:
[[WCSession defaultSession] isPaired]
is not my case.
Upvotes: 0
Views: 248
Reputation: 1203
After checking the current project that I'm working on and also testing creating two new projects to check the bundles (one project with watch and the another without watch included), I saw the difference between them:
The difference is that the project with the watch included has a Build Phase that has the Watch app embedded in the subdirectory called "Watch".
Also we can see the "Watch" folder when Showing the Package Contents of the build in Finder:
So the condition whenever that iOS app has Watch embedded in code is:
+ (BOOL)isWatchAppEmbedded
{
NSString *watchPath = [NSString stringWithFormat:@"%@/%@", [NSBundle mainBundle].resourcePath, @"Watch"];
BOOL isDirectory = YES;
if ([[NSFileManager defaultManager] fileExistsAtPath:watchPath isDirectory:&isDirectory]) {
return YES;
}
return NO;
}
Upvotes: 0
Reputation: 566
Actually isWatchAppInstalled is the correct way to deal with this scenario.
As the documentation states:
The user can choose to install only a subset of available apps on Apple Watch. The value of this property is true when the Watch app associated with the current iOS app is installed on the user’s Apple Watch or false when it is not installed.
https://developer.apple.com/documentation/watchconnectivity/wcsession/1615623-iswatchappinstalled
The property does not look inside the bundle to see if a Watch app is available. It will only return true if the Watch app is installed on the currently paired Apple Watch. If the user deletes the Watch App from the watch it will return false.
Upvotes: 1