年年有"余"

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1873|回复: 0

IOS 开发,调用系统功能打电话,发短信,群发短信,打开网址,发邮件等自带功能

[复制链接]
  • TA的每日心情
    奋斗
    2022-12-13 21:26
  • 签到天数: 371 天

    [LV.9]以坛为家II

    发表于 2014-9-22 09:39:06 | 显示全部楼层 |阅读模式
    1、调用 自带mail
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://[email protected]"]];

    2、调用 电话phone
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://8008808888"]];

    3、调用 SMS
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://800888"]];

    4、调用自带 浏览器 safari
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.hzlzh.com"]];

    调用phone可以传递号码,调用SMS 只能设定号码,不能初始化SMS内容。

    若需要传递内容或群发可以做如下操作:
    加入:MessageUI.framework

    #import <MessageUI/MFMessageComposeViewController.h>

    实现代理:MFMessageComposeViewControllerDelegate
    调用sendSMS函数
    //内容,收件人列表
    1. - (void)sendSMS:(NSString *)bodyOfMessage recipientList:(NSArray *)recipients
    2. {
    3.    
    4.     MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
    5.    
    6.     if([MFMessageComposeViewController canSendText]){
    7.         
    8.         controller.body = bodyOfMessage;
    9.         
    10.         controller.recipients = recipients;
    11.         
    12.         controller.messageComposeDelegate = self;
    13.         
    14.         [self presentViewController:controller animated:YES completion:nil];
    15.         
    16.     }   
    17.    
    18. }
    复制代码
    // 处理发送完的响应结果
    1. - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
    2. {
    3.   [self dismissModalViewControllerAnimated:YES];
    4.   if (result == MessageComposeResultCancelled)
    5.     NSLog(@"Message cancelled")
    6.   else if (result == MessageComposeResultSent)
    7.     NSLog(@"Message sent")  
    8.   else
    9.     NSLog(@"Message failed")  
    10. }
    复制代码
    发送邮件的为:
    导入#import <MessageUI/MFMailComposeViewController.h>
    实现代理:MFMailComposeViewControllerDelegate

    //发送邮件
    1. -(void)sendMail:(NSString *)subject content:(NSString *)content{
    2.     MFMailComposeViewController *controller = [[[MFMailComposeViewController alloc] init] autorelease];
    3.     if([MFMailComposeViewController canSendMail])
    4.     {
    5.         [controller setSubject:subject];
    6.         [controller setMessageBody:content isHTML:NO];
    7.         controller.mailComposeDelegate = self;
    8.         [self presentModalViewController:controller animated:YES  completion:nil];
    9.     }   
    10. }
    复制代码
    //邮件完成处理
    1. -(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{
    2.     [self dismissModalViewControllerAnimated:YES completion:nil];
    3.     if (result == MessageComposeResultCancelled)
    4.         NSLog(@"Message cancelled");
    5.     else if (result == MessageComposeResultSent)
    6.         NSLog(@"Message sent");
    7.     else
    8.         NSLog(@"Message failed");  
    9. }
    复制代码
    默认发送短信的界面为英文的,解决办法为:
    在.xib 中的Localization添加一组chinese就ok了

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    手机版|小黑屋|Archiver|iOS开发笔记 ( 湘ICP备14010846号 )

    GMT+8, 2024-4-29 21:33 , Processed in 0.046950 second(s), 22 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表