|
|
|
@ -265,33 +265,98 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
|
|
|
|
|
DDLogWarn(@"Application opened with an unknown URL action: %@", url.host);
|
|
|
|
|
}
|
|
|
|
|
} else if ([url.scheme.lowercaseString isEqualToString:@"file"]) {
|
|
|
|
|
|
|
|
|
|
if ([Environment getCurrent].callService.call != nil) {
|
|
|
|
|
DDLogWarn(@"%@ ignoring 'open with Signal' due to ongoing WebRTC call.", self.tag);
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NSString *filename = url.lastPathComponent;
|
|
|
|
|
if ([filename stringByDeletingPathExtension].length < 1) {
|
|
|
|
|
DDLogError(@"Application opened with URL invalid filename: %@", url);
|
|
|
|
|
[self showErrorAlertWithTitle:
|
|
|
|
|
NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_TITLE",
|
|
|
|
|
@"Title for the alert indicating the 'export with signal' attachment had an error.")
|
|
|
|
|
message:NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_MESSAGE_INVALID_FILENAME",
|
|
|
|
|
@"Message for the alert indicating the 'export with signal' file had an "
|
|
|
|
|
@"invalid filename.")];
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
NSString *fileExtension = [filename pathExtension];
|
|
|
|
|
if (fileExtension.length < 1) {
|
|
|
|
|
DDLogError(@"Application opened with URL missing file extension: %@", url);
|
|
|
|
|
[self showErrorAlertWithTitle:
|
|
|
|
|
NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_TITLE",
|
|
|
|
|
@"Title for the alert indicating the 'export with signal' attachment had an error.")
|
|
|
|
|
message:NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_MESSAGE_UNKNOWN_TYPE",
|
|
|
|
|
@"Message for the alert indicating the 'export with signal' file had "
|
|
|
|
|
@"unknown type.")];
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
NSString *utiType = [MIMETypeUtil utiTypeForFileExtension:fileExtension];
|
|
|
|
|
if (utiType.length < 1) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NSString *utiType;
|
|
|
|
|
NSError *typeError;
|
|
|
|
|
[url getResourceValue:&utiType forKey:NSURLTypeIdentifierKey error:&typeError];
|
|
|
|
|
if (typeError) {
|
|
|
|
|
DDLogError(
|
|
|
|
|
@"%@ Determining type of picked document at url: %@ failed with error: %@", self.tag, url, typeError);
|
|
|
|
|
OWSAssert(NO);
|
|
|
|
|
}
|
|
|
|
|
if (!utiType) {
|
|
|
|
|
DDLogDebug(@"%@ falling back to default filetype for picked document at url: %@", self.tag, url);
|
|
|
|
|
OWSAssert(NO);
|
|
|
|
|
utiType = (__bridge NSString *)kUTTypeData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NSNumber *isDirectory;
|
|
|
|
|
NSError *isDirectoryError;
|
|
|
|
|
[url getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:&isDirectoryError];
|
|
|
|
|
if (isDirectoryError) {
|
|
|
|
|
DDLogError(@"%@ Determining if picked document at url: %@ was a directory failed with error: %@",
|
|
|
|
|
self.tag,
|
|
|
|
|
url,
|
|
|
|
|
isDirectoryError);
|
|
|
|
|
OWSAssert(NO);
|
|
|
|
|
return NO;
|
|
|
|
|
} else if ([isDirectory boolValue]) {
|
|
|
|
|
DDLogInfo(@"%@ User picked directory at url: %@", self.tag, url);
|
|
|
|
|
DDLogError(@"Application opened with URL of unknown UTI type: %@", url);
|
|
|
|
|
[self showErrorAlertWithTitle:NSLocalizedString(@"ATTACHMENT_PICKER_DOCUMENTS_PICKED_DIRECTORY_FAILED_ALERT_TITLE",
|
|
|
|
|
@"Alert title when picking a document fails because user picked a directory/bundle")
|
|
|
|
|
message:NSLocalizedString(@"ATTACHMENT_PICKER_DOCUMENTS_PICKED_DIRECTORY_FAILED_ALERT_BODY",
|
|
|
|
|
@"Alert body when picking a document fails because user picked a directory/bundle")];
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NSData *data = [NSData dataWithContentsOfURL:url];
|
|
|
|
|
if (!data) {
|
|
|
|
|
DDLogError(@"Application opened with URL with unloadable content: %@", url);
|
|
|
|
|
[self showErrorAlertWithTitle:
|
|
|
|
|
NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_TITLE",
|
|
|
|
|
@"Title for the alert indicating the 'export with signal' attachment had an error.")
|
|
|
|
|
message:NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_MESSAGE_MISSING_DATA",
|
|
|
|
|
@"Message for the alert indicating the 'export with signal' data "
|
|
|
|
|
@"couldn't be loaded.")];
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
SignalAttachment *attachment = [SignalAttachment attachmentWithData:data dataUTI:utiType filename:filename];
|
|
|
|
|
if (!attachment) {
|
|
|
|
|
DDLogError(@"Application opened with URL with invalid content: %@", url);
|
|
|
|
|
[self showErrorAlertWithTitle:
|
|
|
|
|
NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_TITLE",
|
|
|
|
|
@"Title for the alert indicating the 'export with signal' attachment had an error.")
|
|
|
|
|
message:NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_MESSAGE_MISSING_ATTACHMENT",
|
|
|
|
|
@"Message for the alert indicating the 'export with signal' attachment "
|
|
|
|
|
@"couldn't be loaded.")];
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
if ([attachment hasError]) {
|
|
|
|
|
DDLogError(@"Application opened with URL with content error: %@ %@", url, [attachment errorName]);
|
|
|
|
|
[self showErrorAlertWithTitle:
|
|
|
|
|
NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_TITLE",
|
|
|
|
|
@"Title for the alert indicating the 'export with signal' attachment had an error.")
|
|
|
|
|
message:[attachment errorName]];
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
DDLogInfo(@"Application opened with URL: %@", url);
|
|
|
|
@ -318,6 +383,23 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)showErrorAlertWithTitle:(NSString *)title message:(NSString *)message
|
|
|
|
|
{
|
|
|
|
|
OWSAssert(title.length > 0);
|
|
|
|
|
OWSAssert(message.length > 0);
|
|
|
|
|
|
|
|
|
|
UIAlertController *controller =
|
|
|
|
|
[UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
|
|
|
|
|
|
|
|
|
|
[controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil)
|
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
|
handler:nil]];
|
|
|
|
|
|
|
|
|
|
[[Environment getCurrent].signalsViewController presentTopLevelModalViewController:controller
|
|
|
|
|
animateDismissal:YES
|
|
|
|
|
animatePresentation:YES];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
|
|
|
|
DDLogWarn(@"%@ applicationDidBecomeActive.", self.tag);
|
|
|
|
|
|
|
|
|
|