From ef0e53a7ac2487158608a2c95fa699533fb1e6cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Thu, 19 Mar 2020 11:52:02 +0800 Subject: [PATCH] iOS: hasNotch implements --- doric-iOS/Pod/Classes/Engine/DoricJSEngine.m | 1 + doric-iOS/Pod/Classes/Util/DoricUtil.h | 2 ++ doric-iOS/Pod/Classes/Util/DoricUtil.m | 9 +++++++++ 3 files changed, 12 insertions(+) diff --git a/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m b/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m index c1c25bc1..7d6f6e8d 100644 --- a/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m +++ b/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m @@ -68,6 +68,7 @@ - (instancetype)init { @"screenWidth": @([[UIScreen mainScreen] bounds].size.width), @"screenHeight": @([[UIScreen mainScreen] bounds].size.height), @"statusBarHeight": @([[UIApplication sharedApplication] statusBarFrame].size.height), + @"hasNotch": @(hasNotch()), @"deviceBrand": @"Apple", @"deviceModel": platform, }; diff --git a/doric-iOS/Pod/Classes/Util/DoricUtil.h b/doric-iOS/Pod/Classes/Util/DoricUtil.h index e04430d2..4cc81175 100644 --- a/doric-iOS/Pod/Classes/Util/DoricUtil.h +++ b/doric-iOS/Pod/Classes/Util/DoricUtil.h @@ -42,3 +42,5 @@ NSBundle *_Nonnull DoricBundle(void); void ShowToast(NSString *_Nonnull text, DoricGravity gravity); UIImage *_Nonnull UIImageWithColor(UIColor *_Nonnull color); + +BOOL hasNotch(void); diff --git a/doric-iOS/Pod/Classes/Util/DoricUtil.m b/doric-iOS/Pod/Classes/Util/DoricUtil.m index a84eec6c..e6e8653a 100644 --- a/doric-iOS/Pod/Classes/Util/DoricUtil.m +++ b/doric-iOS/Pod/Classes/Util/DoricUtil.m @@ -95,3 +95,12 @@ void ShowToast(NSString *text, DoricGravity gravity) { UIGraphicsEndImageContext(); return image; } + +BOOL hasNotch() { + if (@available(iOS 11.0, *)) { + CGFloat height = [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom; + return (height > 0); + } else { + return NO; + } +}