Today Extension UIWebView

My app has a daily quote section and this quote is pulled from a web page on the internet. I'm trying to add a quote using the Today Extension so it could be viewed there, but the extension keeps showing blank.

I added a Today extension file with storyboard, and in the implementation file for the code:

#import "TodayViewController.h"
#import <NotificationCenter/NotificationCenter.h>

@interface TodayViewController () <NCWidgetProviding>

@end

@implementation TodayViewController


-(void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"Today 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

      

However, all I get is a blank line that says "Unable to download" in the Action Center. What am I doing wrong?

+3


source to share


1 answer


This is how I went from UIWebView to WKWebView.

Note. There is no property like UIWebView that you can drag and drop onto your storyboard, you need to do it programmatically.

Make sure you import WebKit / WebKit.h in your header file.



#import <WebKit/WebKit.h>

      

Here's the implementation:

#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

      

0


source







All Articles