问题描述
我正在尝试测试MyApp(CanOpen)中是否存在某个应用程序.如果是这样,我希望打开该应用程序,否则我有一个https地址来打开Web视图.我在开罐测试中得到了错误的回报.我相信我的代码是正确的,但是我不确定在info.plist上.我有一个MyApp的url类型(在info.plist中).我有另一个应用程序(运行状况)的LSApplicationQueriesSchemes条目,但是不确定该引用如何绑定到实际应用程序....非常感谢您的帮助:
I am trying to test if an app is present from MyApp (CanOpen). If so, I wish to open the app, otherwise I have an https address to open a webview. I am getting the false return on the can open test. I believe my code is sound but I am not sure on the info.plist. I have a url type (in info.plist) for MyApp. I have the LSApplicationQueriesSchemes entry for the other app (health), but unsure of how that reference is tied back to the actual app.... Any help is greatly appreciated:
是以下界面:
public interface IAppHandler
{
Task<bool> LaunchApp(string uri);
}
在模型视图"中,我对实际的处理程序进行去势性调用:
string appid = @"health://";
var result = await DependencyService.Get<IAppHandler>().LaunchApp(appid);
if (!result)
{
Show_WebView(url);
}
在特定于平台的AppHandler中:
public Task<bool> LaunchApp(string uri)
{
try
{
var canOpen = UIApplication.SharedApplication.CanOpenUrl(new NSUrl(uri));
if (!canOpen)
return Task.FromResult(false);
return Task.FromResult(UIApplication.SharedApplication.OpenUrl(new NSUrl(uri)));
}
catch (Exception ex)
{
return Task.FromResult(false);
}
}
在info.plist中:
<key>CFBundleURLSchemes</key>
<array>
<string>MyApp</string>
<string>com.apple.Health</string>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>health</string>
</array>
推荐答案
您需要将目标应用的URL方案添加到info.plist文件中,以便使用 canOpen
功能.IE
You need to add the URL Scheme of the target app into the info.plist file in order to use canOpen
functionality. i.e
这篇关于从Xamarin Forms App启动另一个IOS App的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!