今天扩展UIWebView

3
我的应用程序中有一个每日引用节,这个引用是从互联网上的一个网页中获得的。我一直在尝试使用Today扩展添加引用,以便可以在那里查看,但扩展始终为空白。
我已经添加了带有故事板的Today扩展文件,在代码的实现文件中,我有以下内容:
#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

然而,我得到的只是一个空行,通知中心上显示“无法加载”。我做错了什么?


你找到解决方案了吗?我现在也遇到了同样的问题。 - cptdanko
1个回答

0

这是我从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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接