1. 程式人生 > >iOS APP調取簡訊 傳送訊息給其他人

iOS APP調取簡訊 傳送訊息給其他人

 if( [MFMessageComposeViewController canSendText]) {
            MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc] init];
            controller.recipients = @[@"10086"];//傳送簡訊的號碼,陣列形式入參
            controller.navigationBar.tintColor = [UIColor redColor];
            controller.body = @"body"; //此處的body就是簡訊將要發生的內容
            controller.messageComposeDelegate = self;
            [self presentViewController:controller animated:YES completion:nil];
            [[[[controller viewControllers] lastObject] navigationItem] setTitle:@"title"];//修改簡訊介面標題
        }
        else {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示資訊"
                                                            message:@"該裝置不支援簡訊功能"
                                                           delegate:nil
                                                  cancelButtonTitle:@"確定"
                                                  otherButtonTitles:nil, nil];
            [alert show];

        }

首先是判斷手機是否支援調取簡訊功能,標頭檔案引入
#import <MessageUI/MessageUI.h>如要獲取傳送狀態,遵守代理MFMessageComposeViewControllerDelegate並實現代理方法

-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result { [self dismissViewControllerAnimated:YES completion:nil]; switch (result) { case MessageComposeResultSent: //資訊傳送成功 break; case MessageComposeResultFailed: //資訊傳送失敗 break; case MessageComposeResultCancelled: //資訊被使用者取消傳送 break; default: break; } } 作者:biubiu15 連結:http://www.jianshu.com/p/1e87a9716266 來源:簡書 著作權歸作者所有。商業轉載請聯絡作者獲得授權,非商業轉載請註明出處。 -(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result { [self dismissViewControllerAnimated:YES completion:nil]; switch (result) { case MessageComposeResultSent: //資訊傳送成功 break; case MessageComposeResultFailed: //資訊傳送失敗 break; case MessageComposeResultCancelled: //資訊被使用者取消傳送 break; default: break; } } 作者:biubiu15 連結:http://www.jianshu.com/p/1e87a9716266 來源:簡書 著作權歸作者所有。商業轉載請聯絡作者獲得授權,非商業轉載請註明出處。 -(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result { [self dismissViewControllerAnimated:YES completion:nil]; switch (result) { case MessageComposeResultSent: //資訊傳送成功 break; case MessageComposeResultFailed: //資訊傳送失敗 break; case MessageComposeResultCancelled: //資訊被使用者取消傳送 break; default: break; } } 作者:biubiu15 連結:http://www.jianshu.com/p/1e87a9716266 來源:簡書 著作權歸作者所有。商業轉載請聯絡作者獲得授權,非商業轉載請註明出處。 -(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result { [self dismissViewControllerAnimated:YES completion:nil]; switch (result) { case MessageComposeResultSent: //資訊傳送成功 break; case MessageComposeResultFailed: //資訊傳送失敗 break; case MessageComposeResultCancelled: //資訊被使用者取消傳送 break; default: break; } } 作者:biubiu15 連結:http://www.jianshu.com/p/1e87a9716266 來源:簡書 著作權歸作者所有。商業轉載請聯絡作者獲得授權,非商業轉載請註明出處。 -(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
    [self dismissViewControllerAnimated:YES completion:nil];
    switch (result) {
        case MessageComposeResultSent:
            //資訊傳送成功
            break;
        case MessageComposeResultFailed:
            //資訊傳送失敗
            break;
        case MessageComposeResultCancelled:
            //資訊被使用者取消傳送
            break;
        default:
            break;
    }
}
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result { [self dismissViewControllerAnimated:YES completion:nil]; switch (result) { case MessageComposeResultSent: //資訊傳送成功 break; case MessageComposeResultFailed: //資訊傳送失敗 break; case MessageComposeResultCancelled: //資訊被使用者取消傳送 break; default: break; } } 作者:biubiu15 連結:http://www.jianshu.com/p/1e87a9716266 來源:簡書 著作權歸作者所有。商業轉載請聯絡作者獲得授權,非商業轉載請註明出處。