gpt4 book ai didi

iphone - PhoneGap/iOS,从 .shouldStartLoadWithRequest() 打开 ChildBrowser?

转载 作者:可可西里 更新时间:2023-11-01 17:10:58 26 4
gpt4 key购买 nike

我正在 PhoneGap 中打包一个移动网站(通过网络),我想拦截指向 PDF 的链接并使用 ChildBrowser 打开它们插入。是否 1:可以从 native 代码触发 ChildBrowser(我已经确定要拦截哪些链接)和 2:是 AppDelegate.m, .shouldStartLoadWithRequest() 做对的地方?在那种情况下:3:如何从 native 代码正确调用 ChildBrowser

我尝试过这种公认的幼稚方法:

return [self exec:@"ChildBrowserCommand.showWebPage",
[url absoluteString]];

但它只会导致错误,如 ...'NSInvalidArgumentException', reason: '-[AppDelegate exec:]: unrecognized selector sent to instance

(PS:我知道这种方法不是理想的做法,但这个项目的价格仅为 2 天的工作)

最佳答案

如果您在插件文件夹中添加(Child Browser)插件类,那么您必须使用 appDelegate.m 文件,#import "ChildBrowserViewController.h"
例如,您的 html 文件具有以下 html/javascript 代码,如下所示
window.location="http://xyz.com/magazines/magazines101.pdf";
要在子浏览器中执行此 url,您需要修改包含 pdf 扩展文件的请求 url 的原生 shouldStartLoadWithRequest: 方法。


/**
* Start Loading Request
* This is where most of the magic happens... We take the request(s) and process the response.
* From here we can re direct links and other protocalls to different internal methods.
*/
- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
//return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ];
NSURL *url = [request URL];
if([request.URL.absoluteString isEqualToString:@"about:blank"])
return [ super webView:theWebView shouldStartLoadWithRequest:request
navigationType:navigationType ];
if ([[url scheme] isEqualToString:@"gap"]) {
return [ super webView:theWebView shouldStartLoadWithRequest:request
navigationType:navigationType ];
} else {
NSString *urlFormat = [[[url path] componentsSeparatedByString:@"."] lastObject];
if ([urlFormat compare:@"pdf"] == NSOrderedSame) {
[theWebView sizeToFit];
//This code will open pdf extension files (url's) in Child Browser
ChildBrowserViewController* childBrowser = [ [ ChildBrowserViewController alloc ] initWithScale:FALSE ];
childBrowser.modalPresentationStyle = UIModalPresentationFormSheet;
childBrowser.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[super.viewController presentModalViewController:childBrowser animated:YES ];
NSString* urlString=[NSString stringWithFormat:@"%@",[url absoluteString]];
[childBrowser loadURL:urlString];
[childBrowser release];
return NO;
}
else
return [ super webView:theWebView shouldStartLoadWithRequest:request
navigationType:navigationType ];
}
}

谢谢,
马约尔

关于iphone - PhoneGap/iOS,从 .shouldStartLoadWithRequest() 打开 ChildBrowser?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7952626/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com