如何在我的viewcontroller中加载cordova webview?

时间:2017-09-27 15:03:40

标签: ios objective-c iphone cordova webview

我的cordova库很旧,因为iOS11而不得不更新它。我已将其更新到最新版本4.4.0。 CDVViewController现在完全不同,它使webviewEngine能够获取UIWebview或WKWebview。如何在我的原生应用程序中启动Cordova webview。以前,我加载它 -

 - (void) viewDidLoad {
        [super viewDidLoad];

        CDVViewController *viewController = [CDVViewController new];
        viewController.wwwFolderName = @"www";
        viewController.startPage = @"blank.html";
        viewController.view.frame = self.webView.frame;
        [self.webView removeFromSuperview];
        self.webView = nil;
        [self.view addSubview:viewController.view];
        self.webView = viewController.webView;
        viewController.webView.delegate = self;
        self.cordovaWebViewController = viewController;
        self.webView.scalesPageToFit = YES;

        if (self.url)
          [self.webView loadRequest: [NSURLRequest requestWithURL: self.url]];
     }

并使用webview委托作为

#pragma mark Webview Delegate
- (void) webViewDidStartLoad: (UIWebView *) webViewLocal {
        [self.spinner startAnimating];
        [self.cordovaWebViewController webViewDidStartLoad:webViewLocal];
    }

- (void) webViewDidFinishLoad: (UIWebView *) webViewLocal {
     [self.spinner stopAnimating];
     [self.cordovaWebViewController webViewDidFinishLoad:webViewLocal];
    }

- (void) webView: (UIWebView *) webView didFailLoadWithError: (NSError *) error {
    [self.spinner stopAnimating];
  }

      - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    if (navigationType == UIWebViewNavigationTypeLinkClicked) {
        if ([request.URL.absoluteString hasSuffix: @"link_restart_movie_file"]) {
            [self loadItem];
            return NO;
        }
        [self.webView loadRequest: request];
        return NO;
    }
     [self.cordovaWebViewController webView:self.webView      shouldStartLoadWithRequest:request navigationType:navigationType];
     return YES;
    }

如何使用WebviewEngine加载我的viewcontroller?是否有任何教程,解释了CDVViewController的用法?请帮忙!谢谢!

0 个答案:

没有答案