ios - URL Scheme 在 iOS9 中不起作用

标签 ios objective-c url-scheme

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

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

我在 info.plist 和代码中做了以下事情 1.信息.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.在我使用的应用委托(delegate)中:

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

    }
}

最佳答案

您将 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

关于ios - URL Scheme 在 iOS9 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37562236/

相关文章:

iphone - cs5.5 : Can't install ipa on ios version prior to 4. 3.1 问题

iphone - 指针指向不同的对象: (Unrecognized selector sent to instance)

ios - 在 iOS 的 .c 文件中读取 .txt 文件

为字符串常量妖魔化的 Objective-C#define 指令

ios - iPhone http ://URL redirection

javascript - 浏览器是否应该将使用 javascript 伪协议(protocol) URL 输出更新的窗口视为新位置?

ios - UITextView 的 RxSwift 事件

ios - 如果在数字之前按下计算器应用程序中的运算符(operator)按钮,则应用程序崩溃

ios - UIRefreshControl 和 UITableView 反弹的问题

html - 如何从网站上的链接打开 native iOS 应用程序(日历、笔记...)?