IOS从一个APP跳到另一个APP

时间:2023-03-08 21:36:24

以下为跳转到大众点评APP代码如下:

NSString *requestUrlString = @"dianping://shopinfo?id=1000";        
NSURL *requestUrl = [NSURL URLWithString: requestUrlString];
if([[UIApplication sharedApplication] canOpenURL:requestUrl]) {
[[UIApplication sharedApplication] openURL:requestUrl];
} else {
//没有安装应用,默认打开HTML5站
NSString *keywords = [@"吃饭饭" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
requestUrl = [NSURL URLWithString:[NSString stringWithFormat:@"http://m.dianping.com/shoplist/219/search?from=m_search&keyword=%@",keywords]];
[[UIApplication sharedApplication] openURL:requestUrl];
}

跳转的过程中可能会出现ERROR:

error: "This app is not allowed to query for scheme dianping"

解决方法是在info.plist文件内添加以下配置项,将其列为白名单才可以正常检查是否已经安装此程序。

<key>LSApplicationQueriesSchemes</key>

<array>

<string>weixin</string>

<string>wechat</string>

<string>dianping</string>

</array>