ViewController Demo Created by Kunal Batra on 10 31 13 Copyright 2013

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
//
// ViewController.m
// Demo
//
// Created by Kunal Batra on 10/31/13.
// Copyright (c) 2013 SendGrid. All rights reserved.
//
#import "ViewController.h"
#import <SendGrid/SendGrid.h>
#import <SendGrid/SendGridEmail.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)attachPhoto:(id)sender
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)sendEmail:(id)sender
{
#warning Don't forget to change the apiUser and apiKey values
SendGrid *sendgrid = [SendGrid apiUser:@"YOUR_USERNAME" apiKey:@"YOUR_PASSWORD"];
SendGridEmail *email = [[SendGridEmail alloc] init];
email.to = @"foo@bar.com";
email.from = @"bar@foo.com";
email.subject = @"testing format";
email.html = @"<h1>hello world</h1>";
email.text = @"hello world";
//Uncomment this part to send an email with an inline image, category,
//unique argument and substitution
/*
UIImage *sendgridLogo = [UIImage imageNamed:@"sendgrid_logo.png"];
[email attachImage:sendgridLogo];
email.inlinePhoto = true;
email.html = @"<h1>hello world</h1><img src=\"cid:image0.png\">";
[email.smtpapi addSubstitution:@"-name-" val:@"Awesome Person"];
[email.smtpapi addUniqueArg:@"uid" val:@"12345"];
[email.smtpapi addCategory:@"welcome_email"];
//Image attachment
if (self.imgs != NULL) {
for (UIImage *img in self.imgs){
[email attachImage:img];
}
}
*/
//this is an example of sending an image as a general attachment
//you can send other types of files as well
/*
UIImage *sendgridLogo = [UIImage imageNamed:@"sendgrid_logo.png"];
SendGridEmailAttachment* someImageAttachment = [[SendGridEmailAttachment alloc] init];
someImageAttachment.attachmentData = UIImagePNGRepresentation(sendgridLogo);
someImageAttachment.mimeType = @"image/png";
someImageAttachment.fileName = @"sendgrid_logo";
someImageAttachment.extension = @"png";
[email attachFile:someImageAttachment];
[sendgrid sendAttachmentWithWeb:email];
*/
[sendgrid sendWithWeb:email];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
NSLog(@"Image Name: %@",info[UIImagePickerControllerMediaURL]);
if (self.imgs == NULL)
self.imgs = [[NSMutableArray alloc] init];
[picker dismissViewControllerAnimated:YES completion:NULL];
[self.imgs addObject:chosenImage];
self.preview.image = chosenImage;
}
@end