撥號功能有三種方法: 1.第一種:會彈出呼叫提示,撥打完電話后無法回到原來的應用,會停留在通訊錄里
NSString* str=[@"tel:10086"];[[UIapplication sharedApplication] openURL:[NSURL URLWithString:str]];2.第二種:會彈出呼叫提示,撥打完電話后會回到原來的應用,但是是私有API,不合法。
NSString* str=[@"tel3.第三種:撥打電話后還會回到原來的程序,也會彈出提示。NSString* str=@"tel:10086"];UIWebView* callWebview = [[UIWebView alloc] init];[callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];[self.view addSubview:callWebview];PS:在撥打電話過程中可以得到一些本機數(shù)據(jù)(服務商,移動業(yè)務國家代碼,移動網(wǎng)絡代碼,所在國家,是否允許網(wǎng)絡電話)。
CTTelephonyNetworkInfo *info = [[CTTelephonyNetworkInfo alloc] init];CTCarrier *carrier = info.subscriberCellularProvider;NSLog(@"carrier:%@", [carrier description]);短信功能有兩種方法: 1.第一種
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"sms://10086"]];2.第二種 首先需要加入頭文件
#import <MessageUI/MessageUI.h>使用MessageUI 框架發(fā)送短信
-(void)sendMessage { //用于判斷是否有發(fā)送短信的功能(模擬器上就沒有短信功能) Class messageClass = (NSClassFromString(@"MFMessageComposeViewController")); //判斷是否有短信功能 if (messageClass != nil) { MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init]; messageController.messageComposeDelegate = self; //拼接并設置短信內容 NSString *messageContent = [NSString stringWithFormat:@"蛤蛤蛤蛤蛤蛤"]; messageController.body = messageContent; //設置發(fā)送給誰 messageController.recipients = @[@"10086"]; //推到發(fā)送視圖控制器 [self presentViewController:messageController animated:YES completion:^{ }]; } else { UIAlertController* alertView = [UIAlertController alertControllerWithTitle:@"提示" message:@"iOS版本過低" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {}]; [alertView addAction:cancelAction]; [self presentViewController:alertView animated:YES completion:nil]; }}實現(xiàn)代理函數(shù)
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result { switch (result) { case MessageComposeResultCancelled: NSLog(@"返回APP界面") ; break; case MessageComposeResultFailed: NSLog(@"發(fā)送失敗") ; break; case MessageComposeResultSent: NSLog(@"發(fā)送成功") ; break; default: break; } //最后解除短息發(fā)送界面,返回原app [self dismissViewControllerAnimated:YES completion:NULL];}最后設置一個按鈕,點擊即發(fā)送固定短信給固定號碼
- (IBAction)sendMegAction:(UIButton *)sender { [self sendMessage];}Github:https://github.com/NowOrNeverDG/DialingAndSendMeg
新聞熱點
疑難解答
圖片精選