Skip to content

Commit 347789e

Browse files
committed
新增NativeUI.OpenURL
1 parent c27f5d8 commit 347789e

3 files changed

Lines changed: 29 additions & 4 deletions

File tree

Plugins/CS/NativeUI.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace iOSNativePlugin
1010
public static class NativeUI
1111
{
1212
[DllImport("__Internal")] static extern void NativeUI_GetUnityViewSize(ref double x, ref double y);
13+
[DllImport("__Internal")] static extern void NativeUI_OpenUrl(string url);
1314
[DllImport("__Internal")] static extern void NativeUI_SafariViewFromUrl(string url, CompletionCallback onCompletionCallback);
1415
[DllImport("__Internal")] static extern void NativeUI_SafariPageSheetFromUrl(string url, CompletionCallback onCompletionCallback);
1516
[DllImport("__Internal")] static extern void NativeUI_RegisterStatusBarOrientationChangeCallback(OrientationChangeCallback callback);
@@ -50,9 +51,14 @@ public static bool HideHomeIndicator
5051
#endif
5152
}
5253
}
53-
54-
55-
54+
55+
56+
public static void OpenURL(string url)
57+
{
58+
NativeUI_OpenUrl(url);
59+
}
60+
61+
5662
/// <summary>
5763
/// 调用游戏内Safari窗口打开url
5864
/// </summary>
@@ -75,7 +81,7 @@ public static void SafariPageSheetFromUrl(string url, Action onCompletionCallbac
7581
_onSafariViewComplete = onCompletionCallback;
7682
}
7783

78-
private static Action _onSafariViewComplete;
84+
static Action _onSafariViewComplete;
7985

8086
[MonoPInvokeCallback(typeof(CompletionCallback))]
8187
static void OnSafariViewCompletionCallback()

Plugins/Native/Headers/NativeUI.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//SFSafariViewControllerDelegate 实现SafariView回调协议
55
@interface NativeUI : NSObject <SFSafariViewControllerDelegate>
66
+(CGSize)GetUnityViewSize;
7+
+(void)OpenUrl:(NSString *)url;
78
+(void)SafariViewFromUrl:(NSString *)url onCompletionCallback:(CompletionCallback)callback;
89
+(void)SafariPageSheetFromUrl:(NSString *)url onCompletionCallback:(CompletionCallback)callback;
910
+(void)RegisterStatusBarOrientationChangeCallback:(OrientationChangeCallback)callback;
@@ -32,6 +33,14 @@ extern "C"
3233
y = size.height;
3334
}
3435

36+
void NativeUI_OpenUrl(const char* url)
37+
{
38+
if(url == NULL)
39+
return;
40+
41+
[NativeUI OpenUrl:[NSString stringWithUTF8String:url]];
42+
}
43+
3544
void NativeUI_SafariViewFromUrl(const char* url, CompletionCallback onCompletionCallback)
3645
{
3746
if(url == NULL)

Plugins/Native/Implementations/NativeUI.mm

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ +(instancetype)Instance {
2020
}
2121

2222

23+
+(void)OpenUrl:(NSString *)url
24+
{
25+
NSURL * nsUrl = [NSURL URLWithString:url];
26+
27+
if(nsUrl == nil)
28+
{
29+
return;
30+
}
31+
[[UIApplication sharedApplication] openURL:nsUrl options:@{} completionHandler:nil];
32+
}
2333

2434
+(void)SafariViewFromUrl:(NSString *)url onCompletionCallback:(CompletionCallback)callback
2535
{

0 commit comments

Comments
 (0)