3

我的应用程序有一个包含每日报价的部分,该报价是从互联网上的网页中提取的。我一直在尝试使用 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

但是,我得到的只是通知中心中显示“无法加载”的空白行。我究竟做错了什么?

4

1 回答 1

0

这是我从 UIWebView 转换到 WKWebView 的方式。

注意:没有像 UIWebView 这样的属性可以拖到情节提要上,您必须以编程方式进行。

确保将 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
于 2016-04-26T07:31:47.340 回答