是的。终于我得到了这个问题的解决方案。
顺便说一句。我使用 Cocoapods 在我的项目中安装 GCDWebServer,并且我将我的电视应用与我的手机应用一起构建,但它们是不同的目标。
就我而言,我使用 Objective-C 编写我的手机应用程序并使用 Swift 编写电视应用程序。所以我应该添加 bridging header 到我的电视目标。
TARGETS > YOUR-TV-TARGET > Build Settings > Swift Compiler > Objective-C Bridging Header > 添加这个
$(SRCROOT)/YOUR-TV-PROJECT/YOUR-PROJECT-MODULE-Bridging-Header.h
然后我在我的项目中创建这个头文件并添加
#import <GCDWebServer/GCDWebServer.h>
#import <GCDWebServer/GCDWebServerDataResponse.h>
如何在 Swift 和 Objective-C 之间架起一座桥梁,你可以点击这个链接:
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html
然后我遇到了这个问题
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_GCDWebServer", referenced from:
objc-class-ref in AppDelegate.o
"_OBJC_CLASS_$_GCDWebServerDataResponse", referenced from:
objc-class-ref in AppDelegate.o
"_OBJC_CLASS_$_GCDWebServerRequest", referenced from:
objc-class-ref in AppDelegate.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我认为我的构建可能有问题。可能缺少一些库。所以我转到 TARGETS > YOUR-TV-TARGET > Build Phrase > Link Binary With Libraries 并添加这些框架等:
libxml2.2.tbd
libz.1.2.5.tbd
CFNetwork.framework
MobileCoreServices.framework
UIKit.framework
这是我的 TV-TARGET 的 Build Phases。我们还应该检查 Pods > GCDWebServer > Build Settings 等。因为它在 Pods 中,所以我们必须编辑 Podfile 并重建我的项目。这是 Podfile。你应该在 Podfile 中分离目标。
source 'https://github.com/CocoaPods/Specs.git'
def common_pods
pod 'Fabric' , '~> 1.6.4'
end
def tv_pods
pod 'GCDWebServer' , '~ 3.3.2'
end
target :phoneApp do
link_with 'YOUR-PHONE-TARGET'
platform :ios, '8.0'
common_pods
end
target :tvApp do
link_with 'YOUR-TV-TARGET'
platform :tvos, '9.0'
tv_pods
end
编辑 Podfile 并运行后:
pod install
您可以在 TV-TARGET 中调用 GCDWebServer,而 GCDWebServer 在您的 tvOS 中运行良好。 :-)
希望对你有帮助。