From 2af818b3ba82b799207af8db80c76794afd216d0 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Fri, 1 Dec 2017 15:43:40 -0800 Subject: [PATCH] Make SignalMessaging AppExtension safe // FREEBIE --- Signal.xcodeproj/project.pbxproj | 3 +++ Signal/src/util/MainAppContext.m | 6 ++++++ SignalMessaging/categories/UIView+OWS.m | 4 ++-- SignalServiceKit/src/Util/AppContext.h | 2 ++ SignalShareExtension/utils/ShareAppExtensionContext.m | 9 +++++++++ 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index 6aae4041e..d79e7e515 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -3493,6 +3493,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = 9B533A9FA46206D3D99C9ADA /* Pods-SignalMessaging.debug.xcconfig */; buildSettings = { + APPLICATION_EXTENSION_API_ONLY = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; @@ -3546,6 +3547,7 @@ baseConfigurationReference = 948239851C08032C842937CC /* Pods-SignalMessaging.test.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + APPLICATION_EXTENSION_API_ONLY = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; @@ -3618,6 +3620,7 @@ baseConfigurationReference = 8EEE74B0753448C085B48721 /* Pods-SignalMessaging.app store release.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + APPLICATION_EXTENSION_API_ONLY = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; diff --git a/Signal/src/util/MainAppContext.m b/Signal/src/util/MainAppContext.m index 89e9a685c..0a677cc45 100644 --- a/Signal/src/util/MainAppContext.m +++ b/Signal/src/util/MainAppContext.m @@ -18,6 +18,12 @@ NS_ASSUME_NONNULL_BEGIN return [UIApplication sharedApplication].applicationState == UIApplicationStateActive; } +- (BOOL)isRTL +{ + return + [[UIApplication sharedApplication] userInterfaceLayoutDirection] == UIUserInterfaceLayoutDirectionRightToLeft; +} + - (UIApplicationState)mainApplicationState { return [UIApplication sharedApplication].applicationState; diff --git a/SignalMessaging/categories/UIView+OWS.m b/SignalMessaging/categories/UIView+OWS.m index 19f2e0dbc..bed1ade89 100644 --- a/SignalMessaging/categories/UIView+OWS.m +++ b/SignalMessaging/categories/UIView+OWS.m @@ -4,6 +4,7 @@ #import "OWSMath.h" #import "UIView+OWS.h" +#import NS_ASSUME_NONNULL_BEGIN @@ -256,8 +257,7 @@ CGFloat ScaleFromIPhone5(CGFloat iPhone5Value) return ([UIView userInterfaceLayoutDirectionForSemanticContentAttribute:self.semanticContentAttribute] == UIUserInterfaceLayoutDirectionRightToLeft); } else { - return - [UIApplication sharedApplication].userInterfaceLayoutDirection == UIUserInterfaceLayoutDirectionRightToLeft; + return [CurrentAppContext() isRTL]; } } diff --git a/SignalServiceKit/src/Util/AppContext.h b/SignalServiceKit/src/Util/AppContext.h index cb4d179ba..578cf9ec7 100755 --- a/SignalServiceKit/src/Util/AppContext.h +++ b/SignalServiceKit/src/Util/AppContext.h @@ -26,6 +26,8 @@ typedef void (^BackgroundTaskExpirationHandler)(void); // Should only be called if isMainApp is YES. - (void)setMainAppBadgeNumber:(NSInteger)value; +- (BOOL)isRTL; + @end id CurrentAppContext(void); diff --git a/SignalShareExtension/utils/ShareAppExtensionContext.m b/SignalShareExtension/utils/ShareAppExtensionContext.m index d3d5db6cd..b430e1dfa 100644 --- a/SignalShareExtension/utils/ShareAppExtensionContext.m +++ b/SignalShareExtension/utils/ShareAppExtensionContext.m @@ -18,6 +18,15 @@ NS_ASSUME_NONNULL_BEGIN return NO; } +- (BOOL)isRTL +{ + // Borrowed from PureLayout's AppExtension compatible RTL support. + // App Extensions may not access -[UIApplication sharedApplication]; fall back to checking the bundle's preferred + // localization character direction + return [NSLocale characterDirectionForLanguage:[[NSBundle mainBundle] preferredLocalizations][0]] + == NSLocaleLanguageDirectionRightToLeft; +} + - (UIApplicationState)mainApplicationState { OWSFail(@"%@ called %s.", self.logTag, __PRETTY_FUNCTION__);