Merge branch 'charlesmchen/appDelegateHooksVsAppReadiness'

pull/1/head
Matthew Chen 7 years ago
commit ab95c501ee

@ -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,37 +646,43 @@ 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:]. UIAlertController *controller =
completionHandler(NO); [UIAlertController alertControllerWithTitle:NSLocalizedString(@"REGISTER_CONTACTS_WELCOME", nil)
} message:NSLocalizedString(@"REGISTRATION_RESTRICTED_MESSAGE", nil)
preferredStyle:UIAlertControllerStyleAlert];
[controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *_Nonnull action){
}]];
UIViewController *fromViewController = [[UIApplication sharedApplication] frontmostViewController];
[fromViewController presentViewController:controller
animated:YES
completion:^{
completionHandler(NO);
}];
return;
}
if ([TSAccountManager isRegistered]) {
[SignalApp.sharedApp.homeViewController showNewConversationView]; [SignalApp.sharedApp.homeViewController showNewConversationView];
completionHandler(YES); completionHandler(YES);
} else { }];
UIAlertController *controller =
[UIAlertController alertControllerWithTitle:NSLocalizedString(@"REGISTER_CONTACTS_WELCOME", nil)
message:NSLocalizedString(@"REGISTRATION_RESTRICTED_MESSAGE", nil)
preferredStyle:UIAlertControllerStyleAlert];
[controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *_Nonnull action){
}]];
UIViewController *fromViewController = [[UIApplication sharedApplication] frontmostViewController];
[fromViewController presentViewController:controller
animated:YES
completion:^{
completionHandler(NO);
}];
}
} }
/** /**
* Among other things, this is used by "call back" callkit dialog and calling from native contacts app. * Among other things, this is used by "call back" callkit dialog and calling from native contacts app.
*
* We always return YES if we are going to try to handle the user activity since
* we never want iOS to contact us again using a URL.
*
* From https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623072-application?language=objc:
*
* If you do not implement this method or if your implementation returns NO, iOS tries to
* create a document for your app to open using a URL.
*/ */
- (BOOL)application:(UIApplication *)application - (BOOL)application:(UIApplication *)application
continueUserActivity:(nonnull NSUserActivity *)userActivity continueUserActivity:(nonnull NSUserActivity *)userActivity
@ -687,12 +695,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,38 +717,42 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
return NO; return NO;
} }
NSString *_Nullable phoneNumber = handle; [AppReadiness runNowOrWhenAppIsReady:^{
if ([handle hasPrefix:CallKitCallManager.kAnonymousCallHandlePrefix]) { NSString *_Nullable phoneNumber = handle;
phoneNumber = [[TSStorageManager sharedManager] phoneNumberForCallKitId:handle]; if ([handle hasPrefix:CallKitCallManager.kAnonymousCallHandlePrefix]) {
if (phoneNumber.length < 1) { phoneNumber = [[TSStorageManager sharedManager] phoneNumberForCallKitId:handle];
DDLogWarn(@"%@ ignoring attempt to initiate video call to unknown anonymous signal user.", self.logTag); if (phoneNumber.length < 1) {
return NO; DDLogWarn(
@"%@ ignoring attempt to initiate video call to unknown anonymous signal user.", self.logTag);
return;
}
} }
}
// This intent can be received from more than one user interaction. // This intent can be received from more than one user interaction.
// //
// * It can be received if the user taps the "video" button in the CallKit UI for an // * It can be received if the user taps the "video" button in the CallKit UI for an
// an ongoing call. If so, the correct response is to try to activate the local // an ongoing call. If so, the correct response is to try to activate the local
// video for that call. // video for that call.
// * It can be received if the user taps the "video" button for a contact in the // * It can be received if the user taps the "video" button for a contact in the
// contacts app. If so, the correct response is to try to initiate a new call // contacts app. If so, the correct response is to try to initiate a new call
// to that user - unless there already is another call in progress. // to that user - unless there already is another call in progress.
if (SignalApp.sharedApp.callService.call != nil) { if (SignalApp.sharedApp.callService.call != nil) {
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 +776,27 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
return NO; return NO;
} }
NSString *_Nullable phoneNumber = handle; [AppReadiness runNowOrWhenAppIsReady:^{
if ([handle hasPrefix:CallKitCallManager.kAnonymousCallHandlePrefix]) { NSString *_Nullable phoneNumber = handle;
phoneNumber = [[TSStorageManager sharedManager] phoneNumberForCallKitId:handle]; if ([handle hasPrefix:CallKitCallManager.kAnonymousCallHandlePrefix]) {
if (phoneNumber.length < 1) { phoneNumber = [[TSStorageManager sharedManager] phoneNumberForCallKitId:handle];
DDLogWarn(@"%@ ignoring attempt to initiate audio call to unknown anonymous signal user.", self.logTag); if (phoneNumber.length < 1) {
return NO; DDLogWarn(
@"%@ 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,
@ -815,6 +825,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
// callManager.startCall(handle: handle, video: video) // callManager.startCall(handle: handle, video: video)
// return true // return true
// } // }
return NO; return NO;
} }
@ -910,16 +921,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
[[PushManager sharedManager] application:application [AppReadiness runNowOrWhenAppIsReady:^{
handleActionWithIdentifier:identifier [[PushManager sharedManager] application:application
forLocalNotification:notification handleActionWithIdentifier:identifier
completionHandler:completionHandler]; forLocalNotification:notification
completionHandler:completionHandler];
}];
} }
- (void)application:(UIApplication *)application - (void)application:(UIApplication *)application
@ -935,17 +948,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
[[PushManager sharedManager] application:application [AppReadiness runNowOrWhenAppIsReady:^{
handleActionWithIdentifier:identifier [[PushManager sharedManager] application:application
forLocalNotification:notification handleActionWithIdentifier:identifier
withResponseInfo:responseInfo forLocalNotification:notification
completionHandler:completionHandler]; withResponseInfo:responseInfo
completionHandler:completionHandler];
}];
} }
- (void)versionMigrationsDidComplete - (void)versionMigrationsDidComplete

Loading…
Cancel
Save