display error if user picks directory/bundle e.g. .pxm

// FREEBIE
pull/1/head
Michael Kirk
parent babe024ea6
commit 93fe122323

@ -2182,7 +2182,7 @@ typedef enum : NSUInteger {
- (void)showAttachmentDocumentPicker
{
NSString *allItems = (__bridge NSString *)kUTTypeData;
NSString *allItems = (__bridge NSString *)kUTTypeItem;
NSArray<NSString *> *documentTypes = @[ allItems ];
// UIDocumentPickerModeImport copies to a temp file within our container.
// It uses more memory than "open" but lets us avoid working with security scoped URLs.
@ -2209,13 +2209,45 @@ typedef enum : NSUInteger {
NSData *attachmentData = [NSData dataWithContentsOfURL:url];
NSString *type;
NSError *error;
[url getResourceValue:&type forKey:NSURLTypeIdentifierKey error:&error];
if (error) {
DDLogError(@"%@ Determining type of picked document at url: %@ failed with error: %@", self.tag, url, error);
NSError *typeError;
[url getResourceValue:&type forKey:NSURLTypeIdentifierKey error:&typeError];
if (typeError) {
DDLogError(
@"%@ Determining type of picked document at url: %@ failed with error: %@", self.tag, url, typeError);
OWSAssert(NO);
}
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);
} else if ([isDirectory boolValue]) {
DDLogInfo(@"%@ User picked directory at url: %@", self.tag, url);
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:
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")
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *dismissAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"DISMISS_BUTTON_TEXT", nil)
style:UIAlertActionStyleCancel
handler:nil];
[alertController addAction:dismissAction];
dispatch_async(dispatch_get_main_queue(), ^{
[self presentViewController:alertController animated:YES completion:nil];
});
return;
}
if (!type) {
DDLogDebug(@"%@ falling back to default filetype for picked document at url: %@", self.tag, url);
OWSAssert(NO);

@ -106,6 +106,12 @@
/* Alert title when picking a document fails for an unknown reason */
"ATTACHMENT_PICKER_DOCUMENTS_FAILED_ALERT_TITLE" = "Failed to choose document.";
/* Alert body when picking a document fails because user picked a directory/bundle */
"ATTACHMENT_PICKER_DOCUMENTS_PICKED_DIRECTORY_FAILED_ALERT_BODY" = "Signal can't handle that file as is. Try zipping it before sending.";
/* Alert title when picking a document fails because user picked a directory/bundle */
"ATTACHMENT_PICKER_DOCUMENTS_PICKED_DIRECTORY_FAILED_ALERT_TITLE" = "Unsupported File";
/* An explanation of the consequences of blocking another user. */
"BLOCK_BEHAVIOR_EXPLANATION" = "Blocked users will not be able to call you or send you messages.";

Loading…
Cancel
Save