我有一个自定义的 URL 方案和一个 TARGET 应用程序,该应用程序注册了该方案以供识别。
当我在移动版 Safari 中启动 WEB 应用程序并按下 WEB 应用程序中的按钮时,按钮会提供一个 URL 链接,并且会启动一个专用的 TARGET 应用程序 - 这是所需的行为。
但是,如果我启动 native SOURCE 应用程序,并在 UIButton 上实现操作,然后我将 appdelegate 调用到 openURL 并传递与网络应用程序相同的 url,TARGET 应用程序不会启动。 [UIApplication canOpenURL] 检查甚至返回 NO,这很奇怪,因为 TARGET App DID 正确注册了该自定义 URL Scheme,否则它将无法在 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
}
}
最佳答案
好的,所以问题是他的 url 包含未使用 UTF8 编码转义的字符。
解决方法:
NSString *urlString = @"sorry..can't show this :(";
NSString *escapedUrlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url =[ NSURL URLWithString:escapedUrlString];
[[UIApplication sharedApplication] openURL:url];
关于ios - URL Scheme 不适用于 native iOS 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28240087/