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 



原文地址:https://www.cnblogs.com/greywolf/p/2615310.html