首页 文章

URL方案无法在本机iOS应用程序中运行

提问于
浏览
0

我有一个自定义的URL方案和一个TARGET应用程序,注册该方案以进行识别 .

当我在移动版Safari中启动WEB应用程序并按下WEB App中的按钮时,按钮提供了一个URL链接,并启动了一个专用的TARGET应用程序 - 这是所需的行为 .

但是,如果我启动本机SOURCE应用程序,并在UIButton上实现操作,并在那里我将appdelegate称为openURL并传递从Web应用程序使用的相同URL,则TARGET应用程序不会启动 . [UIApplication canOpenURL]检查甚至返回NO,这很奇怪,因为TARGET App DID正确注册了自定义URL方案,否则它将无法在Web应用程序中运行 .

有帮助吗?

PS:SOURCE和TARGET只是SO的便捷名称 .

更新:

- (IBAction)handleAction:(id)sender
{
    NSString *urlString = @"nda://nda.undernda/actionundernda?someparamters..";

BOOL isURLSchemeRegistered = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:urlString]];

if (isURLSchemeRegistered == YES)
    {
        [[UIApplication sharedApplication] openURL:[NSURL     URLWithString:urlString]];
    }
else
  {
    //go to appstore
  }
}

1 回答

  • 1

    好吧,问题是他的网址没有使用UTF8编码转义的字符 .

    解:

    NSString *urlString = @"sorry..can't show this :(";
    NSString *escapedUrlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    NSURL *url =[ NSURL URLWithString:escapedUrlString];
    
    [[UIApplication sharedApplication] openURL:url];
    

相关问题