diff --git a/Classes/SendGrid.m b/Classes/SendGrid.m index e581495..f010796 100755 --- a/Classes/SendGrid.m +++ b/Classes/SendGrid.m @@ -67,12 +67,23 @@ - (void)sendWithWeb:(SendGridEmail *)email successBlock:(void(^)(id responseObje { for (int i = 0; i < email.imgs.count; i++) { - UIImage *img = [email.imgs objectAtIndex:i]; + #if TARGET_IPHONE_OS + UIImage *img = [email.imgs objectAtIndex:i]; + #else + NSImage *img = [email.imgs objectAtIndex:i]; + #endif NSString *filename = [NSString stringWithFormat:@"image%d.png", i]; NSString *name = [NSString stringWithFormat:@"files[image%d.png]", i]; NSLog(@"name: %@, Filename: %@", name, filename); - NSData *imageData = UIImagePNGRepresentation(img); - [formData appendPartWithFileData:imageData name:name fileName:filename mimeType:@"image/png"]; + #if TARGET_IPHONE_OS + NSData *imageData = UIImagePNGRepresentation(img); + NSString *mimeType = @"image/png"; + #else + // TODO: Find UIImagePNGRepresentation for NSImage. TIFF probably huge + NSData *imageData = [img TIFFRepresentation]; + NSString *mimeType = @"image/tiff"; + #endif + [formData appendPartWithFileData:imageData name:name fileName:filename mimeType:mimeType]; } } success:^(AFHTTPRequestOperation *operation, id responseObject) diff --git a/Classes/SendGridEmail.h b/Classes/SendGridEmail.h index d38eb53..74a41bf 100644 --- a/Classes/SendGridEmail.h +++ b/Classes/SendGridEmail.h @@ -7,7 +7,6 @@ // #import -#import #import "SMTPAPI.h" #import "SendGridEmailAttachment.h" @@ -40,7 +39,11 @@ - (SendGridEmail *)addFilter:(NSString *)filterName parameterName:(NSString *)parameterName parameterValue:(NSString *)parameterValue; - (SendGridEmail *)addFilter:(NSString *)filterName parameterName:(NSString *)parameterName parameterIntValue:(int)parameterIntValue; +#if TARGET_IPHONE_OS - (void)attachImage:(UIImage *)img; +#else +- (void)attachImage:(NSImage *)img; +#endif - (void)attachFile:(SendGridEmailAttachment *)attachment; - (NSDictionary *)parametersDictionary:(NSString *)apiUser apiKey:(NSString *)apiKey; diff --git a/Classes/SendGridEmail.m b/Classes/SendGridEmail.m index a8b603a..4f1db6d 100644 --- a/Classes/SendGridEmail.m +++ b/Classes/SendGridEmail.m @@ -68,10 +68,15 @@ - (SendGridEmail *)addFilter:(NSString *)filterName parameterName:(NSString *)pa return self; } -- (void)attachImage:(UIImage *)img +#if TARGET_IPHONE_OS +- (void)attachImage:(UIImage *)img; +#else +- (void)attachImage:(NSImage *)img; +#endif { - if (self.imgs == NULL) - self.imgs = [[NSMutableArray alloc] init]; + if (self.imgs == NULL) { + self.imgs = [NSMutableArray new]; + } [self.imgs addObject:img]; } @@ -82,15 +87,14 @@ - (void)attachFile:(SendGridEmailAttachment *)attachment [self.attachments addObject:attachment]; } -- (NSDictionary *)parametersDictionary:(NSString *)apiUser apiKey:(NSString *)apiKey +- (NSDictionary *)parametersDictionary:(nonnull NSString *)apiUser apiKey:(nonnull NSString *)apiKey { [self.smtpapi configureHeader]; self.xsmtpapi = [self.smtpapi encodedHeader]; NSLog(@"%@", self.xsmtpapi); - if (self.html != nil && self.text == nil) - self.text = self.html; - + self.text = (self.html != nil && self.text == nil) ? self.html : @""; + //must set the "to" parameter even if X-SMTPAPI tos array is set if ([self.smtpapi getTos] != nil && [[self.smtpapi getTos] count] > 0 && self.to == nil) [self setTo:[[self.smtpapi getTos] objectAtIndex:0]];