在 iPhone OS 中未使用自定义 url 模式调用 handleOpenURL
我已成功将自己的 url 方案添加到我的应用程序中。该应用程序使用这些方案正确启动。
现在我想处理传入的数据,但未调用委托。它是一个通用应用程序,我已向两个 AppDelegate 添加了以下功能:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
if (!url) { return NO; }
NSString *URLString = [url absoluteString];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:NSLocalizedString(@"test message", nil)
message:URLString
delegate:self
cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
[alert release];
return YES;
}
我正在使用如下模式进行测试:myapp://appalarm.com …并且期望 URLString 中是 appalarm.com 有
什么问题吗?
感谢您的回复!
I have successfuly added my own url schemes to my App. The App correctly launches using the schemes.
Now I want to handle the incoming data but the delegate is not called. It is an universal app and I have added the following function to both AppDelegates:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
if (!url) { return NO; }
NSString *URLString = [url absoluteString];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:NSLocalizedString(@"test message", nil)
message:URLString
delegate:self
cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
[alert release];
return YES;
}
I am testing with a schema like: myapp://appalarm.com
…and would expect to be appalarm.com in the URLString
What is wrong with it?
Thanks for your responses!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我试图在另一篇文章中进行澄清< /a>.阿什利·克拉克 (Ashley Clark) 的回答仅部分正确。在 OS 4.0 下,handleOpenURL 被调用(至少对于文件 URL),并且您必须实现它来处理应用程序在后台时的打开 url 调用。因此,用两种方法打开文件可能会打开它两次(如果 applicationDidFinishLaunchingWithOptions 返回 YES,它应该返回 YES)。请参阅另一篇文章。
I tried to clarify in another post. The answer of Ashley Clark is only partly correct. Under OS 4.0 the handleOpenURL gets called (at least for file URLs) and you have to implement it to handle open url calls for when the app is in background. Thus, opening the file in both methods may open it twice (if applicationDidFinishLaunchingWithOptions returned YES, which it should). See another post.
如果您的应用程序委托已实现“applicationDidFinishLaunchingWithOptions:”,则永远不会调用“handleOpenURL:”方法。查看通过其他方法传入的选项,以确定您的应用程序是如何启动的以及您应该实现什么行为。
If your application delegate has implemented 'applicationDidFinishLaunchingWithOptions:' then the 'handleOpenURL:' method will never be called. Look at the options passed in through the other method to determine how your app was launched and what behavior you should implement.
尝试将您的代码放入以下函数中
Try your code into below function