iOS 打电话,发短信,复制

来源:互联网 发布:淘宝二手手机靠谱么 编辑:程序博客网 时间:2024/05/18 02:31

一、打电话

1、打电话会先弹出提示框,询问你是否打电话,结束通话后会返回到程序中

    if (_webView ==nil){

        _webView = [[UIWebViewalloc]initWithFrame:CGRectZero];

    }

    [_webViewloadRequest:[NSURLRequestrequestWithURL:[NSURLURLWithString:@"tel://10086"]]];


2、直接跳转到打电话界面

NSURL *url = [NSURLURLWithString:@"tel://10086"];

    [[UIApplicationsharedApplication]openURL:url];

3、打电话会先弹出提示框,询问你是否打电话,结束通话后会返回到程序中

NSURL *url = [NSURLURLWithString:@"telprompt://10010"];

    [[UIApplicationsharedApplication]openURL:url];


二、发送短信,

MFMessageComposeViewController *controller = [[MFMessageComposeViewControlleralloc]init];

    if([MFMessageComposeViewControllercanSendText])//判断当前设备是否可以发送短信息

    {

        controller.body =@"你好";//短信内容

        controller.recipients =@[@"123"];//短信接收者,可设置多个

        controller.messageComposeDelegate =self;

        [selfpresentViewController:controlleranimated:YEScompletion:nil];

        

    }else{

        UIAlertView * aler = [[UIAlertViewalloc]initWithTitle:@""message:@"设备不具备发短信功能"delegate:nilcancelButtonTitle:@"确定"otherButtonTitles:nil];

        [alershow];

    }

#pragma mark - MFMessageComposeViewControllerDelegate  //处理发送完的响应结果


(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result

{

    [selfdismissViewControllerAnimated:YEScompletion:nil];

    

    NSString * str ;

    if (result ==MessageComposeResultCancelled)

    {

        str =@"取消发送短信!";

    }

    elseif (result ==MessageComposeResultSent)

    {

        str =@"发送短信成功!";

        UIAlertView * aler = [[UIAlertViewalloc]initWithTitle:nilmessage:strdelegate:nilcancelButtonTitle:@"确定"otherButtonTitles:nil];

        [alershow];

    }

    else

    {

        str =@"短信发送失败!";

    }

}

三、复制

NSString *str =@"123456";

    UIPasteboard *pastboard = [UIPasteboardgeneralPasteboard];

    pastboard.string = str;

0 0
原创粉丝点击