Official code
Send short message and mail add messageui.framework Library
Send Message
-(ibaction) Showsmspicker: (ID) Sender
{
//You must check, the current device can send SMS messages before
//Attempt to create an instance of Mfmessagecomposeviewcontroller. If the
//device can not send SMS messages,
//[[Mfmessagecomposeviewcontroller alloc] init] would return nil. Your app
//would crash when it calls-presentviewcontroller:animated:completion:with
//A nil view controller.
if ([mfmessagecomposeviewcontrollercansendtext])
//The device can send email.
{
[self displaysmscomposersheet];
}
Else
//The device can not send email.
{
Self. feedbackmsg. Hidden =NO;
Self . feedbackmsg . text = @ "Device not configured to send SMS." ;
}
-(void) Displaysmscomposersheet
{
Mfmessagecomposeviewcontroller *picker = [[mfmessagecomposeviewcontrolleralloc] init];
Picker. Messagecomposedelegate =self;
Picker. Navigationbar. Tintcolor = [uicolorblackcolor];
Picker. Recipients = [nsarrayarraywithobject:@ "186888888"];
Picker. Body =@ "Hello from california!" ;
[self presentviewcontroller:p icker animated:YEScompletion: NULL ];
}
// -------------------------------------------------------------------------------
Messagecomposeviewcontroller:didfinishwithresult:
Dismisses the message composition interface when users tap Cancel or Send.
Proceeds to update the feedback message field with the result of the
Operation.
// -------------------------------------------------------------------------------
-(void) Messagecomposeviewcontroller: (mfmessagecomposeviewcontroller *) controller
Didfinishwithresult: (messagecomposeresult) result
{
Self . Feedbackmsg. Hidden = NO ;
Notifies users about errors associated with the interface
Switch (Result)
{
Case messagecomposeresultcancelled:
Self . feedbackmsg . text = @ "result:sms sending canceled";
Break;
Case Messagecomposeresultsent:
Self . feedbackmsg . text = @ "Result:sms sent" ;
Break;
Case messagecomposeresultfailed:
Self . feedbackmsg . text = @ "result:sms sending failed";
Break;
Default:
Self . feedbackmsg . text = @ "Result:sms not sent" ;
Break;
}
[self dismissviewcontrolleranimated:YEScompletion:NULL ];
}
Send mail
-(ibaction) Showmailpicker: (ID) Sender
{
//You must check, the current device can send an email messages before you
//Attempt to create an instance of Mfmailcomposeviewcontroller. If the
//device can not send email messages,
//[[Mfmailcomposeviewcontroller alloc] init] would return nil. Your app
//would crash when it calls-presentviewcontroller:animated:completion:with
//A nil view controller.
if ([mfmailcomposeviewcontrollercansendmail])
//The device can send email.
{
[self displaymailcomposersheet];
}
Else
//The device can not send email.
{
Self. feedbackmsg. Hidden =NO;
Self . feedbackmsg . text =@ "Device not configured to send mail." ;
}
}
#pragma mark-compose mail/sms
// -------------------------------------------------------------------------------
Displaymailcomposersheet
Displays an email composition interface inside the application.
Populates all the Mail fields.
// -------------------------------------------------------------------------------
-(void) Displaymailcomposersheet
{
Mfmailcomposeviewcontroller *picker = [[mfmailcomposeviewcontrolleralloc] init];
Picker. Mailcomposedelegate =self;
[Picker setsubject:@ "Hello from california!" ];
Set Up recipients
Nsarray *torecipients = [nsarrayarraywithobject:@ "[email protected]"];
Nsarray *ccrecipients = [nsarrayarraywithobjects:@ "[Email protected]" ,@ "[email protected]", nil];
Nsarray *bccrecipients = [nsarrayarraywithobject:@ "[email protected]"];
[Picker settorecipients: torecipients];
[Picker setccrecipients: ccrecipients];
[Picker setbccrecipients: bccrecipients];
Attach an image to the email
NSString *path = [[nsbundlemainbundle] pathforresource:@ "Rainy"ofType: @ "jpg"];
NSData *mydata = [nsdatadatawithcontentsoffile:p Ath];
[Picker addattachmentdata: MyData mimeType:@ "image/jpeg"fileName: @ "Rainy" ];
Fill out the email body text
NSString *emailbody =@ "It's Raining in sunny california!" ;
[Picker setmessagebody: Emailbody ishtml:NO];
[self presentviewcontroller:p icker animated:YEScompletion: NULL ];
}
#pragma mark-delegate Methods
// -------------------------------------------------------------------------------
Mailcomposecontroller:didfinishwithresult:
Dismisses the email composition interface when users tap Cancel or Send.
Proceeds to update the message field with the result of the operation.
// -------------------------------------------------------------------------------
-(void) Mailcomposecontroller: (mfmailcomposeviewcontroller*) controller
Didfinishwithresult: (mfmailcomposeresult) result error: (nserror*) error
{
Self . Feedbackmsg. Hidden = NO ;
Notifies users about errors associated with the interface
Switch (Result)
{
Case mfmailcomposeresultcancelled:
Self . feedbackmsg . text = @ "Result:mail sending canceled";
Break;
Case Mfmailcomposeresultsaved:
Self . feedbackmsg . text = @ "Result:mail saved" ;
Break;
Case Mfmailcomposeresultsent:
Self . feedbackmsg . text = @ "Result:mail sent" ;
Break;
Case mfmailcomposeresultfailed:
Self . feedbackmsg . text = @ "Result:mail sending failed";
Break;
Default:
Self . feedbackmsg . text = @ "Result:mail not sent" ;
Break;
}
[self dismissviewcontrolleranimated:YEScompletion: NULL];
}
I only wrote a simple way to make a call.
Add Addressbookui.framework Library
#import <AddressBook/AddressBook.h>
#import <AddressBook/ABMultiValue.h>
#import <AddressBook/ABRecord.h>
-(void) TableView: (uitableview *) TableView Accessorybuttontappedforrowwithindexpath: ( Nsindexpath *) Indexpath
{
nsstring *key = [keyarrayobjectatindex: Indexpath. Row];
nsarray *array = [tabledatadictionaryobjectforkey: key];
nsstring *phonenum = [arrayobjectatindex:1]; // Phone number
nsurl *phoneurl = [nsurlurlwithstring: [nsstring stringwithformat: @ "tel:%@", Phonenum]];
if (! _phonecallwebview ) {
_phonecallwebview = [[uiwebviewalloc] initwithframe:Cgrectzero];
}
[_phonecallwebviewloadrequest: [nsurlrequest requestwithurl: Phoneurl]];
}