1.
// Homeviewcontroller. h
// Maildemo
# Import <uikit/uikit. h>
# Import <messageui/messageui. h>
@ Interface homeviewcontroller: uiviewcontroller <mfmailcomposeviewcontrollerdelegate>
-(Ibaction) displaycomposersheet;
@ End
2.
//
// Homeviewcontroller. m
// Maildemo
//
# Import "homeviewcontroller. H"
@ Interface homeviewcontroller ()
@ End
@ Implementation homeviewcontroller
-(Ibaction) displaycomposersheet
{
Mfmailcomposeviewcontroller * picker = [[mfmailcomposeviewcontroller alloc] init];
Picker. mailcomposedelegate = self;
[Picker setsubject: @ "hello"];
Nsarray * torecipients = [nsarray arraywithobjects: @ "111@qq.com", nil];
Nsarray * ccrecipients = [nsarray arraywithobjects: @ "222@qq.com", @ "333@qq.com", nil];
Nsarray * bccrecipients = [nsarray arraywithobjects: @ "444@qq.com", nil];
[Picker settorecipients: torecipients];
[Picker setccrecipients: ccrecipients];
[Picker setbccrecipients: bccrecipients];
Nsstring * Path = [[nsbundle mainbundle] pathforresource: @ "mm" oftype: @ "jpg"];
Nsdata * mydata = [nsdata datawithcontentsoffile: path];
[Picker addattachmentdata: mydata mimetype: @ "image/jpg" filename: @ "mm"];
Nsstring * emailbody = @ "Pretty mm ";
[Picker setmessagebody: emailbody ishtml: No];
[Self presentmodalviewcontroller: picker animated: Yes];
[Picker release];
}
-(Void) mailcomposecontroller :( mfmailcomposeviewcontroller *) controller didfinishwithresult :( mfmailcomposeresult) Result error :( nserror *) Error
{
[Self dismissmodalviewcontrolleranimated: Yes];
}
-(Void) viewdidload
{
[Super viewdidload];
// Do any additional setup after loading the view from Its nib.
}
-(Void) viewdidunload
{
[Super viewdidunload];
// Release any retained subviews of the main view.
// E.g. Self. myoutlet = nil;
}
-(Bool) shouldautorotatetointerfaceorientation :( uiinterfaceorientation) interfaceorientation
{
Return (interfaceorientation = uiinterfaceorientationportrait );
}
@ End