Cannot open settings from share extension

// FREEBIE
pull/1/head
Michael Kirk 7 years ago
parent bedd1f55f6
commit a1d3073705

@ -6,6 +6,7 @@
#import "Signal-Swift.h" #import "Signal-Swift.h"
#import <SignalMessaging/Environment.h> #import <SignalMessaging/Environment.h>
#import <SignalMessaging/OWSProfileManager.h> #import <SignalMessaging/OWSProfileManager.h>
#import <SignalMessaging/SignalMessaging-Swift.h>
#import <SignalServiceKit/OWSIdentityManager.h> #import <SignalServiceKit/OWSIdentityManager.h>
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@ -178,9 +179,13 @@ NS_ASSUME_NONNULL_BEGIN
return UIApplication.sharedApplication.keyWindow; 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 - (void)doMultiDeviceUpdateWithProfileKey:(OWSAES256Key *)profileKey

@ -282,11 +282,10 @@ NS_ASSUME_NONNULL_BEGIN
style:UIAlertActionStyleCancel style:UIAlertActionStyleCancel
handler:nil]]; handler:nil]];
[alertController addAction:[UIAlertAction actionWithTitle:CommonStrings.openSettingsButton UIAlertAction *_Nullable openSystemSettingsAction = CurrentAppContext().openSystemSettingsAction;
style:UIAlertActionStyleDefault if (openSystemSettingsAction) {
handler:^(UIAlertAction *_Nonnull action) { [alertController addAction:openSystemSettingsAction];
[CurrentAppContext() openSystemSettings]; }
}]];
[viewController presentViewController:alertController animated:YES completion:nil]; [viewController presentViewController:alertController animated:YES completion:nil];
} }

@ -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 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 alertController = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: .alert)
let dismissAction = UIAlertAction(title: CommonStrings.dismissButton, style: .cancel) 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(dismissAction)
alertController.addAction(settingsAction) if let settingsAction = CurrentAppContext().openSystemSettingsAction {
alertController.addAction(settingsAction)
}
CurrentAppContext().frontmostViewController()?.present(alertController, animated: true, completion: nil) CurrentAppContext().frontmostViewController()?.present(alertController, animated: true, completion: nil)
} }

@ -61,8 +61,8 @@ typedef void (^BackgroundTaskExpirationHandler)(void);
// Returns the VC that should be used to present alerts, modals, etc. // Returns the VC that should be used to present alerts, modals, etc.
- (nullable UIViewController *)frontmostViewController; - (nullable UIViewController *)frontmostViewController;
// Should only be called if isMainApp is YES. // Returns nil if isMainApp is NO
- (void)openSystemSettings; @property (nullable, nonatomic, readonly) UIAlertAction *openSystemSettingsAction;
// Should only be called if isMainApp is YES, // Should only be called if isMainApp is YES,
// but should only be necessary to call if isMainApp is YES. // but should only be necessary to call if isMainApp is YES.

@ -177,9 +177,9 @@ NS_ASSUME_NONNULL_BEGIN
return self.rootViewController.view; return self.rootViewController.view;
} }
- (void)openSystemSettings - (nullable UIAlertAction *)openSystemSettingsAction
{ {
OWSFail(@"%@ called %s.", self.logTag, __PRETTY_FUNCTION__); return nil;
} }
- (void)doMultiDeviceUpdateWithProfileKey:(OWSAES256Key *)profileKey - (void)doMultiDeviceUpdateWithProfileKey:(OWSAES256Key *)profileKey

Loading…
Cancel
Save