Skip to content

Commit

Permalink
#240 shareViaEmail does not accept a base64 image correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVerbruggen committed Dec 1, 2014
1 parent 25ff04f commit 6dbe53c
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/ios/SocialSharing.m
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ - (void)shareViaEmail:(CDVInvokedUrlCommand*)command {
[alert show];
return;
}

self.globalMailComposer.mailComposeDelegate = self;

if ([command.arguments objectAtIndex:0] != (id)[NSNull null]) {
Expand Down Expand Up @@ -263,10 +263,20 @@ - (void)shareViaEmail:(CDVInvokedUrlCommand*)command {
NSURL *file = [self getFile:path];
NSData* data = [fileManager contentsAtPath:file.path];

NSString* fileName;
NSString* mimeType;
NSString* basename = [self getBasenameFromAttachmentPath:path];
NSString* fileName = [basename pathComponents].lastObject;
NSString* mimeType = [self getMimeTypeFromFileExtension:[basename pathExtension]];


if ([basename hasPrefix:@"data:"]) {
mimeType = (NSString*)[[[basename substringFromIndex:5] componentsSeparatedByString: @";"] objectAtIndex:0];
fileName = @"attachment.";
fileName = [fileName stringByAppendingString:(NSString*)[[mimeType componentsSeparatedByString: @"/"] lastObject]];
NSString *base64content = (NSString*)[[basename componentsSeparatedByString: @","] lastObject];
data = [NSData dataFromBase64String:base64content];
} else {
fileName = [basename pathComponents].lastObject;
mimeType = [self getMimeTypeFromFileExtension:[basename pathExtension]];
}
[self.globalMailComposer addAttachmentData:data mimeType:mimeType fileName:fileName];
}
}
Expand Down Expand Up @@ -337,7 +347,7 @@ - (void)shareViaSMS:(CDVInvokedUrlCommand*)command {
NSString *message = [options objectForKey:@"message"];
NSString *subject = [options objectForKey:@"subject"];
NSString *image = [options objectForKey:@"image"];

MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = (id) self;
if (message != (id)[NSNull null]) {
Expand All @@ -355,7 +365,7 @@ - (void)shareViaSMS:(CDVInvokedUrlCommand*)command {
}
}
}

if (phonenumbers != (id)[NSNull null]) {
[picker setRecipients:[phonenumbers componentsSeparatedByString:@","]];
}
Expand Down

0 comments on commit 6dbe53c

Please sign in to comment.