您的位置:首页 > 编程语言

打电话、发短信、发邮件常用代码

2015-07-06 14:48 302 查看


打电话、发短信、发邮件常用代码

+ (void) makeCall:(NSString *)phoneNumber
{
    if ([DeviceDetection isIPodTouch]){
        [UIUtils alert:kCallNotSupportOnIPod];
        return;
    }
    
    NSString* numberAfterClear = [UIUtils cleanPhoneNumber:phoneNumber];    
    
    NSURL *phoneNumberURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", 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]];
    
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: