简体   繁体   中英

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. It working properly in android by the raise of an exception, but there isn't any exception raise for iOS. Is there any other solution to open default browser if fb app is not installed in device.

Unfortunately it will never raise exception with 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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