gpt4 book ai didi

objective-c - UIWebView 和 WKWebView

转载 作者:太空狗 更新时间:2023-10-30 03:38:47 25 4
gpt4 key购买 nike

我想在 IOS8 上使用 WKWebView,但也需要 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

最佳答案

转到您的项目,点击General,向下滚动到Linked Frameworks and Libraries,然后添加WebKit.framework 作为可选。看这里:Xcode 6 + iOS 8 SDK but deploy on iOS 7 (UIWebKit & WKWebKit)

关于objective-c - UIWebView 和 WKWebView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27615041/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com