如果当前目标有可用的手表应用程序版本,如何签入代码?
How to check in code if current target has watch app version available?
我在一个视图中工作,我应该根据应用程序是否有 Watch 版本对其进行自定义。
我知道我可以使用:
[[WCSession defaultSession] isWatchAppInstalled]
(但这不是我想要的,因为用户可以在 Apple Watch 中卸载该应用程序,但 iOS 应用程序仍然可以安装 Watch 版本)
还有:
[[WCSession defaultSession] isPaired]
不是我的情况。
实际上 isWatchAppInstalled 是处理这种情况的正确方法。
如文档所述:
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
属性 不会在捆绑包内部查看是否有 Watch 应用程序可用。只有在当前配对的 Apple Watch 上安装了 Watch 应用程序时,它才会 return 为真。如果用户从手表中删除 Watch App,它将 return false。
在检查了我正在处理的当前项目并测试了创建两个新项目来检查捆绑包之后(一个项目包含 watch,另一个不包含 watch),我看到了它们之间的区别:
不同之处在于包含手表的项目有一个构建阶段,该阶段将手表应用程序嵌入到名为 "Watch" 的子目录中。
在 Finder 中显示构建的包内容时,我们还可以看到 "Watch" 文件夹:
因此,只要 iOS 应用在代码中嵌入了 Watch,条件就是:
+ (BOOL)isWatchAppEmbedded
{
NSString *watchPath = [NSString stringWithFormat:@"%@/%@", [NSBundle mainBundle].resourcePath, @"Watch"];
BOOL isDirectory = YES;
if ([[NSFileManager defaultManager] fileExistsAtPath:watchPath isDirectory:&isDirectory]) {
return YES;
}
return NO;
}
我在一个视图中工作,我应该根据应用程序是否有 Watch 版本对其进行自定义。
我知道我可以使用:
[[WCSession defaultSession] isWatchAppInstalled]
(但这不是我想要的,因为用户可以在 Apple Watch 中卸载该应用程序,但 iOS 应用程序仍然可以安装 Watch 版本)
还有:
[[WCSession defaultSession] isPaired]
不是我的情况。
实际上 isWatchAppInstalled 是处理这种情况的正确方法。
如文档所述:
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
属性 不会在捆绑包内部查看是否有 Watch 应用程序可用。只有在当前配对的 Apple Watch 上安装了 Watch 应用程序时,它才会 return 为真。如果用户从手表中删除 Watch App,它将 return false。
在检查了我正在处理的当前项目并测试了创建两个新项目来检查捆绑包之后(一个项目包含 watch,另一个不包含 watch),我看到了它们之间的区别:
不同之处在于包含手表的项目有一个构建阶段,该阶段将手表应用程序嵌入到名为 "Watch" 的子目录中。
在 Finder 中显示构建的包内容时,我们还可以看到 "Watch" 文件夹:
因此,只要 iOS 应用在代码中嵌入了 Watch,条件就是:
+ (BOOL)isWatchAppEmbedded
{
NSString *watchPath = [NSString stringWithFormat:@"%@/%@", [NSBundle mainBundle].resourcePath, @"Watch"];
BOOL isDirectory = YES;
if ([[NSFileManager defaultManager] fileExistsAtPath:watchPath isDirectory:&isDirectory]) {
return YES;
}
return NO;
}