static async void PlatformOpen(string number) { ValidateOpen(number); var nsUrl = CreateNsUrl(number); await Launcher.PlatformOpenAsync(nsUrl); }
static async Task <bool> PlatformOpenAsync(Uri uri, BrowserLaunchOptions options) { switch (options.LaunchMode) { case BrowserLaunchMode.SystemPreferred: var nativeUrl = new NSUrl(uri.AbsoluteUri); var sfViewController = new SFSafariViewController(nativeUrl, false); var vc = Platform.GetCurrentViewController(); if (options.PreferredToolbarColor != null) { sfViewController.PreferredBarTintColor = options.PreferredToolbarColor.AsUIColor(); } if (options.PreferredControlColor != null) { sfViewController.PreferredControlTintColor = options.PreferredControlColor.AsUIColor(); } if (sfViewController.PopoverPresentationController != null) { sfViewController.PopoverPresentationController.SourceView = vc.View; } if (options.HasFlag(BrowserLaunchFlags.PresentAsFormSheet)) { sfViewController.ModalPresentationStyle = UIModalPresentationStyle.FormSheet; } else if (options.HasFlag(BrowserLaunchFlags.PresentAsPageSheet)) { sfViewController.ModalPresentationStyle = UIModalPresentationStyle.PageSheet; } await vc.PresentViewControllerAsync(sfViewController, true); break; case BrowserLaunchMode.External: return(await Launcher.PlatformOpenAsync(uri)); } return(true); }
internal static async Task PlatformOpenMapsAsync(Placemark placemark, MapLaunchOptions options) { #if __IOS__ var address = new MKPlacemarkAddress { CountryCode = placemark.CountryCode, Country = placemark.CountryName, State = placemark.AdminArea, Street = placemark.Thoroughfare, City = placemark.Locality, Zip = placemark.PostalCode }.Dictionary; #else var address = new NSMutableDictionary { [CNPostalAddressKey.City] = new NSString(placemark.Locality ?? string.Empty), [CNPostalAddressKey.Country] = new NSString(placemark.CountryName ?? string.Empty), [CNPostalAddressKey.State] = new NSString(placemark.AdminArea ?? string.Empty), [CNPostalAddressKey.Street] = new NSString(placemark.Thoroughfare ?? string.Empty), [CNPostalAddressKey.PostalCode] = new NSString(placemark.PostalCode ?? string.Empty), [CNPostalAddressKey.IsoCountryCode] = new NSString(placemark.CountryCode ?? string.Empty) }; #endif var resolvedPlacemarks = await GetPlacemarksAsync(address); if (resolvedPlacemarks?.Length > 0) { await OpenPlacemark(new MKPlacemark(resolvedPlacemarks[0].Location.Coordinate, address), options); } else { #if __IOS__ || __MACOS__ // https://developer.apple.com/library/archive/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html var uri = $"http://maps.apple.com/?q={placemark.GetEscapedAddress()}"; var nsurl = NSUrl.FromString(uri); await Launcher.PlatformOpenAsync(nsurl); #else await OpenPlacemark(new MKPlacemark(default, address), options);
static async Task ComposeWithUrl(EmailMessage message) { var url = GetMailToUri(message); var nsurl = NSUrl.FromString(url); await Launcher.PlatformOpenAsync(nsurl); }