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操作

  • 相关阅读:
    Eclipse上改动Jython代码的Comment颜色
    StaggeredGridView+universal-image-loader载入网路图片实现瀑布流
    HDU 1890 Robotic Sort
    overload和override
    FileStream大文件复制
    [Asp.Net]状态管理(Session、Application、Cache)
    c#简单自定义异常处理日志辅助类
    Socket网络编程(3)--两端通信
    [Asp.Net]状态管理(ViewState、Cookie)
    Socket网络编程(2)--服务端实现
  • 原文地址:https://www.cnblogs.com/jinlianglu/p/6399533.html
Copyright © 2011-2022 走看看