我们正在使用Xcode 6 beta 5 + Swift和iOS 8 SDK创建一个应用程序。我们希望也能部署到iOS 7上。这是可能的吗?当我们将项目的部署目标设置为7.0时,我们会得到类似以下的编译错误:
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_WKPreferences", referenced from:
__TMaCSo13WKPreferences in WebViewController.o
"_OBJC_CLASS_$_WKWebView", referenced from:
__TMaCSo9WKWebView in WebViewController.o
"_OBJC_CLASS_$_WKWebViewConfiguration", referenced from:
__TMaCSo22WKWebViewConfiguration in WebViewController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我认为这是因为我们正在使用WKWebKit
,它只支持iOS 8及以上版本。我们可以在iOS 7上使用UIWebKit
,但在iOS 8上要使用WKWebKit
。如何定义呢?
我们的类定义看起来像这样...
import WebKit
class WebViewController: UIViewController, WKNavigationDelegate {
...
}
并且它是通过以下方式调用的:
let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
let destinationVC = mainStoryboard.instantiateViewControllerWithIdentifier("WebViewController") as WebViewController
presentViewController(destinationVC, animated: true, completion: nil)
我在考虑使用这个片段来调用presentViewController
,但这并不能解决编译时的问题。(NSFoundationVersionNumber
也不能解决编译时的问题)
if ((UIDevice.currentDevice().systemVersion as NSString).floatValue >= 8.0) {
} else {
}
更新:kkoltzau给出了正确答案。我为其他人添加了更多信息。
首先,进入您的Project
,点击General
,向下滚动到Linked Frameworks and Libraries
,并将WebKit.framework
添加为可选项。(我还为UIKit.framework
这样做了)请参阅屏幕截图:
至于我的WebViewController
类。它仍然导入UIKit
和WebKit
,但viewDidLoad()
基于kkoltzau的示例设置视图。然后,每当我需要加载/重新加载网页时,它都会检查wkWebView
是否存在。