From a1d30737052a08b74da71f46e580d28dd36ad619 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Tue, 6 Feb 2018 08:32:09 -0800 Subject: [PATCH] Cannot open settings from share extension // FREEBIE --- Signal/src/util/MainAppContext.m | 9 +++++++-- SignalMessaging/Views/ContactsViewHelper.m | 9 ++++----- SignalMessaging/views/OWSAlerts.swift | 9 ++++----- SignalServiceKit/src/Util/AppContext.h | 4 ++-- SignalShareExtension/utils/ShareAppExtensionContext.m | 4 ++-- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Signal/src/util/MainAppContext.m b/Signal/src/util/MainAppContext.m index 97f26ccec..1853fed41 100644 --- a/Signal/src/util/MainAppContext.m +++ b/Signal/src/util/MainAppContext.m @@ -6,6 +6,7 @@ #import "Signal-Swift.h" #import #import +#import #import NS_ASSUME_NONNULL_BEGIN @@ -178,9 +179,13 @@ NS_ASSUME_NONNULL_BEGIN return UIApplication.sharedApplication.keyWindow; } -- (void)openSystemSettings +- (nullable UIAlertAction *)openSystemSettingsAction { - [UIApplication.sharedApplication openSystemSettings]; + return [UIAlertAction actionWithTitle:CommonStrings.openSettingsButton + style:UIAlertActionStyleDefault + handler:^(UIAlertAction *_Nonnull action) { + [UIApplication.sharedApplication openSystemSettings]; + }]; } - (void)doMultiDeviceUpdateWithProfileKey:(OWSAES256Key *)profileKey diff --git a/SignalMessaging/Views/ContactsViewHelper.m b/SignalMessaging/Views/ContactsViewHelper.m index 858a6c04b..50438e5e0 100644 --- a/SignalMessaging/Views/ContactsViewHelper.m +++ b/SignalMessaging/Views/ContactsViewHelper.m @@ -282,11 +282,10 @@ NS_ASSUME_NONNULL_BEGIN style:UIAlertActionStyleCancel handler:nil]]; - [alertController addAction:[UIAlertAction actionWithTitle:CommonStrings.openSettingsButton - style:UIAlertActionStyleDefault - handler:^(UIAlertAction *_Nonnull action) { - [CurrentAppContext() openSystemSettings]; - }]]; + UIAlertAction *_Nullable openSystemSettingsAction = CurrentAppContext().openSystemSettingsAction; + if (openSystemSettingsAction) { + [alertController addAction:openSystemSettingsAction]; + } [viewController presentViewController:alertController animated:YES completion:nil]; } diff --git a/SignalMessaging/views/OWSAlerts.swift b/SignalMessaging/views/OWSAlerts.swift index 0a21d58ae..a0d5cdf25 100644 --- a/SignalMessaging/views/OWSAlerts.swift +++ b/SignalMessaging/views/OWSAlerts.swift @@ -14,12 +14,11 @@ import Foundation let alertMessage = NSLocalizedString("CALL_AUDIO_PERMISSION_MESSAGE", comment:"Alert message when calling and permissions for microphone are missing") let alertController = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: .alert) let dismissAction = UIAlertAction(title: CommonStrings.dismissButton, style: .cancel) - let settingsString = CommonStrings.openSettingsButton - let settingsAction = UIAlertAction(title: settingsString, style: .default) { _ in - CurrentAppContext().openSystemSettings() - } + alertController.addAction(dismissAction) - alertController.addAction(settingsAction) + if let settingsAction = CurrentAppContext().openSystemSettingsAction { + alertController.addAction(settingsAction) + } CurrentAppContext().frontmostViewController()?.present(alertController, animated: true, completion: nil) } diff --git a/SignalServiceKit/src/Util/AppContext.h b/SignalServiceKit/src/Util/AppContext.h index bf367a797..a003f302b 100755 --- a/SignalServiceKit/src/Util/AppContext.h +++ b/SignalServiceKit/src/Util/AppContext.h @@ -61,8 +61,8 @@ typedef void (^BackgroundTaskExpirationHandler)(void); // Returns the VC that should be used to present alerts, modals, etc. - (nullable UIViewController *)frontmostViewController; -// Should only be called if isMainApp is YES. -- (void)openSystemSettings; +// Returns nil if isMainApp is NO +@property (nullable, nonatomic, readonly) UIAlertAction *openSystemSettingsAction; // Should only be called if isMainApp is YES, // but should only be necessary to call if isMainApp is YES. diff --git a/SignalShareExtension/utils/ShareAppExtensionContext.m b/SignalShareExtension/utils/ShareAppExtensionContext.m index 4553f1cc7..60dc26ae7 100644 --- a/SignalShareExtension/utils/ShareAppExtensionContext.m +++ b/SignalShareExtension/utils/ShareAppExtensionContext.m @@ -177,9 +177,9 @@ NS_ASSUME_NONNULL_BEGIN return self.rootViewController.view; } -- (void)openSystemSettings +- (nullable UIAlertAction *)openSystemSettingsAction { - OWSFail(@"%@ called %s.", self.logTag, __PRETTY_FUNCTION__); + return nil; } - (void)doMultiDeviceUpdateWithProfileKey:(OWSAES256Key *)profileKey