mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Choose arbitrary attachments from iCloud/GDrive/Dropbox/etc
// FREEBIE
This commit is contained in:
parent
b1ea340c36
commit
70d235a670
|
@ -1665,6 +1665,9 @@
|
||||||
com.apple.VPNLite = {
|
com.apple.VPNLite = {
|
||||||
enabled = 0;
|
enabled = 0;
|
||||||
};
|
};
|
||||||
|
com.apple.iCloud = {
|
||||||
|
enabled = 1;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
D221A0A9169C9E5F00537ABF = {
|
D221A0A9169C9E5F00537ABF = {
|
||||||
|
|
|
@ -4,5 +4,17 @@
|
||||||
<dict>
|
<dict>
|
||||||
<key>aps-environment</key>
|
<key>aps-environment</key>
|
||||||
<string>development</string>
|
<string>development</string>
|
||||||
|
<key>com.apple.developer.icloud-container-identifiers</key>
|
||||||
|
<array>
|
||||||
|
<string>iCloud.$(CFBundleIdentifier)</string>
|
||||||
|
</array>
|
||||||
|
<key>com.apple.developer.icloud-services</key>
|
||||||
|
<array>
|
||||||
|
<string>CloudDocuments</string>
|
||||||
|
</array>
|
||||||
|
<key>com.apple.developer.ubiquity-container-identifiers</key>
|
||||||
|
<array>
|
||||||
|
<string>iCloud.$(CFBundleIdentifier)</string>
|
||||||
|
</array>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
|
|
@ -186,7 +186,10 @@ typedef enum : NSUInteger {
|
||||||
|
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
|
|
||||||
@interface MessagesViewController () <JSQMessagesComposerTextViewPasteDelegate, OWSTextViewPasteDelegate> {
|
@interface MessagesViewController () <JSQMessagesComposerTextViewPasteDelegate,
|
||||||
|
OWSTextViewPasteDelegate,
|
||||||
|
UIDocumentMenuDelegate,
|
||||||
|
UIDocumentPickerDelegate> {
|
||||||
UIImage *tappedImage;
|
UIImage *tappedImage;
|
||||||
BOOL isGroupConversation;
|
BOOL isGroupConversation;
|
||||||
}
|
}
|
||||||
|
@ -2182,6 +2185,87 @@ typedef enum : NSUInteger {
|
||||||
[self presentViewController:actionSheetController animated:YES completion:nil];
|
[self presentViewController:actionSheetController animated:YES completion:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#pragma mark - Attachment Picking: Documents
|
||||||
|
|
||||||
|
- (void)showAttachmentDocumentPicker
|
||||||
|
{
|
||||||
|
NSString *allItems = (__bridge NSString *)kUTTypeData;
|
||||||
|
NSArray<NSString *> *documentTypes = @[ allItems ];
|
||||||
|
// UIDocumentPickerModeImport copies to a temp file within our container.
|
||||||
|
// It uses more memory than "open" but let's us avoid working with security scoped URLs.
|
||||||
|
UIDocumentPickerMode pickerMode = UIDocumentPickerModeImport;
|
||||||
|
UIDocumentMenuViewController *menuController =
|
||||||
|
[[UIDocumentMenuViewController alloc] initWithDocumentTypes:documentTypes inMode:pickerMode];
|
||||||
|
menuController.delegate = self;
|
||||||
|
[self presentViewController:menuController animated:YES completion:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark UIDocumentMenuDelegate
|
||||||
|
|
||||||
|
- (void)documentMenu:(UIDocumentMenuViewController *)documentMenu
|
||||||
|
didPickDocumentPicker:(UIDocumentPickerViewController *)documentPicker
|
||||||
|
{
|
||||||
|
documentPicker.delegate = self;
|
||||||
|
[self presentViewController:documentPicker animated:YES completion:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark UIDocumentPickerDelegate
|
||||||
|
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url
|
||||||
|
{
|
||||||
|
DDLogDebug(@"%@ Picked document at url: %@", self.tag, url);
|
||||||
|
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);
|
||||||
|
OWSAssert(NO);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!type) {
|
||||||
|
DDLogDebug(@"%@ falling back to default filetype for picked document at url: %@", self.tag, url);
|
||||||
|
OWSAssert(NO);
|
||||||
|
type = (__bridge NSString *)kUTTypeData;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSString *filename = url.lastPathComponent;
|
||||||
|
if (!filename) {
|
||||||
|
DDLogDebug(@"%@ Unable to determine filename from url: %@", self.tag, url);
|
||||||
|
OWSAssert(NO);
|
||||||
|
filename = NSLocalizedString(
|
||||||
|
@"ATTACHMENT_DEFAULT_FILENAME", @"Generic filename for an attachment with no known name");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!attachmentData || attachmentData.length == 0) {
|
||||||
|
DDLogError(@"%@ attachment data was unexpectedly empty for picked document url: %@", self.tag, url);
|
||||||
|
OWSAssert(NO);
|
||||||
|
UIAlertController *alertController = [UIAlertController
|
||||||
|
alertControllerWithTitle:NSLocalizedString(@"ATTACHMENT_PICKER_DOCUMENTS_FAILED_ALERT_TITLE",
|
||||||
|
@"Alert title when picking a document fails for an unknown reason")
|
||||||
|
message:nil
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
OWSAssert(attachmentData);
|
||||||
|
OWSAssert(type);
|
||||||
|
OWSAssert(filename);
|
||||||
|
SignalAttachment *attachment =
|
||||||
|
[[SignalAttachment alloc] initWithData:attachmentData dataUTI:type filename:filename];
|
||||||
|
[ThreadUtil sendMessageWithAttachment:attachment inThread:self.thread messageSender:self.messageSender];
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - UIImagePickerController
|
#pragma mark - UIImagePickerController
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -2680,7 +2764,16 @@ typedef enum : NSUInteger {
|
||||||
[self chooseFromLibrary];
|
[self chooseFromLibrary];
|
||||||
}];
|
}];
|
||||||
[actionSheetController addAction:chooseMediaAction];
|
[actionSheetController addAction:chooseMediaAction];
|
||||||
|
|
||||||
|
UIAlertAction *chooseDocumentAction =
|
||||||
|
[UIAlertAction actionWithTitle:NSLocalizedString(@"MEDIA_FROM_DOCUMENT_PICKER_BUTTON",
|
||||||
|
@"action sheet button title when choosing attachment type")
|
||||||
|
style:UIAlertActionStyleDefault
|
||||||
|
handler:^(UIAlertAction *_Nonnull action) {
|
||||||
|
[self showAttachmentDocumentPicker];
|
||||||
|
}];
|
||||||
|
[actionSheetController addAction:chooseDocumentAction];
|
||||||
|
|
||||||
[self presentViewController:actionSheetController animated:true completion:nil];
|
[self presentViewController:actionSheetController animated:true completion:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ class AttachmentPointerView: UIView {
|
||||||
let isIncoming: Bool
|
let isIncoming: Bool
|
||||||
let filename: String
|
let filename: String
|
||||||
let attachmentPointer: TSAttachmentPointer
|
let attachmentPointer: TSAttachmentPointer
|
||||||
let genericFilename = NSLocalizedString("ATTACHMENT_DOWNLOADING_DEFAULT_ATTACHMENT_LABEL", comment: "Generic name label when downloading an attachment with no known name.")
|
let genericFilename = NSLocalizedString("ATTACHMENT_DEFAULT_FILENAME", comment: "Generic filename for an attachment with no known name")
|
||||||
|
|
||||||
var progress: CGFloat = 0 {
|
var progress: CGFloat = 0 {
|
||||||
didSet {
|
didSet {
|
||||||
|
|
|
@ -61,8 +61,8 @@
|
||||||
/* Label for 'send' button in the 'attachment approval' dialog. */
|
/* Label for 'send' button in the 'attachment approval' dialog. */
|
||||||
"ATTACHMENT_APPROVAL_SEND_BUTTON" = "Send";
|
"ATTACHMENT_APPROVAL_SEND_BUTTON" = "Send";
|
||||||
|
|
||||||
/* Generic name label when downloading an attachment with no known name. */
|
/* Generic filename for an attachment with no known name */
|
||||||
"ATTACHMENT_DOWNLOADING_DEFAULT_ATTACHMENT_LABEL" = "Attachment";
|
"ATTACHMENT_DEFAULT_FILENAME" = "Attachment";
|
||||||
|
|
||||||
/* Status label when an attachment download has failed. */
|
/* Status label when an attachment download has failed. */
|
||||||
"ATTACHMENT_DOWNLOADING_STATUS_FAILED" = "Failed. Tap to retry.";
|
"ATTACHMENT_DOWNLOADING_STATUS_FAILED" = "Failed. Tap to retry.";
|
||||||
|
@ -100,6 +100,9 @@
|
||||||
/* Accessibility label for attaching photos */
|
/* Accessibility label for attaching photos */
|
||||||
"ATTACHMENT_LABEL" = "Attachment";
|
"ATTACHMENT_LABEL" = "Attachment";
|
||||||
|
|
||||||
|
/* Alert title when picking a document fails for an unknown reason */
|
||||||
|
"ATTACHMENT_PICKER_DOCUMENTS_FAILED_ALERT_TITLE" = "Failed to choose document.";
|
||||||
|
|
||||||
/* An explanation of the consequences of blocking another user. */
|
/* 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.";
|
"BLOCK_BEHAVIOR_EXPLANATION" = "Blocked users will not be able to call you or send you messages.";
|
||||||
|
|
||||||
|
@ -589,6 +592,9 @@
|
||||||
/* media picker option to take photo or video */
|
/* media picker option to take photo or video */
|
||||||
"MEDIA_FROM_CAMERA_BUTTON" = "Camera";
|
"MEDIA_FROM_CAMERA_BUTTON" = "Camera";
|
||||||
|
|
||||||
|
/* action sheet button title when choosing attachment type */
|
||||||
|
"MEDIA_FROM_DOCUMENT_PICKER_BUTTON" = "Document";
|
||||||
|
|
||||||
/* media picker option to choose from library */
|
/* media picker option to choose from library */
|
||||||
"MEDIA_FROM_LIBRARY_BUTTON" = "Photo Library";
|
"MEDIA_FROM_LIBRARY_BUTTON" = "Photo Library";
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue