diff --git a/Signal/src/ViewControllers/AttachmentSharing.m b/Signal/src/ViewControllers/AttachmentSharing.m index 824f4f558..0ee5f518b 100644 --- a/Signal/src/ViewControllers/AttachmentSharing.m +++ b/Signal/src/ViewControllers/AttachmentSharing.m @@ -5,6 +5,7 @@ #import "AttachmentSharing.h" #import "TSAttachmentStream.h" #import "UIUtil.h" +#import #import @implementation AttachmentSharing @@ -55,10 +56,7 @@ } }]; - // Find the frontmost presented UIViewController from which to present the - // share view. - UIWindow *window = [UIApplication sharedApplication].keyWindow; - UIViewController *fromViewController = window.rootViewController; + UIViewController *fromViewController = CurrentAppContext().frontmostViewController; while (fromViewController.presentedViewController) { fromViewController = fromViewController.presentedViewController; } diff --git a/Signal/src/ViewControllers/MediaMessageView.swift b/Signal/src/ViewControllers/MediaMessageView.swift index 682dfef00..e973b15dd 100644 --- a/Signal/src/ViewControllers/MediaMessageView.swift +++ b/Signal/src/ViewControllers/MediaMessageView.swift @@ -403,7 +403,7 @@ class MediaMessageView: UIView, OWSAudioAttachmentPlayerDelegate { guard let fromView = sender.view else { return } - guard let fromViewController = fromViewController() else { + guard let fromViewController = CurrentAppContext().frontmostViewController() else { return } let window = UIApplication.shared.keyWindow @@ -412,19 +412,6 @@ class MediaMessageView: UIView, OWSAudioAttachmentPlayerDelegate { viewController.present(from:fromViewController) } - private func fromViewController() -> UIViewController? { - var responder: UIResponder? = self - while true { - if responder == nil { - return nil - } - if let viewController = responder as? UIViewController { - return viewController - } - responder = responder?.next - } - } - // MARK: - Video Playback func videoTapped(sender: UIGestureRecognizer) { diff --git a/Signal/src/util/MainAppContext.m b/Signal/src/util/MainAppContext.m index c67837087..30d85f6ff 100644 --- a/Signal/src/util/MainAppContext.m +++ b/Signal/src/util/MainAppContext.m @@ -74,6 +74,11 @@ NS_ASSUME_NONNULL_BEGIN return getenv("runningTests_dontStartApp"); } +- (void)setNetworkActivityIndicatorVisible:(BOOL)value +{ + [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:value]; +} + @end NS_ASSUME_NONNULL_END diff --git a/SignalMessaging/SignalMessaging.h b/SignalMessaging/SignalMessaging.h index b3c6da959..11dcbd23c 100644 --- a/SignalMessaging/SignalMessaging.h +++ b/SignalMessaging/SignalMessaging.h @@ -13,9 +13,11 @@ FOUNDATION_EXPORT const unsigned char SignalMessagingVersionString[]; // The public headers of the framework #import #import +#import #import #import #import #import #import #import +#import diff --git a/SignalMessaging/contacts/OWSContactsManager.m b/SignalMessaging/contacts/OWSContactsManager.m index 1637ba90e..f67c8dbdf 100644 --- a/SignalMessaging/contacts/OWSContactsManager.m +++ b/SignalMessaging/contacts/OWSContactsManager.m @@ -232,7 +232,8 @@ NSString *const kTSStorageManager_lastKnownContactRecipientIds = @"lastKnownCont for (Contact *contact in contacts) { NSArray *signalRecipients = contactIdToSignalRecipientsMap[contact.uniqueId]; - for (SignalRecipient *signalRecipient in [signalRecipients sortedArrayUsingSelector:@selector(compare:)]) { + for (SignalRecipient *signalRecipient in + [signalRecipients sortedArrayUsingSelector:@selector((compare:))]) { SignalAccount *signalAccount = [[SignalAccount alloc] initWithSignalRecipient:signalRecipient]; signalAccount.contact = contact; if (signalRecipients.count > 1) { @@ -437,7 +438,7 @@ NSString *const kTSStorageManager_lastKnownContactRecipientIds = @"lastKnownCont OWSAssert([phoneNumbersWithTheSameName containsObject:recipientId]); if (phoneNumbersWithTheSameName.count > 1) { NSUInteger index = - [[phoneNumbersWithTheSameName sortedArrayUsingSelector:@selector(compare:)] indexOfObject:recipientId]; + [[phoneNumbersWithTheSameName sortedArrayUsingSelector:@selector((compare:))] indexOfObject:recipientId]; NSString *indexText = [OWSFormat formatInt:(int)index + 1]; phoneNumberLabel = [NSString stringWithFormat:NSLocalizedString(@"PHONE_NUMBER_TYPE_AND_INDEX_NAME_FORMAT", diff --git a/SignalMessaging/environment/VersionMigrations.m b/SignalMessaging/environment/VersionMigrations.m index c679c9ac6..c9b3a07e1 100644 --- a/SignalMessaging/environment/VersionMigrations.m +++ b/SignalMessaging/environment/VersionMigrations.m @@ -7,6 +7,7 @@ #import "LockInteractionController.h" #import "OWSDatabaseMigrationRunner.h" #import "SignalKeyingStorage.h" +#import #import #import #import @@ -65,9 +66,7 @@ }]; [alertController addAction:quitAction]; - [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alertController - animated:YES - completion:nil]; + [CurrentAppContext().frontmostViewController presentViewController:alertController animated:YES completion:nil]; } if ([self isVersion:previousVersion atLeast:@"2.0.0" andLessThan:@"2.1.70"] && [TSAccountManager isRegistered]) { diff --git a/SignalMessaging/viewControllers/LockInteractionController.m b/SignalMessaging/viewControllers/LockInteractionController.m index 03e40e287..becbdce70 100644 --- a/SignalMessaging/viewControllers/LockInteractionController.m +++ b/SignalMessaging/viewControllers/LockInteractionController.m @@ -3,11 +3,16 @@ // #import "LockInteractionController.h" +#import @interface LockInteractionController () -@property UIAlertController *alertController; + +@property (nonatomic) UIAlertController *alertController; + @end +#pragma mark - + @implementation LockInteractionController + (instancetype)sharedController @@ -27,7 +32,7 @@ { if (networkFlag) { - [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:networkFlag]; + [CurrentAppContext() setNetworkActivityIndicatorVisible:networkFlag]; } LockInteractionController *sharedController = [LockInteractionController sharedController]; @@ -36,10 +41,9 @@ message:nil preferredStyle:UIAlertControllerStyleAlert]; - [[UIApplication sharedApplication].keyWindow.rootViewController - presentViewController:sharedController.alertController - animated:YES - completion:nil]; + [CurrentAppContext().frontmostViewController presentViewController:sharedController.alertController + animated:YES + completion:nil]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ BOOL success = blockingOperation(); @@ -49,7 +53,7 @@ dismissViewControllerAnimated:YES completion:^{ if (networkFlag) { - [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; + [CurrentAppContext() setNetworkActivityIndicatorVisible:NO]; } if (!success) { @@ -84,9 +88,7 @@ usesNetwork:YES]; }]]; - [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:retryController - animated:YES - completion:nil]; + [CurrentAppContext().frontmostViewController presentViewController:retryController animated:YES completion:nil]; }; return retryBlock; diff --git a/SignalServiceKit/src/Util/AppContext.h b/SignalServiceKit/src/Util/AppContext.h index 75a9f9146..cfa110562 100755 --- a/SignalServiceKit/src/Util/AppContext.h +++ b/SignalServiceKit/src/Util/AppContext.h @@ -22,6 +22,7 @@ typedef void (^BackgroundTaskExpirationHandler)(void); // Should just return UIBackgroundTaskInvalid if isMainApp is NO. - (UIBackgroundTaskIdentifier)beginBackgroundTaskWithExpirationHandler: (BackgroundTaskExpirationHandler)expirationHandler; + // Should be a NOOP if isMainApp is NO. - (void)endBackgroundTask:(UIBackgroundTaskIdentifier)backgroundTaskIdentifier; @@ -42,6 +43,9 @@ typedef void (^BackgroundTaskExpirationHandler)(void); - (BOOL)isRunningTests; +// Should be a NOOP if isMainApp is NO. +- (void)setNetworkActivityIndicatorVisible:(BOOL)value; + @end id CurrentAppContext(void); diff --git a/SignalShareExtension/utils/ShareAppExtensionContext.m b/SignalShareExtension/utils/ShareAppExtensionContext.m index da438ee22..ddddc25f6 100644 --- a/SignalShareExtension/utils/ShareAppExtensionContext.m +++ b/SignalShareExtension/utils/ShareAppExtensionContext.m @@ -98,6 +98,11 @@ NS_ASSUME_NONNULL_BEGIN return NO; } +- (void)setNetworkActivityIndicatorVisible:(BOOL)value +{ + OWSFail(@"%@ called %s.", self.logTag, __PRETTY_FUNCTION__); +} + @end NS_ASSUME_NONNULL_END