標籤:
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 調用系統發簡訊以及打電話功能