First of all:
To introduce messageui.framework in frameworks
#import <MessageUI/MessageUI.h>
Add protocol:<mfmessagecomposeviewcontrollerdelegate>
Then look at the code:
There are two types of SMS call, 1 is the call system within the SMS function, you can send a text message back to the app, another call system outside the text messaging function, can not recall the app
Call the SMS function within the system to return to the app
if ([Mfmessagecomposeviewcontroller Cansendtext]) {
Mfmessagecomposeviewcontroller *picker =
[[Mfmessagecomposeviewcontroller alloc] init];
Picker.messagecomposedelegate = self;
Picker.navigationBar.tintColor = [Uicolor blackcolor];
Default recipients (can be multiple)
picker.recipients = [Nsarray arraywithobject:@ "", @ ""];
Picker.body = @ "AAAAAAAAAA";
[Self Presentviewcontroller:picker
Animated:yes
completion:^{
}];
}else{
Call the SMS function outside the system, can not return to the app
[[UIApplication Sharedapplication]openurl:[nsurl urlwithstring:[nsstring stringwithformat:@ "sms://%@", Mobile]];
}
}
#pragma mark-mfmessagecomposeviewcontrollerdelegate
-(void) Messagecomposeviewcontroller: (Mfmessagecomposeviewcontroller *) controller didfinishwithresult: ( Messagecomposeresult) Result
{
Switch (Result) {
Case messagecomposeresultcancelled:
ShowMsg (@ "send Cancel");
Break
Case Messagecomposeresultsent:
ShowMsg (@ "send success");
Break
Case messagecomposeresultfailed:
ShowMsg (@ "send failed");
Break
Default
Break
}
[Controller Dismissviewcontrolleranimated:no completion:^{
}];
}
Large arc function
nsstring* DeviceType = [Uidevice currentdevice].model;
return [DeviceType isequaltostring:@ "IPhone"];
if (![ Method isphonesupported]) {
ShowMsg (@ "Current device does not support phone calls");
return NO;
}
Nsurl *telurl =[nsurl urlwithstring:[nsstring stringwithformat:@ "tel://%@", Num]];
[[UIApplication sharedapplication] openurl:telurl];
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
iOS call, text messaging feature