使用 Swift 3 在 Xcode 8 中为 WatchOS 和 iOS 构建嵌入式框架 [英] Building an embedded framework for WatchOS and iOS in Xcode 8 with Swift 3

查看:28
本文介绍了使用 Swift 3 在 Xcode 8 中为 WatchOS 和 iOS 构建嵌入式框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将最初用 Swift 1 编写的所有 iOS + WatchOS 1 应用程序移植到最新的 Xcode 8、WatchOS 3、Swift 3.

I am in the process of porting an all iOS + WatchOS 1 app written originally in Swift 1, to the latest Xcode 8, WatchOS 3, Swift 3.

我的应用有一个嵌入式框架,其中包含一些常用功能,用于为 watchkit 扩展目标和 ios 应用目标编译和运行文件.

My app has an embedded framework with some common functionality that used to compile and run file for both the watchkit extension target and the ios app target.

使用 Xcode 8,我似乎无法再使用它.当我尝试在 watchkit 扩展代码中import 框架时,出现 module not found 错误.

With Xcode 8 I can no longer seem to get this to work. When I try to import the framework in the watchkit extension code, I get the module not found error.

是否仍然可以在目标 iOS 和 WatchKit 扩展目标上编译和使用一个嵌入式框架包?在我的框架中,我将目标平台设置为 watchos, watchsimulator, iphoneos, iphonesimulator.

Is it still possible to compile and use one single embedded framework package on both the target iOS and WatchKit extension targets? In my framework I have the target platforms set to watchos, watchsimulator, iphoneos, iphonesimulator.

我的直觉告诉我这不可能了.最初所有代码真正在手机上运行,​​而不是在实际手表和手机上运行,​​您需要专门为每个代码编译一个嵌入式框架.

My gut says it's not possible anymore. Where originally all the code really ran on the phone itself, not that codes runs on the actual watch and the phone, you'd need to compile an embedded framework specifically for each.

推荐答案

简短版本:你不能.创建一个重复的目标并将其设置为使用手表 SDK.

Short version: You can't. Create a duplicate target and set it to use the watch SDK.

来自 Apple 文档的更长版本:https://developer.apple.com/library/content/documentation/General/Conceptual/WatchKitProgrammingGuide/iOSSupport.html#//apple_ref/doc/uid/TP40014969-CH21-SW1

Longer version from Apple's docs: https://developer.apple.com/library/content/documentation/General/Conceptual/WatchKitProgrammingGuide/iOSSupport.html#//apple_ref/doc/uid/TP40014969-CH21-SW1

包括:

注意

在为 WatchKit 创建单独的框架目标之后扩展,您必须单独管理该框架的内容适用于 iOS 和 watchOS.如果您将文件添加到 iOS 版本的框架,记得在watchOS版本中添加.

After you create a separate framework target for your WatchKit extension, you must manage the contents of that framework separately for both iOS and watchOS. If you add files to the iOS version of the framework, remember to add them to the watchOS version.

这篇关于使用 Swift 3 在 Xcode 8 中为 WatchOS 和 iOS 构建嵌入式框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆