SMS, phone calls, emails inside the app
In the app development, many times need in the app to implement SMS verification, sharing, and switching calls and other functions, which will be called to the system relative to the functional system;
There are generally two modes in IOS development:
1) in the app to implement SMS and telephone dialing function, will stay in the SMS and phone interface after completion
2) in the app to achieve text messaging and telephone calls, after completion can jump to the original app interface, to do the next step.
First, send a text message
1) Direct dialing, will stay in the call log when the dial is completed
Method:
Nsurl *url = [Nsurl urlwithstring:@ "sms://10010"
[[UIApplication sharedapplication] openurl:url];
Advantages: Simple
Disadvantage: Cannot specify SMS content, and can not jump back to the original app interface
2) Use Mfmessagecomposeviewcontroller---------(import messageui frame)
Method: ( need to follow SMS Agent----------mfmessagecomposeviewcontrollerdelegate)
//Invite Phone Contact person//determine if the device can send text messages if(![Mfmessagecomposeviewcontroller Cansendtext]) { return; } //initializing the SMS controllerMfmessagecomposeviewcontroller *MESSAGEVC =[[Mfmessagecomposeviewcontroller alloc]init]; //Set Delegate ObjectMessagevc.messagecomposedelegate =Self ; NSString*text = [NSString stringWithFormat:@"[%@] invite you to register IBOs cool office join "%@", click Join http://www.ibos.cn/?corp=%@", Getmyinfo (). Realname, Getmyinfo (). Corpname, Getmyinfo (). Corpcode]; //SMS ContentMessagevc.body = text;//(Note: If the text message contains a post-URL, can be automatically identified, can still send text messages, the recipient can click the trigger link to achieve jump) //set the recipient (can not be set, the SMS interface can jump to the system Address Book, choose the person by themselves)Controller.recipients = [@"10010",@"10086"]; //Display SMS Controller[Self PRESENTVIEWCONTROLLER:MESSAGEVC animated:yes completion:nil];
After the message is sent, call the proxy method to close the SMS interface
:
- (void) Messagecomposeviewcontroller: (Mfmessagecomposeviewcontroller *Controller Didfinishwithresult: (messagecomposeresult) Result {Switch(Result) { CaseMessagecomposeresultcancelled://Cancel { Break; } CaseMessagecomposeresultsent://Send { Break; } CaseMessagecomposeresultfailed://failed{Uialertview*ALERTV = [[Uialertview alloc]initwithtitle:@"Tips"Message@"Send SMS Error, please resend! " Delegate: Self Cancelbuttontitle:nil otherbuttontitles:@"Determine", nil]; [Alertv show]; Break; } default: Break; } //Close the SMS interface[Controller Dismissviewcontrolleranimated:yes Completion:nil];}
Second, call
SMS, phone calls, emails inside the app