我想将 WKWebView 用于 IOS8,但也需要与 IOS7 兼容,我已经看到有关使用此代码的帖子:
if ([WKWebView class]) {
// do new webview stuff
}
else {
// do old webview stuff
}
但不确定我做错了什么,因为下面的代码给了我一个链接器错误:
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)
非常感谢任何帮助,这是我的代码:
.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 文件:
#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