Defer handling app delegate hooks until app is ready.

pull/1/head
Matthew Chen 8 years ago
parent 6ed5d814f1
commit 3e8b08e19b

@ -476,7 +476,9 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
if (!AppReadiness.isAppReady) { if (!AppReadiness.isAppReady) {
DDLogWarn(@"%@ Ignoring openURL: app not ready.", self.logTag); DDLogWarn(@"%@ Ignoring openURL: app not ready.", self.logTag);
// TODO: Consider using [AppReadiness runNowOrWhenAppIsReady:]. // We don't need to use [AppReadiness runNowOrWhenAppIsReady:];
// the only URLs we handle in Signal iOS at the moment are used
// for resuming the verification step of the registration flow.
return NO; return NO;
} }
@ -644,16 +646,8 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
return; return;
} }
if (!AppReadiness.isAppReady) { [AppReadiness runNowOrWhenAppIsReady:^{
DDLogWarn(@"%@ Ignoring performActionForShortcutItem: app not ready.", self.logTag); if (![TSAccountManager isRegistered]) {
// TODO: Consider using [AppReadiness runNowOrWhenAppIsReady:].
completionHandler(NO);
}
if ([TSAccountManager isRegistered]) {
[SignalApp.sharedApp.homeViewController showNewConversationView];
completionHandler(YES);
} else {
UIAlertController *controller = UIAlertController *controller =
[UIAlertController alertControllerWithTitle:NSLocalizedString(@"REGISTER_CONTACTS_WELCOME", nil) [UIAlertController alertControllerWithTitle:NSLocalizedString(@"REGISTER_CONTACTS_WELCOME", nil)
message:NSLocalizedString(@"REGISTRATION_RESTRICTED_MESSAGE", nil) message:NSLocalizedString(@"REGISTRATION_RESTRICTED_MESSAGE", nil)
@ -670,7 +664,13 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
completion:^{ completion:^{
completionHandler(NO); completionHandler(NO);
}]; }];
return;
} }
[SignalApp.sharedApp.homeViewController showNewConversationView];
}];
completionHandler(YES);
} }
/** /**
@ -687,12 +687,6 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
return NO; return NO;
} }
if (!AppReadiness.isAppReady) {
DDLogWarn(@"%@ Ignoring continueUserActivity: app not ready.", self.logTag);
// TODO: Consider using [AppReadiness runNowOrWhenAppIsReady:].
return NO;
}
if ([userActivity.activityType isEqualToString:@"INStartVideoCallIntent"]) { if ([userActivity.activityType isEqualToString:@"INStartVideoCallIntent"]) {
if (!SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(10, 0)) { if (!SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(10, 0)) {
DDLogError(@"%@ unexpectedly received INStartVideoCallIntent pre iOS10", self.logTag); DDLogError(@"%@ unexpectedly received INStartVideoCallIntent pre iOS10", self.logTag);
@ -715,12 +709,14 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
return NO; return NO;
} }
[AppReadiness runNowOrWhenAppIsReady:^{
NSString *_Nullable phoneNumber = handle; NSString *_Nullable phoneNumber = handle;
if ([handle hasPrefix:CallKitCallManager.kAnonymousCallHandlePrefix]) { if ([handle hasPrefix:CallKitCallManager.kAnonymousCallHandlePrefix]) {
phoneNumber = [[TSStorageManager sharedManager] phoneNumberForCallKitId:handle]; phoneNumber = [[TSStorageManager sharedManager] phoneNumberForCallKitId:handle];
if (phoneNumber.length < 1) { if (phoneNumber.length < 1) {
DDLogWarn(@"%@ ignoring attempt to initiate video call to unknown anonymous signal user.", self.logTag); DDLogWarn(
return NO; @"%@ ignoring attempt to initiate video call to unknown anonymous signal user.", self.logTag);
return;
} }
} }
@ -736,17 +732,19 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
if ([phoneNumber isEqualToString:SignalApp.sharedApp.callService.call.remotePhoneNumber]) { if ([phoneNumber isEqualToString:SignalApp.sharedApp.callService.call.remotePhoneNumber]) {
DDLogWarn(@"%@ trying to upgrade ongoing call to video.", self.logTag); DDLogWarn(@"%@ trying to upgrade ongoing call to video.", self.logTag);
[SignalApp.sharedApp.callService handleCallKitStartVideo]; [SignalApp.sharedApp.callService handleCallKitStartVideo];
return YES; return;
} else { } else {
DDLogWarn( DDLogWarn(@"%@ ignoring INStartVideoCallIntent due to ongoing WebRTC call with another party.",
@"%@ ignoring INStartVideoCallIntent due to ongoing WebRTC call with another party.", self.logTag); self.logTag);
return NO; return;
} }
} }
OutboundCallInitiator *outboundCallInitiator = SignalApp.sharedApp.outboundCallInitiator; OutboundCallInitiator *outboundCallInitiator = SignalApp.sharedApp.outboundCallInitiator;
OWSAssert(outboundCallInitiator); OWSAssert(outboundCallInitiator);
return [outboundCallInitiator initiateCallWithHandle:phoneNumber]; [outboundCallInitiator initiateCallWithHandle:phoneNumber];
}];
return YES;
} else if ([userActivity.activityType isEqualToString:@"INStartAudioCallIntent"]) { } else if ([userActivity.activityType isEqualToString:@"INStartAudioCallIntent"]) {
if (!SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(10, 0)) { if (!SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(10, 0)) {
@ -770,23 +768,27 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
return NO; return NO;
} }
[AppReadiness runNowOrWhenAppIsReady:^{
NSString *_Nullable phoneNumber = handle; NSString *_Nullable phoneNumber = handle;
if ([handle hasPrefix:CallKitCallManager.kAnonymousCallHandlePrefix]) { if ([handle hasPrefix:CallKitCallManager.kAnonymousCallHandlePrefix]) {
phoneNumber = [[TSStorageManager sharedManager] phoneNumberForCallKitId:handle]; phoneNumber = [[TSStorageManager sharedManager] phoneNumberForCallKitId:handle];
if (phoneNumber.length < 1) { if (phoneNumber.length < 1) {
DDLogWarn(@"%@ ignoring attempt to initiate audio call to unknown anonymous signal user.", self.logTag); DDLogWarn(
return NO; @"%@ ignoring attempt to initiate audio call to unknown anonymous signal user.", self.logTag);
return;
} }
} }
if (SignalApp.sharedApp.callService.call != nil) { if (SignalApp.sharedApp.callService.call != nil) {
DDLogWarn(@"%@ ignoring INStartAudioCallIntent due to ongoing WebRTC call.", self.logTag); DDLogWarn(@"%@ ignoring INStartAudioCallIntent due to ongoing WebRTC call.", self.logTag);
return NO; return;
} }
OutboundCallInitiator *outboundCallInitiator = SignalApp.sharedApp.outboundCallInitiator; OutboundCallInitiator *outboundCallInitiator = SignalApp.sharedApp.outboundCallInitiator;
OWSAssert(outboundCallInitiator); OWSAssert(outboundCallInitiator);
return [outboundCallInitiator initiateCallWithHandle:phoneNumber]; [outboundCallInitiator initiateCallWithHandle:phoneNumber];
}];
return YES;
} else { } else {
DDLogWarn(@"%@ called %s with userActivity: %@, but not yet supported.", DDLogWarn(@"%@ called %s with userActivity: %@, but not yet supported.",
self.logTag, self.logTag,
@ -910,16 +912,18 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
return; return;
} }
if (!AppReadiness.isAppReady) { // The docs for handleActionWithIdentifier:... state:
DDLogWarn(@"%@ Ignoring handleActionWithIdentifier: app not ready.", self.logTag); // "You must call [completionHandler] at the end of your method.".
// TODO: Consider using [AppReadiness runNowOrWhenAppIsReady:]. // Nonetheless, it is presumably safe to call the completion handler
return; // later, after this method returns.
} //
// https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623068-application?language=objc
[AppReadiness runNowOrWhenAppIsReady:^{
[[PushManager sharedManager] application:application [[PushManager sharedManager] application:application
handleActionWithIdentifier:identifier handleActionWithIdentifier:identifier
forLocalNotification:notification forLocalNotification:notification
completionHandler:completionHandler]; completionHandler:completionHandler];
}];
} }
- (void)application:(UIApplication *)application - (void)application:(UIApplication *)application
@ -935,17 +939,19 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
return; return;
} }
if (!AppReadiness.isAppReady) { // The docs for handleActionWithIdentifier:... state:
DDLogWarn(@"%@ Ignoring handleActionWithIdentifier: app not ready.", self.logTag); // "You must call [completionHandler] at the end of your method.".
// TODO: Consider using [AppReadiness runNowOrWhenAppIsReady:]. // Nonetheless, it is presumably safe to call the completion handler
return; // later, after this method returns.
} //
// https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623068-application?language=objc
[AppReadiness runNowOrWhenAppIsReady:^{
[[PushManager sharedManager] application:application [[PushManager sharedManager] application:application
handleActionWithIdentifier:identifier handleActionWithIdentifier:identifier
forLocalNotification:notification forLocalNotification:notification
withResponseInfo:responseInfo withResponseInfo:responseInfo
completionHandler:completionHandler]; completionHandler:completionHandler];
}];
} }
- (void)versionMigrationsDidComplete - (void)versionMigrationsDidComplete

Loading…
Cancel
Save