简体   繁体   English

如果未在移动Xamarin.Forms中安装应用程序,则如何打开默认浏览器(IOS问题)

[英]How to open default browser if app is not installed in mobile Xamarin.Forms (IOS issue)

try {         
     Device.OpenUri (new Uri("fb://page/page_id"));     
    } catch(Exception e){         
     System.Diagnostics.Debug.WriteLine (e.Message);         
     Device.OpenUri (new Uri("https://www.facebook.com/pages/...."));     
}

If the application is not installed or the scheme is not valid, it should go in the catch and open the Facebook page in the browser. 如果未安装该应用程序或该方案无效,则应将其插入捕获并在浏览器中打开Facebook页面。 It working properly in android by the raise of an exception, but there isn't any exception raise for iOS. 通过引发异常,它可以在android中正常工作,但对于iOS没有任何异常引发。 Is there any other solution to open default browser if fb app is not installed in device. 如果设备中未安装fb应用,是否还有其他解决方案可打开默认浏览器。

Unfortunately it will never raise exception with iOS. 不幸的是,它将永远不会引发iOS异常。

I suggest you use DependencyService to implement opening Facebook in iOS , so that you can detect if the application is not installed or the scheme is not valid. 建议您使用DependencyService在iOS中实现打开Facebook的功能,以便您可以检测是否未安装该应用程序或该方案无效。

 bool isSuccess = UIApplication.SharedApplication.OpenUrl(new NSUrl("fb://page/page_id"));
 if (isSuccess == false) {
     UIApplication.SharedApplication.OpenUrl(new NSUrl("https://www.facebook.com/pages/...."));
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM