【问题标题】:handleOpenURL not called using a custom url schema in iPhone OS未在 iPhone OS 中使用自定义 url 架构调用 handleOpenURL
【发布时间】:2010-06-02 20:13:29
【问题描述】:

我已成功将自己的 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

这有什么问题?

感谢您的回复!

【问题讨论】:

    标签: iphone objective-c xcode url-scheme


    【解决方案1】:

    我试图在another post 中澄清。 Ashley Clark 的回答只是部分正确。在 OS 4.0 下,handleOpenURL 被调用(至少对于文件 URL),您必须实现它来处理应用程序在后台时的打开 url 调用。因此,在这两种方法中打开文件可能会打开两次(如果 applicationDidFinishLaunchingWithOptions 返回 YES,它应该这样做)。见another post

    【讨论】:

      【解决方案2】:

      如果您的应用程序委托已实现“applicationDidFinishLaunchingWithOptions:”,则永远不会调用“handleOpenURL:”方法。查看通过其他方法传入的选项,以确定您的应用是如何启动的以及您应该实现什么行为。

      【讨论】:

      • 谢谢!该 url 也包含在键 UIApplicationLaunchOptionsURLKey 中的 launchOptions
      • 错了!如果您返回 YES,handleOpenURL 将在 applicationDidFinishLaunchingWithOptions 之后不久被调用。请参阅 Apple 的“iOS 应用程序编程指南”中“应用程序间通信”一章中的“处理 URL 请求”部分。
      • @AmitP 是对的。只有当您的实现从 application(_:willFinishLaunchingWithOptions:)application(_:didFinishLaunchingWithOptions:) 方法返回 false 时,application(_:open:options:) 才会被调用。
      【解决方案3】:

      在下面的函数中尝试你的代码

      -(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;
      }
      

      【讨论】:

        猜你喜欢
        • 2016-03-19
        • 1970-01-01
        • 1970-01-01
        • 2013-02-27
        • 1970-01-01
        • 1970-01-01
        • 2020-12-07
        • 1970-01-01
        • 2013-06-10
        相关资源
        最近更新 更多