xcode UIWebView 和 WKWebView
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27615041/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UIWebView and WKWebView
提问by Nicoll
I want to use WKWebView for IOS8 but also need compatibility for IOS7, I have seen the posts referring to using this code:
我想对 IOS8 使用 WKWebView,但也需要对 IOS7 的兼容性,我已经看到了使用此代码的帖子:
if ([WKWebView class]) {
// do new webview stuff
}
else {
// do old webview stuff
}
But not sure what I am doing wrong as the code below gives me a linker error:
但不确定我做错了什么,因为下面的代码给了我一个链接器错误:
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_WKWebView", referenced from:
objc-class-ref in ViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Any help much appreciated, here is my code:
非常感谢任何帮助,这是我的代码:
.h file:
.h 文件:
#import "WebKit/WebKit.h"
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIWebView *contentWebView;
@property (weak, nonatomic) IBOutlet WKWebView *contentWKWebView;
@end
.m file:
.m 文件:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize contentWebView;
@synthesize contentWKWebView;
- (void)viewDidLoad {
[super viewDidLoad];
NSString *filePath = [[NSBundle mainBundle]pathForResource:@"LockBackground" ofType:@"html"];
NSURL * fileURL = [NSURL fileURLWithPath:filePath isDirectory:NO];
NSURLRequest * myNSURLRequest = [[NSURLRequest alloc]initWithURL:fileURL];
if ([WKWebView class]) {
[contentWKWebView loadRequest:myNSURLRequest];
} else {
[contentWebView loadRequest:myNSURLRequest];
}
}
-(UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
回答by Jochen
Go to your Project
, click on General
, scroll down to Linked Frameworks and Libraries
, and add WebKit.framework
as Optional. See here: Xcode 6 + iOS 8 SDK but deploy on iOS 7 (UIWebKit & WKWebKit)
转到您的Project
,单击General
,向下滚动到Linked Frameworks and Libraries
,然后添加WebKit.framework
为可选。请参阅此处:Xcode 6 + iOS 8 SDK 但在 iOS 7 上部署(UIWebKit & WKWebKit)