【问题标题】:Applinks iOS URL NavigationApplinks iOS URL 导航
【发布时间】:2014-05-12 03:07:21
【问题描述】:

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

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

提前致谢!

【问题讨论】:

    标签: ios facebook bolts-framework applinks


    【解决方案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/

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多