如何使用URL方案从我的Xamarin iOS应用程序中打开另一个应用程序

时间:2016-05-18 07:04:17

标签: xamarin xamarin.ios xamarin.forms

我想要的是,在iOS中从我的Xamarin Forms应用程序中打开另一个应用程序。我在iOS中阅读了有关URL方案的内容,但是如何在Xamarin Applications中实现它。我使用依赖服务来调用本机函数。我在Android中完成了这项工作并且运行良好。

我找到了一个链接 https://riccardo-moschetti.org/2014/10/03/opening-a-mobile-app-from-a-link-the-xamarin-way-url-schemas/。但它使用Xamarin Studio,我使用的是Visual Studio,VS2015没有此选项。

任何人都有更好的解决方案吗?

1 个答案:

答案 0 :(得分:1)

我已经通过在我要打开的应用程序的info.plist中添加以下键来解决它。

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLName</key>
        <string>com.example.ios</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>testscheme</string>
        </array>
    </dict>
</array>

然后使用以下代码打开应用程序

if(!UIApplication.SharedApplication.OpenUrl(NSUrl.FromString("testscheme://com.example.ios")))
{
//Use the code below to go to itunes if application not found.
UIApplication.SharedApplication.OpenUrl(NSUrl.FromString("itms://itunes.apple.com/in/app/appname/appid")); 
}