Skip to content

Commit f920ecc

Browse files
committed
新增 Device.IsIPad 以及 Device.IsIPhoneNotchScreen
1 parent 219993f commit f920ecc

4 files changed

Lines changed: 59 additions & 8 deletions

File tree

Plugins/CS/Device.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ namespace iOSNativePlugin
88
{
99
public static class Device
1010
{
11+
[DllImport("__Internal")]
12+
static extern bool Device_IsIPhoneNotchScreen();
13+
14+
[DllImport("__Internal")]
15+
static extern bool Device_IsIPad();
16+
1117
[DllImport("__Internal")]
1218
static extern int Device_GetDeviceOrientation();
1319

@@ -29,6 +35,15 @@ public static class Device
2935
[DllImport("__Internal")]
3036
static extern string Device_GetCountryCode();
3137

38+
/// <summary>
39+
/// 是否是 iPhone 刘海屏
40+
/// </summary>
41+
/// <returns></returns>
42+
public static bool IsIPhoneNotchScreen() => Device_IsIPhoneNotchScreen();
43+
44+
// 是否在 iPad 运行
45+
public static bool IsIPad() => Device_IsIPad();
46+
3247
/// <summary>
3348
/// 获取当前设备的物理朝向
3449
/// </summary>
@@ -45,14 +60,14 @@ public static bool IsBluetoothHeadphonesConnected()
4560
=> Audio_IsBluetoothHeadphonesConnected();
4661

4762
/// <summary>
48-
/// 判断当前app是否运行在Mac Catalyst环境下
63+
/// 判断当前app是否运行在 Mac Catalyst 环境下
4964
/// </summary>
5065
/// <returns></returns>
5166
[Obsolete("Use IsRunningOnMac instead.")]
5267
public static bool IsMacCatalyst() => Device_IsMacCatalyst();
5368

5469
/// <summary>
55-
/// 判断当前app是否运行在Mac环境下
70+
/// 判断当前 app 是否运行在 Mac 环境下
5671
/// </summary>
5772
/// <returns></returns>
5873
public static bool IsRunningOnMac()

Plugins/Native/Headers/Device.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#import "../Utils.mm"
22

33
@interface Device : NSObject
4-
4+
+(BOOL)IsIPhoneNotchScreen;
5+
+(BOOL)IsIPad;
56
+(NSInteger)GetDeviceOrientation;
67
+(BOOL)IsMacCatalyst;
78
+(BOOL)IsSuperuser;
@@ -12,6 +13,14 @@
1213

1314
extern "C"
1415
{
16+
bool Device_IsIPhoneNotchScreen()
17+
{
18+
return [Device IsIPhoneNotchScreen];
19+
}
20+
bool Device_IsIPad()
21+
{
22+
return [Device IsIPad];
23+
}
1524
int Device_GetDeviceOrientation(){
1625
return (int)[Device GetDeviceOrientation];
1726
}

Plugins/Native/Implementations/Device.mm

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
11
#import <UIKit/UIFeedbackGenerator.h>
22
#import "../Headers/Device.h"
3+
#import <UIKit/UIDevice.h>
34

45
@implementation Device
56

6-
+(NSInteger)GetDeviceOrientation{
7+
+(BOOL)IsIPhoneNotchScreen
8+
{
9+
if([Device IsIPad])
10+
return NO;
11+
12+
UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window];
13+
return mainWindow.safeAreaInsets.bottom > 0.0;
14+
}
15+
16+
+(BOOL)IsIPad
17+
{
18+
return [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad;
19+
}
20+
21+
+(NSInteger)GetDeviceOrientation
22+
{
723
return [[UIDevice currentDevice]orientation];
824
}
925

10-
+(BOOL)IsMacCatalyst{
26+
+(BOOL)IsMacCatalyst
27+
{
1128
#if TARGET_OS_MACCATALYST
1229
return YES;
1330
#else

Plugins/Native/Implementations/NativeUI.mm

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,22 @@ +(void)SetStatusBarOrientation:(NSInteger)orientation{
134134
}
135135
+(BOOL)IsStatusBarHidden {
136136
return [UIApplication sharedApplication].isStatusBarHidden;
137+
//return [UnityGetGLViewController() prefersStatusBarHidden];
137138
}
138139

139140

140141
+(void)SetStatusBarHidden:(BOOL)hidden
141142
withAnimation:(NSInteger)withAnimation {
142-
if([NativeUI IsStatusBarHidden] == hidden)
143-
return;
143+
/* if([NativeUI IsStatusBarHidden] == hidden)
144+
return; */
144145

145146
dispatch_async(dispatch_get_main_queue(), ^{
146-
[[UIApplication sharedApplication] setStatusBarHidden:hidden withAnimation:(UIStatusBarAnimation)withAnimation];
147+
[[UIApplication sharedApplication] setStatusBarHidden:hidden
148+
withAnimation:(UIStatusBarAnimation)withAnimation];
149+
[UnityGetGLViewController() setNeedsStatusBarAppearanceUpdate];
150+
UIWindow * keyWindow = [UIApplication sharedApplication].keyWindow;
151+
[keyWindow setNeedsLayout];
152+
[keyWindow layoutIfNeeded];
147153
});
148154
}
149155

@@ -153,6 +159,10 @@ +(void)SetStatusBarStyle:(NSInteger)style animated:(BOOL)animated{
153159

154160
dispatch_async(dispatch_get_main_queue(), ^{
155161
[[UIApplication sharedApplication] setStatusBarStyle:statusBarStyle animated:animated];
162+
[UnityGetGLViewController() setNeedsStatusBarAppearanceUpdate];
163+
UIWindow * keyWindow = [UIApplication sharedApplication].keyWindow;
164+
[keyWindow setNeedsLayout];
165+
[keyWindow layoutIfNeeded];
156166
});
157167

158168
}

0 commit comments

Comments
 (0)