从Xamarin Forms应用程序启动另一个iOS应用程序

4
我正在尝试从MyApp(CanOpen)测试应用程序是否存在。如果是,则希望打开该应用程序,否则我有一个https地址可以打开Web视图。在can open测试中,我得到了false返回。我相信我的代码很好,但我不确定info.plist。我在info.plist中有一个url类型(对于MyApp)。我为其他应用程序(health)设置了LSApplicationQueriesSchemes条目,但不确定该引用如何与实际应用程序联系起来...非常感谢您的帮助:
在MyApp PCL中,以下接口是什么:
   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>

您需要注册您想要打开的应用程序的URLScheme。 - Shabir jan
Shabir,使用bundle id吗?谢谢。 - Nick
我不知道如何将LSApplicationQueriesSchemes与URL类型关联起来。 - Nick
没有捆绑标识符是不同的,您需要注册另一个要打开的应用程序的自定义URL方案。 - Shabir jan
请检查我的答案 - Shabir jan
1个回答

4

为了使用canOpen功能,您需要将目标应用程序的URL Scheme添加到info.plist文件中。例如:

enter image description here

你在 URI 中传递了什么值? - Shabir jan
1
<key>LSApplicationQueriesSchemes</key> <array> <string>accom.ibm.cognos-mobile</string> <string>roomreservation</string> </array> - Shabir jan
不需要传递URL方案,但如果“health”是该应用程序的URL方案,则可以。 - Shabir jan
我如何确定其他应用程序的URL方案。它不是由我的团队开发的。 - Nick
如果您同时在模拟器中安装了该应用程序,它将可以正常工作。 - Shabir jan
显示剩余6条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接