简体   繁体   中英

URL Scheme not working from native iOS app

I have a custom defined URL scheme and a TARGET app that registered this scheme to be recognized.

When I launch a WEB app in mobile Safari and I push a button in the WEB App, there is an URL link provided by the button, and a dedicated TARGET application is launched - which is the desired behaviour.

However if I launch a native SOURCE app, and implement an action on a UIButton, and there I call the appdelegate to openURL and pass the same url that is used from the web app, TARGET app is not launched. The [UIApplication canOpenURL] check even returns NO, which is strange, since TARGET App DID register that custom URL Scheme correctly, otherwise it would not work from the web app.

Any help?

PS:SOURCE and TARGET are just convenient names for SO.

UPDATE:

- (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
  }
}

Ok ,so the problem was that he url had characters that were not escaped using UTF8 encoding.

Solution:

    NSString *urlString = @"sorry..can't show this :(";
NSString *escapedUrlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSURL *url =[ NSURL URLWithString:escapedUrlString];

[[UIApplication sharedApplication] openURL:url];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM