【发布时间】:2017-10-12 03:50:51
【问题描述】:
我正在尝试测试是否存在来自 MyApp (CanOpen) 的应用。如果是这样,我希望打开应用程序,否则我有一个 https 地址来打开 web 视图。我在开罐测试中得到了错误的回报。我相信我的代码是正确的,但我不确定 info.plist 是否存在。我有一个用于 MyApp 的 url 类型(在 info.plist 中)。我有另一个应用程序(健康)的 LSApplicationQueriesSchemes 条目,但不确定该引用如何与实际应用程序联系起来......非常感谢任何帮助:
MyApp PCL 中的界面如下:
public interface IAppHandler
{
Task<bool> LaunchApp(string uri);
}
在我对实际处理程序进行 deoendency 调用的模型视图中:
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>
【问题讨论】:
-
你需要注册你要打开的应用的URLScheme。
-
Shabir,使用捆绑 ID?谢谢
-
我错过了如何将 LSApplicationQueriesSchemes 绑定到 URL 类型。
-
没有bundle id不同,你需要注册另一个你要打开的应用的自定义URL方案
-
检查我的答案