iOS打电话、发短信、发邮件实例代码
程序员文章站
2023-12-17 21:03:04
本文实例为大家分享了ios打电话、发短信、发邮件,指定qq用户发送qq消息的具体代码,供大家参考,具体内容如下
1.发短信
头文件
#import
本文实例为大家分享了ios打电话、发短信、发邮件,指定qq用户发送qq消息的具体代码,供大家参考,具体内容如下
1.发短信
头文件
#import <messageui/messageui.h>
头部代理
@interface viewcontroller ()<mfmessagecomposeviewcontrollerdelegate>
发送信息
- (void)sendermessage{ if([mfmessagecomposeviewcontroller cansendtext]) { ///短信实例化 mfmessagecomposeviewcontroller * messagevc = [[mfmessagecomposeviewcontroller alloc] init]; ///目标号码,可以多个 messagevc.recipients = @[@"18888888888",@"15555555555"]; messagevc.navigationbar.tintcolor = [uicolor redcolor]; messagevc.body = @"发送的内容-发送的内容-发送的内容"; messagevc.messagecomposedelegate = self; [self presentviewcontroller:messagevc animated:yes completion:nil]; [[[[messagevc viewcontrollers] lastobject] navigationitem] settitle:@"title"]; } else { nslog(@"当前设备不支持短信功能"); } }
代理方法实现
-(void)messagecomposeviewcontroller:(mfmessagecomposeviewcontroller *)controller didfinishwithresult:(messagecomposeresult)result { ///dismiss mfmessagecomposeviewcontroller [controller dismissviewcontrolleranimated:yes completion:nil]; if (result == messagecomposeresultsent) { nslog(@"信息发送成功!"); } else if (result == messagecomposeresultfailed){ nslog(@"信息发送失败!"); } else if (result == messagecomposeresultcancelled){ nslog(@"点击了取消"); } else{ } }
2.拨打电话
- (void)dialphone{ ///该方法直接拨打,不会弹出呼叫(取消) [[uiapplication sharedapplication]openurl:[nsurl urlwithstring:@"tel://18888888888"]]; ///该方法会弹出是否取消呼叫 uiwebview*callwebview =[[uiwebview alloc] init]; nsurl *telurl =[nsurl urlwithstring:@"tel:18888888888"]; [callwebview loadrequest:[nsurlrequest requestwithurl:telurl]]; [self.view addsubview:callwebview]; }
3.发送邮件
- (void)senderemail{ nsstring *urlstr =@"mailto:xxxxxxxx@xxxx.com?subject=邮件主题(此参数可不传)&body=邮件内容(此参数可不传)"; nsurl *url = [nsurl urlwithstring:urlstr] ; [[uiapplication sharedapplication] openurl:url]; }
4.发送qq消息
- (void)senderqq{ ///111111111111为qq号码 nsstring *url = @"mqq://im/chat?chat_type=wpa&uin=111111111111&version=1&src_type=web"; [[uiapplication sharedapplication] openurl:[nsurl urlwithstring:url]]; }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。