【问题标题】:Convert URL into hyperlink将 URL 转换为超链接
【发布时间】:2018-01-30 13:25:05
【问题描述】:

我正在开发一个应用程序,在该应用程序中我与一些 url 共享事件图像 分享活动图片时,我正在使用此内容:=

“嘿!我刚刚通过 XXXX App 看到“场地名称”有“活动名称”!我们 应该检查一下。 https://app.com/site/redirectlink?event_id=%@"

现在我可以将这个“https://app.com/site/redirectlink?event_id=%@”链接指向“这里”的超链接吗?

我正在通过“UIActivityViewController”分享此内容。 实际上,此 URL (https://app.com/site/redirectlink?event_id=%@) 稍后用于深度链接,当用户单击此 URL 时,它将被重定向到特定事件,具体取决于 event_id。 而是在我只想在此处使用的整个 URL(作为超链接)上。

【问题讨论】:

  • 你如何准确地“分享”?
  • 如果您通过其他应用分享此内容,则不可以。
  • 请告诉我们您需要做什么
  • @Larme 我已经编辑了我的问题
  • @Niharika 编辑后您可能想查看here 进行深度链接,或者我们可以说通用链接

标签: ios objective-c hyperlink


【解决方案1】:

可能会以这种方式帮助你..

NSString *url=@"https://app.com/site/redirectlink?event_id=%@";
    NSString * title =[NSString stringWithFormat:@"Hey! I just saw \"Venue Name\" is having \"Event Name\" through the XXXX App! We should check it out <html> <body> <a href = '%@'>here</a> </body> </html>",url];
    NSArray* dataToShare = @[title];
    UIActivityViewController* activityViewController =[[UIActivityViewController alloc] initWithActivityItems:dataToShare applicationActivities:nil];
    activityViewController.excludedActivityTypes = @[UIActivityTypeAirDrop];
    [self presentViewController:activityViewController animated:YES completion:^{}];

【讨论】:

  • 嗨。此超链接仅适用于邮件。当我们通过 SMS 共享内容时,它会显示带有 html 标签的 url。有什么解决办法吗?
  • @Niharika 你可以直接发送 url 因为 SMS 不支持 HTML 或 URL,它只接受纯文本。 你可以这样写.... == > NSString *title =[NSString stringWithFormat:@"嘿!我刚刚通过 XXXX App 看到 \"Venue Name\" 有 \"Event Name\"!我们应该在这里查看\n%@",url];
【解决方案2】:

您可能需要 url 的深层链接:projectName://myapp?event_id=12345

添加 info.plist

<key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLName</key>
            <string>com.erimkurt.projectName</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>projectName</string>
            </array>
        </dict>
    </array>

添加 appdelegete.m

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

        NSLog(@"Calling Application Bundle ID: %@", sourceApplication);
        NSLog(@"URL scheme:%@", [url scheme]);
        NSLog(@"URL query: %@", [url query]);

        return YES;
}

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    if (!url) {  return NO; }

    UIAlertView *alertView;
    alertView = [[UIAlertView alloc] initWithTitle:@"Launch by URL" message:@"This app was launched from a URL" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertView show];

    NSString *urlString = [url absoluteString];
    [[NSUserDefaults standardUserDefaults] setObject:urlString forKey:@"url"];
    [[NSUserDefaults standardUserDefaults] synchronize];

    return YES;
}

添加 viewController.m

NSString *url = [[NSUserDefaults standardUserDefaults] objectForKey:@"url"];
    NSLog(@"MYAPPURL: %@",url);

【讨论】:

    猜你喜欢
    • 2022-11-24
    • 1970-01-01
    • 2015-04-22
    • 2018-08-18
    • 1970-01-01
    • 2011-09-30
    • 1970-01-01
    • 2010-12-29
    • 1970-01-01
    相关资源
    最近更新 更多