iOS 打電話 發簡訊(轉載)

來源:互聯網
上載者:User

標籤:class   ext   color   int   c   string   

官方代碼

發短息和郵件添加MessageUI.framework 庫

 

發送資訊

- (IBAction)showSMSPicker:(id)sender

{

    // You must check that the current device can send SMS messages before you

    // attempt to create an instance of MFMessageComposeViewController.  If the

    // device can not send SMS messages,

    // [[MFMessageComposeViewController alloc] init] will return nil.  Your app

    // will crash when it calls -presentViewController:animated:completion: with

    // a nil view controller.

    if ([MFMessageComposeViewControllercanSendText])

    // The device can send email.

    {

        [selfdisplaySMSComposerSheet];

    }

    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!";

    

    [selfpresentViewController:picker 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)

{

caseMessageComposeResultCancelled:

self.feedbackMsg.text = @"Result: SMS sending canceled";

break;

caseMessageComposeResultSent:

self.feedbackMsg.text = @"Result: SMS sent";

break;

caseMessageComposeResultFailed:

self.feedbackMsg.text = @"Result: SMS sending failed";

break;

default:

self.feedbackMsg.text = @"Result: SMS not sent";

break;

}

    

[selfdismissViewControllerAnimated:YEScompletion:NULL];

}

 

發送郵件

 

- (IBAction)showMailPicker:(id)sender

{

    // You must check that the current device can send email messages before you

    // attempt to create an instance of MFMailComposeViewController.  If the

    // device can not send email messages,

    // [[MFMailComposeViewController alloc] init] will return nil.  Your app

    // will crash when it calls -presentViewController:animated:completion: with

    // a nil view controller.

    if ([MFMailComposeViewControllercanSendMail])

    // The device can send email.

    {

        [selfdisplayMailComposerSheet];

    }

    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:path];

[picker addAttachmentData:myData mimeType:@"image/jpeg"fileName:@"rainy"];

 

 

// Fill out the email body text

 

 

NSString *emailBody =@"It is raining in sunny California!";

[picker setMessageBody:emailBody isHTML:NO];

 

[selfpresentViewController:picker 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)

{

caseMFMailComposeResultCancelled:

self.feedbackMsg.text = @"Result: Mail sending canceled";

break;

caseMFMailComposeResultSaved:

self.feedbackMsg.text = @"Result: Mail saved";

break;

caseMFMailComposeResultSent:

self.feedbackMsg.text = @"Result: Mail sent";

break;

caseMFMailComposeResultFailed:

self.feedbackMsg.text = @"Result: Mail sending failed";

break;

default:

self.feedbackMsg.text = @"Result: Mail not sent";

break;

}

    

[selfdismissViewControllerAnimated:YEScompletion:NULL];

}

 

打電話 我唯寫了一種簡單的方式 還有其他的

添加  AddressBookUI.framework 庫

 

#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];//電話號碼

    

    NSURL *phoneURL = [NSURLURLWithString:[NSString stringWithFormat:@"tel:%@",phoneNum]];

    

    if ( !_phoneCallWebView ) {

        

        _phoneCallWebView = [[UIWebViewalloc] initWithFrame:CGRectZero];

        

    }

    

    [_phoneCallWebViewloadRequest:[NSURLRequest requestWithURL:phoneURL]];

   

}

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.