iOS-打电话、发短信、发邮件【指定QQ用户发送QQ消息】_移动开发_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > 移动开发 > iOS-打电话、发短信、发邮件【指定QQ用户发送QQ消息】

iOS-打电话、发短信、发邮件【指定QQ用户发送QQ消息】

 2017/11/16 13:18:08  小圭哥  程序员俱乐部  我要评论(0)
  • 摘要:1.发短信头文件#import<MessageUI/MessageUI.h>头部代理@interfaceViewController()<MFMessageComposeViewControllerDelegate>发送信息-(void)senderMessage{if([MFMessageComposeViewControllercanSendText])
  • 标签: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]];
}

 

发表评论
用户名: 匿名