IOS問題匯總:2015-1-9 iOS 調用系統發簡訊以及打電話功能

來源:互聯網
上載者:User

標籤:

iOS 調用系統發簡訊以及打電話功能

ios電話smsinterface互連網class
先介紹一種最簡單的方法:

調用打電話功能

[[UIApplicationsharedApplication] openURL:[NSURL URLWithString:@“tel://10086”]];

調用發簡訊功能

[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@“sms://10000”]];

上面的發簡訊的功能是調用系統的介面,下面是實現一種點擊按鍵就直接傳送簡訊,相當於後台發送,能不能上軟體商店,還不能確定。相對建議來說,盡量使用第一種。

首先匯入MFMessageComposeViewControllerDelegate這個代理,實現裡面的方法

-(void)messageComposeViewController:(MFMessageComposeViewController *)controllerdidFinishWithResult:(MessageComposeResult)result {

  //Notifies users about errors associated with the interface  switch (result) {     case MessageComposeResultCancelled:        if (DEBUG) NSLog(@"Result: canceled");        break;     case MessageComposeResultSent:        if (DEBUG) NSLog(@"Result: Sent");        break;     case MessageComposeResultFailed:        if (DEBUG) NSLog(@"Result: Failed");        break;     default:        break;  }  [self dismissModalViewControllerAnimated:YES]; 

}

群發簡訊:

-(IBAction)sendSMS {

BOOL canSendSMS = [MFMessageComposeViewController canSendText];

NSLog(@“can send SMS [%d]”,canSendSMS);

if (canSendSMS) {

 MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init]; picker.messageComposeDelegate = self; picker.navigationBar.tintColor = [UIColor blackColor]; picker.body = @"test"; picker.recipients = [NSArray arrayWithObject:@"10086"]; [self presentModalViewController:picker animated:YES]; [picker release];   

}

}

給一個人發簡訊:
從網頁上獲得內容

-(void)displaySMSComposerSheet

{

MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];picker.messageComposeDelegate = self;UIWebView *web = nil;NSMutableString* absUrl = [[NSMutableString alloc] initWithString:web.request.URL.absoluteString];[absUrl replaceOccurrencesOfString:@"http://i.aizheke.com" withString:@"http://m.aizheke.com" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [absUrl length])];picker.body=[NSString stringWithFormat:@"我在愛折客上看到:%@ 可能對你有用,推薦給你!link:%@",[webstringByEvaluatingJavaScriptFromString:@"document.title"],absUrl];

[absUrl release];

[self presentModalViewController:picker animated:YES];

[picker release];

}

事件綁定傳送簡訊

-(IBAction)showSMSPicker:(id)sender {

Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));if (messageClass != nil) {    if ([messageClass canSendText]) {        [self displaySMSComposerSheet];    }    else {

//裝置沒有簡訊功能

   }}else {

// iOS版本過低,iOS4.0以上才支援程式內傳送簡訊

}

}

IOS問題匯總:2015-1-9 iOS 調用系統發簡訊以及打電話功能

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.