iOS basic texting and calling calls

Source: Internet
Author: User

Phone, SMS is the basic function of the phone, iOS provides the interface, let us call. This article simply describes how iOS calls and text messages are called in the program.

1. Call

[CPP]View PlainCopyprint?
    1. [[UIApplication sharedapplication] openurl:[nsurl urlwithstring:@"tel://10010"]];//call

Use OpenURL this API call end, return is the system to call the interface, how to return to their own application? There are two ways to share with you.

The first is to load the phone with UIWebView, which is legal and can be used on the App store.

The code is as follows:

[CPP]View PlainCopyprint?
    1. Uiwebview*callwebview =[[uiwebview alloc] init];
    2. Nsurl *telurl =[nsurl urlwithstring:@"tel:10010"];
    3. [Callwebview loadrequest:[nsurlrequest Requestwithurl:telurl];
    4. Remember to add to the view
    5. [Self.view Addsubview:callwebview];



The second is a private method, not on the App Store (you haven't tried it).

[CPP]View PlainCopyprint?
    1. [[UIApplication sharedapplication] openurl:[nsurl urlwithstring:@"telprompt://10010"];

The above code just puts the first method of Tel as telprompt.

2. Send SMS

There are two ways to send text messages in iOS, the simplest of which is to use OpenURL:

[CPP]View PlainCopyprint?
    1. [[UIApplication Sharedapplication]openurl:[nsurl urlwithstring:@"sms://10010"]];// texting

The above method can not specify the text message content, iOS4.0 New added Mfmessagecomposeviewcontroller and mfmessagecomposeviewcontrollerdelegate, provide the interface to send SMS, You can send text messages as you do without jumping out of the program. Description can be found in message uiframework Reference

Mfmessagecomposeviewcontroller provides the operation interface must be checked before using the Cansendtext method, if the return of no should not show the controller, but should be prompted to not support the sending of SMS.

Messagecomposedelegate: agent, processing send results

Recipients: Recipient < list, support group >

Body: SMS Content

To introduce messageui.framework in frameworks

#import <MessageUI/MessageUI.h>
Add Protocol:<mfmessagecomposeviewcontrollerdelegate>

[CPP]View PlainCopyprint?
    1. #import <MessageUI/MessageUI.h>
    2. @interface Demoviewcontroller:uiviewcontroller <MFMessageComposeViewControllerDelegate>
    3. @end


Call Mfmessagecomposeviewcontroller, and implement protocol mfmessagecomposeviewcontrollerdelegate.

[CPP]View PlainCopyprint?
  1. -(void) Showmessageview
  2. {
  3. if ([Mfmessagecomposeviewcontroller Cansendtext]) {
  4. Mfmessagecomposeviewcontroller * Controller = [[Mfmessagecomposeviewcontroller alloc]init];  //autorelease];
  5. controller.recipients = [Nsarray arraywithobject:@"10010"];
  6. Controller.body = @"Test texting";
  7. Controller.messagecomposedelegate = self;
  8. [Self Presentmodalviewcontroller:controller animated:yes];
  9. [[[Controller viewcontrollers] lastobject] navigationitem] settitle:@"Test SMS"]; //Modify SMS interface title
  10. }else{
  11. [Self alertwithtitle:@"message" msg:@ "device does not have SMS function"];
  12. }
  13. }
  14. Mfmessagecomposeviewcontrollerdelegate
  15. -(void) Messagecomposeviewcontroller: (Mfmessagecomposeviewcontroller *) controller didfinishwithresult: ( Messagecomposeresult) result{
  16. [Controller Dismissmodalviewcontrolleranimated:no]; //The key sentence cannot be Yes
  17. switch (result) {
  18. Case messagecomposeresultcancelled:
  19. [Self alertwithtitle:@"message" msg:@ "send Cancel"];
  20. Break ;
  21. Case messagecomposeresultfailed://Send failed
  22. [Self alertwithtitle:@"prompt message" msg:@"send Success"];
  23. Break ;
  24. Case Messagecomposeresultsent:
  25. [Self alertwithtitle:@"message" msg:@ "send Failed"];
  26. Break ;
  27. Default:
  28. Break ;
  29. }
  30. }
  31. -(void) Alertwithtitle: (NSString *) title msg: (NSString *) msg {
  32. Uialertview *alert = [[Uialertview alloc] Initwithtitle:title
  33. Message:msg
  34. Delegate:self
  35. Cancelbuttontitle:nil
  36. otherbuttontitles:@"OK", nil];
  37. [Alert show];
  38. }



Send an email for reference

/*** @author Zhang Xingye * http://blog.csdn.net/xyz_lmn* iOS starter Group: 83702688* Android Development Advanced Group: 241395671* my Sina Weibo:@ Zhang Xingye tbow*/


Reference:

http://developer.apple.com/library/ios/#documentation/messageui/reference/mfmessagecomposeviewcontroller_class /reference/reference.html

iOS basic texting and calling

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.