zoukankan      html  css  js  c++  java
  • iPhone调用发短信,电话,邮件的方法

    + (void)alert:(NSString *)msg
    {
        UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:msg message:@"" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] autorelease];
        [alertView showWithBackground];
    }

    + (void) makeCall:(NSString *)phoneNumber
    {
        if ([DeviceDetection isIPodTouch]){
            [UIUtils alert:kCallNotSupportOnIPod];
            return;
        }
        
        NSString* numberAfterClear = [UIUtils cleanPhoneNumber:phoneNumber];    
        
        NSURL *phoneNumberURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", numberAfterClear]];
        //NSURL *phoneNumberURL = [NSURL URLWithString:[NSString stringWithFormat:@"atel:%@", numberAfterClear]];
        NSLog(@"make call, URL=%@", phoneNumberURL);
        
        [[UIApplication sharedApplication] openURL:phoneNumberURL];    
    }

    + (void) sendSms:(NSString *)phoneNumber
    {
        if ([DeviceDetection isIPodTouch]){
            [UIUtils alert:kSmsNotSupportOnIPod];
            return;
        }
        
        NSString* numberAfterClear = [UIUtils cleanPhoneNumber:phoneNumber];
        
        NSURL *phoneNumberURL = [NSURL URLWithString:[NSString stringWithFormat:@"sms:%@", numberAfterClear]];
        NSLog(@"send sms, URL=%@", phoneNumberURL);
        [[UIApplication sharedApplication] openURL:phoneNumberURL];    
    }

    + (void) sendEmail:(NSString *)phoneNumber
    {
        NSURL *phoneNumberURL = [NSURL URLWithString:[NSString stringWithFormat:@"mailto:%@", phoneNumber]];
        NSLog(@"send sms, URL=%@", phoneNumberURL);
        [[UIApplication sharedApplication] openURL:phoneNumberURL];    
    }

    + (void) sendEmail:(NSString *)to cc:(NSString*)cc subject:(NSString*)subject body:(NSString*)body
    {
        NSString* str = [NSString stringWithFormat:@"mailto:%@?cc=%@&subject=%@&body=%@",
                         to, cc, subject, body];

        str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
        

    }  

    当然,除了这几种办法之外,也可以使用MFXXXViewController等在应用程序内部调用发短信和发邮件。

     

    iPhone包含一些其他除了http://或者mailto:之外的URL:

    sms:// 可以调用短信程序

    tel:// 可以拨打电话

    itms:// 可以打开MobileStore.app

    audio-player-event:// 可以打开iPod

    audio-player-event://?uicmd=show-purchased-playlist 可以打开iPod播放列表

    video-player-event:// 可以打开iPod中的视频


     InAppSMS.zip (22 K) 下载次数:1763 



    参考:

    http://blog.csdn.net/realtool/article/details/7054784

    http://www.cocoachina.com/iphonedev/sdk/2009/0611/242.html

    http://www.cocoachina.com/bbs/read.php?tid-23149.html



     InAppSMS.zip (22 K) 下载次数:1763 



  • 相关阅读:
    读取csv遇到的双循环
    hadoop环境配置
    mysql的查询
    mysql的基本操作
    mysql与python的交互
    设置自动获取IP和DNS
    pyecharts绘制地图
    集合 set方法
    字符串 string方法
    字典 dict方法
  • 原文地址:https://www.cnblogs.com/greywolf/p/2615310.html
Copyright © 2011-2022 走看看