Applinks iOS URL导航

时间:2014-05-12 03:07:22

标签: ios facebook bolts-framework applinks

我正在尝试创建一个使用applinks的应用程序。也就是说,我想从我自己的导航到其他iOS应用程序。我已经安装了Bolt框架并正在使用     [BFAppLinkNavigation navigateToURLInBackground:url]; 导航到网页。我似乎无法直接链接到我手机上安装的应用程序。我相信这是因为我不知道传入的当前URL是什么。

如果有人可以建议在哪里找到能够引导我使用AppLinks的应用程序的URL,我们将不胜感激。

提前致谢!

2 个答案:

答案 0 :(得分:1)

看起来像这样:

NSString *html = [self htmlWithMetaTags:@[
                                          @{
                                              @"al:ios": [NSNull null],
                                              @"al:ios:url": @"bolts://",
                                              @"al:ios:app_name": @"Bolts",
                                              @"al:ios:app_store_id": @"12345"
                                              }
                                          ]];
NSURL *url = [self dataUrlForHtml:html];

[BFAppLinkNavigation navigateToURLInBackground:url];

下面仍然需要三个自定义功能:

- (NSString *)htmlWithMetaTags:(NSArray *)tags {
    NSMutableString *html = [NSMutableString stringWithString:@"<html><head>"];

    for (NSDictionary *dict in tags) {
        for (NSString *key in dict) {
            if (dict[key] == [NSNull null]) {
                [html appendFormat:@"<meta property=\"%@\">", key];
            } else {
                [html appendFormat:@"<meta property=\"%@\" content=\"%@\">", key, dict[key]];
            }
        }
    }

    [html appendString:@"</head><body>Hello, world!</body></html>"];
    NSLog(@"html:%@",html);
    return html;
}

- (NSURL *)dataUrlForHtml:(NSString *)html {
    NSString *encoded = [self stringByEscapingQueryString:html];
    NSString *urlString = [NSString stringWithFormat:@"data:text/html,%@", encoded];
    return [NSURL URLWithString:urlString];
}

- (NSString *)stringByEscapingQueryString:(NSString *)string {
    return (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL,(CFStringRef)string,NULL,(CFStringRef)@":/?#[]@!$&'()*+,;=",kCFStringEncodingUTF8));
}

您可以在BoltsTests中找到以上所有内容。 http://applinks.org/documentation/

答案 1 :(得分:0)

这可以通过在您的应用程序中实现URL Scheme来实现,这也要求您要导航的其他应用程序应该具有该实现,您可以在下面的链接中看到相同的教程。

链接:http://code.tutsplus.com/tutorials/ios-sdk-working-with-url-schemes--mobile-6629