【问题标题】:URL Scheme not working in iOS9URL方案在iOS9中不起作用
【发布时间】:2016-06-01 07:34:09
【问题描述】:

我正在开发一个应用程序,其中将用户确认邮件发送到用户电子邮件。 我可以接收这种格式的邮件“http://www.sample.com//Register.aspx?xxx(withparameters)”。 现在点击这封邮件,我必须在 iOS9 中启动注册页面。

注意:如果我在 safari 应用程序中键入 Register.aspx://,但不是来自电子邮件 URL。

我在 info.plist 和代码中做了以下事情 1.info.plist

<key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>Register.aspx</string>
            </array>
        </dict>
    </array> 
<key>LSApplicationQueriesSchemes</key>
    <array>
        <string>Register.aspx</string>
    </array>

2.在我使用的应用代理中:

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {

    BOOL canBeOpened = [[UIApplication sharedApplication]
                        canOpenURL:[NSURL URLWithString:@"Register.aspx://"]];

    if (canBeOpened) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Test Message"
                                                        message:@"This is a url scheme"
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        [alert show];

    }
    else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Test Message"
                                                        message:@"This is not a url scheme"
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        [alert show];

    }
}

【问题讨论】:

    标签: ios objective-c url-scheme


    【解决方案1】:

    您将 URL 的错误部分注册为方案。您提供的示例具有http 的标准 URL 方案。

    第一个冒号之前的 URL 位是方案(通常为 httphttps)。要使用自定义方案,您需要为 URL 创建一个新方案并在您的电子邮件中输出该 URL,例如:

    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>mycoolapp</string>
            </array>
        </dict>
    </array> 
    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>mycoolapp</string>
    </array>
    

    需要带有如下 URL 的电子邮件:

    mycoolapp://www.sample.com/Register.aspx
    

    【讨论】:

      【解决方案2】:

      iOS 9 对 URL 方案的处理做了一个小改动。您必须使用 Info.plist 中的 LSApplicationQueriesSchemes 键将您的应用调用的 url 列入白名单。

      请检查此链接 :http://awkwardhare.com/post/121196006730/quick-take-on-ios-9-url-scheme-changes

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-02-18
        • 1970-01-01
        • 1970-01-01
        • 2015-09-30
        • 2014-04-22
        • 1970-01-01
        • 2012-01-14
        相关资源
        最近更新 更多