gpt4 book ai didi

带有 Phonegap 1.6.0 的 iOS handleOpenURL

转载 作者:行者123 更新时间:2023-11-29 13:37:26 25 4
gpt4 key购买 nike

Cordova :1.6.0

iOS: 5.1

X代码:4.3.1

我正在尝试使用一个非常基本的示例程序来访问 Phonegap 1.6.0 中的 handleOpenURL。每次发出 http/https 请求时,我都想分析一个 url。我现在所做的就是添加一条日志消息以查看 url 的主机。

- (BOOL) application:(UIApplication*)application handleOpenURL: 
(NSURL*)url
{
NSLog(@"Hi");
NSLog(@"Host: %@", [url host]);

if (!url) {
return NO;
}

...
}

但是,日志消息不会向控制台写入任何内容。

我确实注意到了评论:

// only valid if Example-Info.plist specifies a protocol to handle 

也许我的 Example-Info.plist 文件有误?我已经将 CFBundleURLTypes 添加到其中,假设这就是“指定要处理的协议(protocol)”的含义。我必须在某处添加其他内容吗?下面是我的 Example-Info.plist 文件的示例部分。模拟器是否可能无法识别我的 .plist 修改?

... 
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>http</string>
<string>https</string>
</array>
</dict>
</array>

由于 handleOpenURL 已被弃用,因此我也有所了解。

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication (NSString *)sourceApplication annotation:(id)annotation
{
NSLog(@"Hi");
...
}

当我在我的应用程序中打开 URL 时,两者都没有被调用。我已经尝试了堆栈溢出中的所有解决方案,但没有这样的运气。如果有任何帮助,我正在使用 jQuery Mobile 1.1.0 进行页面转换。

最佳答案

那不是那些方法的目的。它们将处理用于打开您的应用的 URL,而不是您在 UIWebView 中打开的任何 URL。

您应该查看 UIWebView 的委托(delegate)方法

特别是

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
导航类型:(UIWebViewNavigationType)导航类型

关于带有 Phonegap 1.6.0 的 iOS handleOpenURL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10192448/

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