我的应用程序有一个包含每日报价的部分,该报价是从互联网上的网页中提取的。我一直在尝试使用 Today Extension 添加报价,以便可以在那里查看,但扩展始终显示为空白。
我在 Storyboard中添加了 Today Extension 文件,并且在我拥有的代码的实现文件中:
#import "TodayViewController.h"
#import <NotificationCenter/NotificationCenter.h>
@interface TodayViewController () <NCWidgetProviding>
@end
@implementation TodayViewController
-(void)viewDidLoad {
[super viewDidLoad];
self.title = @"Today's Scripture";
self.preferredContentSize = CGSizeMake(320, 50);
[reader loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.316apps.com/testingdailyreader.html"]cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60.0]];
// timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:@selector(tick) userInfo:nil repeats:YES];
}
@end
但是,我得到的只是通知中心中显示“无法加载”的空白行。我做错了什么?
最佳答案
下面是我如何从 UIWebView 过渡到 WKWebView。
注意:没有像 UIWebView 这样的属性可以拖到 Storyboard上,您必须以编程方式进行。
确保将 WebKit/WebKit.h 导入头文件。
#import <WebKit/WebKit.h>
这里,实现:
#import "ViewController.h"
@interface ViewController ()
@property(strong,nonatomic) WKWebView *webView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.productURL = @"http://www.URL YOU WANT TO VIEW GOES HERE";
NSURL *url = [NSURL URLWithString:self.productURL];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
//[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.316apps.com/testingdailyreader.html"]cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60.0]];
_webView = [[WKWebView alloc] initWithFrame:self.view.frame];
[_webView loadRequest:request];
_webView.frame = CGRectMake(self.view.frame.origin.x,self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
[self.view addSubview:_webView];
}
@end
关于ios - 今天扩展 UIWebView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25999061/