iphone发送短信

1.进入通讯录页面,当然要记住dismiss

                peoPicker = [[ABPeoplePickerNavigationController alloc] init];

                

                peoPicker.peoplePickerDelegate = self;

                

                [self presentViewController:peoPicker animated:YES completion:nil];

2.设置代理方法 dismiss

- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker

{

    [peoPicker dismissModalViewControllerAnimated:YES];

}



3.当点击联系人 当这个返回值为yes时 可以进入用户详情页面 为no时则不进行下一步操作

    // Called after a value has been selected by the user.

    // Return YES if you want default action to be performed.

    // Return NO to do nothing (the delegate is responsible for dismissing the peoplePicker).

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person{

    NSString *phoneContact;


      ABMultiValueRef phone = ABRecordCopyValue(person, kABPersonPhoneProperty);

    if ((phone != nil)&&ABMultiValueGetCount(phone)>0) {

        

        for (int m = 0; m < ABMultiValueGetCount(phone); m++) {

            NSString * aPhone = (__bridge NSString *)ABMultiValueCopyValueAtIndex(phone, m) ;

            NSString * aLabel = (__bridge NSString *)ABMultiValueCopyLabelAtIndex(phone, m) ;


            if ([aLabel isEqualToString:@"_$!<Mobile>!$_"]) {

               phoneContact = aPhone;

            }

            if ([aLabel isEqualToString:@"_$!<WorkFAX>!$_"]) {

                 phoneContact = aPhone;

            }

            

            if ([aLabel isEqualToString:@"_$!<Work>!$_"]) {

                phoneContact = aPhone;

            }

            if ([aLabel isEqualToString:@"_$!<Home>!$_"]) {

                phoneContact = aPhone;

            }

        }

    }

    

    if (phoneContact&&phoneContact.length>0) {

        [self sendMessage:phoneContact];

    }else{

        [self showAlertStr:@"对不起,该联系人无可用电话号码"];

    }

    

    return NO;

}


4.发送短信


- (void)sendMessage:(NSString *)phoneNum{

    

    if( [MFMessageComposeViewController canSendText] ){

        

        MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc]init]; //autorelease];

        

        controller.recipients = [NSArray arrayWithObject:phoneNum];

        controller.body = @"老友,以面具会议、讲后即焚为特色的职场社交【贵人】真不错,您也来吧!贵人下载地址:http://guirenhui.cn";

        controller.messageComposeDelegate = self;

        

        [self presentModalViewController:controller animated:YES];

        

        [[[[controller viewControllers] lastObject] navigationItem] setTitle:@"测试短信"];//修改短信界面标题

    }else{

        

        [self showAlertStr:@"设备没有短信功能"];

    }

}


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

    

    [controller dismissModalViewControllerAnimated:NO];//关键的一句   不能为YES

    

    switch ( result ) {

        case MessageComposeResultCancelled:

            [self showAlertStr:@"发送取消"];

            break;

        case MessageComposeResultFailed:// send failed

            [self showAlertStr:@"发送成功"];

            break;

        case MessageComposeResultSent:

            [self showAlertStr:@"发送失败"];

            break;

        default:

            break;

    }

}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值