zoukankan      html  css  js  c++  java
  • 发送短信/邮件/打电话的代码

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

    + (NSString*) cleanPhoneNumber:(NSString*)phoneNumber
    {
        NSString* number = [NSString stringWithString:phoneNumber];
        NSString* number1 = [[[number stringByReplacingOccurrencesOfString:@" " withString:@""]
                              //                        stringByReplacingOccurrencesOfString:@"-" withString:@""]
                              stringByReplacingOccurrencesOfString:@"(" withString:@""]
                             stringByReplacingOccurrencesOfString:@")" withString:@""];
       
        return number1;   
    }

    + (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]];
       
    }

    也可以下载第三方  按照SDK操作

  • 相关阅读:
    leetcode题库
    递归的存储以及执行顺序
    linux与开发板串口通信
    opencv基础到进阶(2)
    opencv基础到进阶(1)
    js的搜索遍历精讲
    js闭包深度讲解
    js使用for in遍历时的细节问题
    分分钟解决正则表达式
    css3中的新特性经典应用
  • 原文地址:https://www.cnblogs.com/jinlianglu/p/6399533.html
Copyright © 2011-2022 走看看