File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed
DeviceTests/DeviceTests.Shared
Xamarin.Essentials/Launcher Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,17 @@ public async Task CanOpenUri(string uri)
6868 Assert . True ( await Launcher . CanOpenAsync ( new Uri ( uri ) ) ) ;
6969 }
7070
71+ #if __IOS__
72+ [ Theory ]
73+ [ InlineData ( "https://maps.apple.com/maps?q=Ole Vigs Gate 8B" , "https://maps.apple.com/maps?q=Ole%20Vigs%20Gate%208B" ) ]
74+ [ InlineData ( "https://maps.apple.com" , "https://maps.apple.com" ) ]
75+ public void GetNativeUrl ( string uri , string expected )
76+ {
77+ var url = Launcher . GetNativeUrl ( new Uri ( uri ) ) ;
78+ Assert . Equal ( expected , url . AbsoluteString ) ;
79+ }
80+ #endif
81+
7182 [ Theory ]
7283 [ InlineData ( "Not Valid Uri" ) ]
7384 public async Task InvalidUri ( string uri )
Original file line number Diff line number Diff line change 11using System ;
2+ using System . Diagnostics ;
23using System . Threading . Tasks ;
34using Foundation ;
45using UIKit ;
@@ -8,9 +9,22 @@ namespace Xamarin.Essentials
89 public static partial class Launcher
910 {
1011 static Task < bool > PlatformCanOpenAsync ( Uri uri ) =>
11- Task . FromResult ( UIApplication . SharedApplication . CanOpenUrl ( new NSUrl ( uri . OriginalString ) ) ) ;
12+ Task . FromResult ( UIApplication . SharedApplication . CanOpenUrl ( GetNativeUrl ( uri ) ) ) ;
1213
1314 static Task PlatformOpenAsync ( Uri uri ) =>
14- UIApplication . SharedApplication . OpenUrlAsync ( new NSUrl ( uri . OriginalString ) , new UIApplicationOpenUrlOptions ( ) ) ;
15+ UIApplication . SharedApplication . OpenUrlAsync ( GetNativeUrl ( uri ) , new UIApplicationOpenUrlOptions ( ) ) ;
16+
17+ internal static NSUrl GetNativeUrl ( Uri uri )
18+ {
19+ try
20+ {
21+ return new NSUrl ( uri . OriginalString ) ;
22+ }
23+ catch ( Exception ex )
24+ {
25+ Debug . WriteLine ( "Unable to create Url from Original string, try absolute Uri: " + ex . Message ) ;
26+ return new NSUrl ( uri . AbsoluteUri ) ;
27+ }
28+ }
1529 }
1630}
You can’t perform that action at this time.
0 commit comments