IT虾米网

iOS开发之发送短信详解

qq123 2018年06月23日 手机开发 420 0
    //  调用系统API发送短信   
    - (void)didClickSendMessageButtonAction{   
           
        if ([MFMessageComposeViewController canSendText] == YES) {   
               
            MFMessageComposeViewController *messageVC = [[MFMessageComposeViewController alloc] init];   
            //  设置代理<MFMessageComposeViewControllerDelegate>   
            messageVC.messageComposeDelegate = self;   
            //  发送To Who   
            messageVC.recipients = @[@"18757289870"];   
            messageVC.body = @"hello world";   
            [self presentViewController:messageVC animated:YES completion:nil];   
               
        }else{   
           
            NSLog(@"此设备不支持");   
        }   
    }   
       
    - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{   
           
        switch (result) {   
            case MessageComposeResultCancelled:   
                NSLog(@"取消发送");   
                break;   
            case MessageComposeResultFailed:   
                NSLog(@"发送失败");   
                break;   
            case MessageComposeResultSent:   
                NSLog(@"发送成功");   
                break;   
            default:   
                break;   
        }   
           
        [self dismissViewControllerAnimated:YES completion:nil];   
       
    }   
       
    //  调用系统应用程序发送消息   
    - (void)didClickSendMessage2ButtonAction{   
           
        NSURL *url = [NSURL URLWithString:@"sms:18656348970"];   
        if ([[UIApplication sharedApplication] canOpenURL:url] == YES) {   
               
            [[UIApplication sharedApplication] openURL:url];   
               
        }else{   
           
            NSLog(@"失败");   
        }   
       
    }  

发布评论

分享到:

IT虾米网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!

UITextFiedl 左侧设置小图标 leftview详解
你是第一个吃螃蟹的人
发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。