![](/img/trans.png)
[英]Redirecting from BankID app with custom URL scheme in iOS (Flutter) not working
[英]URL Scheme not working from native iOS app
我有一個自定義的URL方案和一個TARGET應用程序,該應用程序注冊了該方案才能識別。
當我在移動Safari中啟動WEB應用程序並按WEB應用程序中的按鈕時,該按鈕提供了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
}
}
好的,所以問題在於他的網址包含使用UTF8編碼無法轉義的字符。
解:
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.