打电话、发短信
来源:互联网 发布:linux 多tomcat配置 编辑:程序博客网 时间:2024/04/30 07:58
We all know that phone and message are the basic function of the cellphone , iOS SDK provide the interface, let us call . Now let's look how to call the interface in the program.
1. ring up
[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"tel://10010"] ; //ring up
After using the API of openURL ,returned is the interface of making calls. If so ,then how did we go back to our program? There are two methods that we share with you.
The first method is uploading phone by UIWebView ,the code as follows:
UIWebView *callWebView=[UIWebView alloc]init];
NSURL *telURL=[NSURL URLWithString:@"tel:10010"];
[callWebView loadRequest:[NSURLRequest requestWithURL:telURL]];
[self.view addSubView:callWebView];
The second method is private ,the code as follows:
[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"tel://10100"];
2. send message
There are two ways to send messages in iOS program , the simplest is using openURL:
[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"sms://10010"] ; //send message
The method above can't specify the content of the message ,such as "hello ,my daring ,Mr Hu", iOS4.0 newly add MFMessageComposeViewController and MFMessageComposeViewControllerDelegate ,which provide the API of send Messages and can send messages like send e-mails ,rather than stand back from a program . The introduction in details ,about which you can know from Message UiFramework Reference .
Determining if Message Composition Is Available
+ canSendText
Accessing the Delegate
messageComposeDelegateproperty
Setting the initial Message Information
recipients property(the receivers)
body property (the content)MFMessageComposeViewController provides operation interface ,which before using you must check the method of CanSendText , if return NO ,you mustn't expro the controller ,but giving a tint telling the user the device can't support the function of sending message.
messageComposeDelegate : agency , dealing with the result of sending messages
recipients: receivers <list ,supporting mass texting>
body : the message content
Importing MessageUI.framework in Framework.
#import<MessageUI/MessageUI.h>
adding protocol : <MFMessageComposeViewControllerDelegate>
- (IBAction)sendMessageAutoBack:(id)sender {
if ([MFMessageComposeViewControllercanSendText]) {
messageVC=[[MFMessageComposeViewControlleralloc]init];
messageVC.recipients=[NSArrayarrayWithObject:@"sms://15806138106"];
messageVC.body=@"阿邱你好帅";
messageVC.messageComposeDelegate=self;
[selfpresentViewController:messageVCanimated:YEScompletion:nil];
[[[[messageVCviewControllers]lastObject]navigationItem]setTitle:@"测试短信"];
}
else {
[selfalertWithTitle:@"提示信息"msg:@"设备没有短信功能"];
}
}
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{
[messageVCdismissViewControllerAnimated:NOcompletion:nil];
switch (result) {
caseMessageComposeResultCancelled:
[selfalertWithTitle:@"提示信息"msg:@"发送取消"];
break;
caseMessageComposeResultSent:
[selfalertWithTitle:@"提示信息"msg:@"发送成功"];
break;
caseMessageComposeResultFailed:
[selfalertWithTitle:@"提示信息"msg:@"发送失败"];
break;
default:
break;
}
}
-(void)alertWithTitle:(NSString *)title msg:(NSString *)msg{
UIAlertView *alert=[[UIAlertViewalloc]initWithTitle:titlemessage:msg delegate:selfcancelButtonTitle:@"确定"otherButtonTitles:nil];
[alertshow];
}
- android打电话,发短信
- android打电话,发短信
- android 打电话 发短信
- android打电话,发短信
- 打电话和发短信
- 打电话和发短信
- android 打电话发短信
- 打电话、发短信
- 打电话、发短信
- Android打电话&发短信
- 打电话、发短信
- android打电话,发短信
- phonegap 打电话发短信
- 打电话发短信
- 打电话 发短信
- 打电话,发短信
- 按键打电话 发短信
- 发短信/邮件/打电话
- 血型统计
- mysql优化
- Android自定义View之实现环形进度条
- 第九周项目6穷举法解决组合问题:(1)百钱买百鸡
- 三毛最美的九句话
- 打电话、发短信
- 做Java项目过程中遇到乱码问题的解决方案
- C#读取Excel表中同一列数据类型不同时,读取到的部分数据为空
- JDK环境变量设置
- <html:checkbox>标签和ActionForm中的reset()
- android 防止Button连续点击而响应多次点击事件
- receiver在manifest中注册和java注册有什么区别
- JQuery:在input中只能输入数字,并且不能复制粘贴,不能切换输入法
- 更新Android5.0