Skip to content

Commit

Permalink
Handle file-url type
Browse files Browse the repository at this point in the history
i.e. Files from Dropbox
  • Loading branch information
EtienneLem committed Mar 29, 2019
1 parent dbd7944 commit 4268082
Showing 1 changed file with 47 additions and 4 deletions.
51 changes: 47 additions & 4 deletions src/ios/ShareExtension/ShareViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ - (void) viewDidAppear:(BOOL)animated {
if ([itemProvider hasItemConformingToTypeIdentifier:@"public.movie"]) {
[self debug:[NSString stringWithFormat:@"item provider = %@", itemProvider]];

if (([lastDataType length] > 0) && ![lastDataType isEqualToString:@"MOVIE_OR_IMAGE"]) {
if (([lastDataType length] > 0) && ![lastDataType isEqualToString:@"FILE"]) {
--remainingAttachments;
continue;
}

lastDataType = [NSString stringWithFormat:@"MOVIE_OR_IMAGE"];
lastDataType = [NSString stringWithFormat:@"FILE"];

[itemProvider loadItemForTypeIdentifier:@"public.movie" options:nil completionHandler: ^(NSURL* item, NSError *error) {
NSString *fileUrl = [self saveFileToAppGroupFolder:item];
Expand Down Expand Up @@ -141,12 +141,12 @@ - (void) viewDidAppear:(BOOL)animated {
else if ([itemProvider hasItemConformingToTypeIdentifier:@"public.image"]) {
[self debug:[NSString stringWithFormat:@"item provider = %@", itemProvider]];

if (([lastDataType length] > 0) && ![lastDataType isEqualToString:@"MOVIE_OR_IMAGE"]) {
if (([lastDataType length] > 0) && ![lastDataType isEqualToString:@"FILE"]) {
--remainingAttachments;
continue;
}

lastDataType = [NSString stringWithFormat:@"MOVIE_OR_IMAGE"];
lastDataType = [NSString stringWithFormat:@"FILE"];

[itemProvider loadItemForTypeIdentifier:@"public.image" options:nil completionHandler: ^(NSURL* item, NSError *error) {
NSString *fileUrl = [self saveFileToAppGroupFolder:item];
Expand Down Expand Up @@ -180,6 +180,49 @@ - (void) viewDidAppear:(BOOL)animated {
}];
}

// FILE
else if ([itemProvider hasItemConformingToTypeIdentifier:@"public.file-url"]) {
[self debug:[NSString stringWithFormat:@"item provider = %@", itemProvider]];

if (([lastDataType length] > 0) && ![lastDataType isEqualToString:@"FILE"]) {
--remainingAttachments;
continue;
}

lastDataType = [NSString stringWithFormat:@"FILE"];

[itemProvider loadItemForTypeIdentifier:@"public.file-url" options:nil completionHandler: ^(NSURL* item, NSError *error) {
NSString *fileUrl = [self saveFileToAppGroupFolder:item];
NSString *suggestedName = item.lastPathComponent;

NSString *uti = @"public.file-url";
NSString *registeredType = nil;

if ([itemProvider.registeredTypeIdentifiers count] > 0) {
registeredType = itemProvider.registeredTypeIdentifiers[0];
} else {
registeredType = uti;
}

NSString *mimeType = [self mimeTypeFromUti:registeredType];
NSDictionary *dict = @{
@"text" : self.contentText,
@"fileUrl" : fileUrl,
@"uti" : uti,
@"utis" : itemProvider.registeredTypeIdentifiers,
@"name" : suggestedName,
@"type" : mimeType
};

[items addObject:dict];

--remainingAttachments;
if (remainingAttachments == 0) {
[self sendResults:results];
}
}];
}

// URL
else if ([itemProvider hasItemConformingToTypeIdentifier:@"public.url"]) {
[self debug:[NSString stringWithFormat:@"item provider = %@", itemProvider]];
Expand Down

0 comments on commit 4268082

Please sign in to comment.