在 iPhone OS 中未使用自定义 url 模式调用 handleOpenURL

发布于 2024-09-03 13:32:40 字数 759 浏览 5 评论 0原文

我已成功将自己的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

始终不够爱げ你 2024-09-10 13:32:40

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.

狂之美人 2024-09-10 13:32:40

如果您的应用程序委托已实现“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.

笑梦风尘 2024-09-10 13:32:40

尝试将您的代码放入以下函数中

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    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;
}

Try your code into below function

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文