gpt4 book ai didi

iOS WatchKit - 如何确定您的代码是在 watch 扩展程序中运行还是在应用程序中运行

转载 作者:可可西里 更新时间:2023-11-01 03:38:37 25 4
gpt4 key购买 nike

有了 WatchKit,您的应用程序可以在手机上运行,​​ watch 应用程序可以作为扩展程序运行。

如果您创建的库包含在手机应用和 watch 扩展中使用的通用代码,有没有办法判断代码是在手机应用还是在 watch 扩展中运行?

if ([self isRunningInWatchExtension]) {
NSLog(@"this is running on watch");
} else {
NSLog(@"this is running on phone app");
}


- (BOOL)isRunningInWatchExtension {
???
}

最佳答案

在目标条件句中,有一些条件句可能对您有所帮助,

#if TARGET_OS_WATCH
//do something for watch
#else
//do something for ios ==> assuming you only support two platforms
#endif

关于iOS WatchKit - 如何确定您的代码是在 watch 扩展程序中运行还是在应用程序中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29354990/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com