[英]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. 我有一个自定义的URL方案和一个TARGET应用程序,该应用程序注册了该方案才能识别。
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. 当我在移动Safari中启动WEB应用程序并按WEB应用程序中的按钮时,该按钮提供了URL链接,并且启动了专用的TARGET应用程序-这是您所期望的行为。
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. 但是,如果启动本机SOURCE应用程序并在UIButton上执行操作,然后在其中调用appdelegate到openURL并传递与Web应用程序相同的URL,则不会启动TARGET应用程序。 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.
[UIApplication canOpenURL]检查甚至返回NO,这很奇怪,因为TARGET App DID已正确注册了该自定义URL方案,否则将无法从Web应用程序运行。
Any help? 有什么帮助吗?
PS:SOURCE and TARGET are just convenient names for SO. PS:SOURCE和TARGET只是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. 好的,所以问题在于他的网址包含使用UTF8编码无法转义的字符。
Solution: 解:
NSString *urlString = @"sorry..can't show this :(";
NSString *escapedUrlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url =[ NSURL URLWithString:escapedUrlString];
[[UIApplication sharedApplication] openURL:url];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.