ios手机功能:电话 短信 通讯录 总结

1打电话功能

     NSString *str = [telePhone stringByReplacingOccurrencesOfString:@"-" withString:@""];
    NSLog(@"telephone:%@",str);//str为电话号码
   [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",str]]];

2发短信功能引入MessageUI.framework库文件

      #import <MessageUI/MessageUI.h>添加这两个协议

MFMessageComposeViewControllerDelegate

#pragma mark ------Send Message------

- (void)sendMessage

{

    //message

    BOOL canSendSMS = [MFMessageComposeViewController canSendText];

    if (canSendSMS) {

        

        MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];

        picker.messageComposeDelegate = self;

        //picker.navigationBar.tintColor = [UIColor blackColor];

        picker.body = [message objectAtIndex:message_objindex] ;

        //picker.recipients = [NSArray arrayWithObject:@"186-0123-0123"];

        [self presentModalViewController:picker animated:YES];

        [picker release];

    }else {

        UIAlertView *alertDialog;

        alertDialog = [[UIAlertView alloc]initWithTitle:@"提醒" message:@"没有短信功能" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

        [alertDialog show];

    }

    

}

3 获取通讯录

#pragma mark ---------Get Phone List------

- (void)getPhoneList

{

    ABAddressBookRef addressBook = nil;

    

    if ([[UIDevice currentDevice].systemVersion floatValue] >= 6.0)

    {

        addressBook = ABAddressBookCreateWithOptions(NULL, NULL);

        //等待同意后向下执行

        dispatch_semaphore_t sema = dispatch_semaphore_create(0);

        ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error)

                                                 {

                                                     dispatch_semaphore_signal(sema);

                                                 });

        

        dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);

        dispatch_release(sema);

    }

    else

    {

        addressBook = ABAddressBookCreate();

    }

    

    NSArray *myContactArray = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);

    

    for(int i = 0; i < [myContactArray count]; i++){

        ABRecordRef people = (ABRecordRef)[myContactArray objectAtIndex:i];

        CFStringRef firstName = ABRecordCopyValue(people, kABPersonFirstNameProperty);

        CFStringRef midName = ABRecordCopyValue(people, kABPersonMiddleNameProperty);

        CFStringRef lastName = ABRecordCopyValue(people, kABPersonLastNameProperty);

        CFStringRef items = ABRecordCopyValue(people,kABPersonPhoneProperty);

        NSMutableString *fullName = [NSMutableString string];

        if([(NSString *)lastName length] > 0){

            [fullName appendString:(NSString *)lastName];

        }

        if([(NSString *)firstName length] > 0){

            [fullName appendString:(NSString *)firstName];

        }

        

        if([(NSString *)midName length] > 0){

            [fullName appendString:(NSString *)midName];

        }

        CFArrayRef phoneNums = ABMultiValueCopyArrayOfAllValues(items);

        if (phoneNums) {

            for (int j=0; j<CFArrayGetCount(phoneNums); j++)

            {

                NSString *phone = (NSString*)CFArrayGetValueAtIndex(phoneNums, j);

                [name addObject:fullName];

                [phonenum addObject:phone];

            }

        }

        

    }

}


4发邮件

添加这个协议MFMailComposeViewControllerDelegate,

#pragma mark ----- Send Email--------

-(void)displayComposerSheet

{ Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));

    if (mailClass != nil)

    {  // We must always check whether the current device is configured for sending emails

        if ([mailClass canSendMail])

        {

            MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];

            picker.mailComposeDelegate = self;

           [picker setSubject:@"春节快乐!"];

           // Set up recipients

            NSArray *toRecipients = [NSArray arrayWithObject:@" "];

            [picker setToRecipients:toRecipients];

           [picker setMessageBody:[message objectAtIndex:message_objindex] isHTML:NO];

            // Fill out the email body text

          [self presentModalViewController:picker animated:YES];

    }

        else

        {

            UIAlertView *alertDialog;

            alertDialog = [[UIAlertView alloc]initWithTitle:@"提醒" message:@"不支持功能" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

            [alertDialog show];

        }  }

 }



有什么不对的地方望大家指正
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值