Obtain the phone number in the mobile phone address book

Source: Internet
Author: User


Obtain the iPhone user's mobile phone number. Use the following function to return the user's mobile phone number: extern nsstring * ctsettingcopymyphonenumber (). Then call the function. Because this function is included in coretelephony, it can only be used in unofficial iPhone sdks.

Use the following function to return the user's mobile phone number:

 

Extern nsstring
* Ctsettingcopymyphonenumber ();

 

Then you can call it.

 

Because this function is included in coretelephony, it can only be used in unofficial iPhone sdks.

In order to call the system address book interface and corresponding functions, You need to introduce addressbook. framework and addressbookui. framework. At the same time, the source file must contain the same file <addressbook/addressbook. h>, <addressbookui/addressbookui. h>.

Declare the variable first:

 

Abpeoplepickernavigationcontroller * picker;

Call the show select contact interface as needed, and set the abpeoplepickernavigationcontrollerdelegate delegate:

 

If (! Picker ){

Picker = [[abw.lepickernavigationcontroller alloc] init];

// Place the delegate of the picker to the controll

Picker. commandid ickerdelegate = self;

}

 

// Showing the picker

[Self presentmodalviewcontroller: picker animated: Yes];


Shows the contact selection page:

 

 

-(Bool) warn about ickernavigationcontroller:

Shouldcontinueafterselectingperson :( abrecordref) person

{

Return yes;

}

This method is called when you select an item in the address book level-1 list. You can use person to obtain all information about the selected contact, but the selected contact has multiple numbers, we also hope that the user can explicitly specify a number (such as a call) and return YES to allow the address book to enter the contact details page:

When you click a field, the following method is called:

 

-(Bool) warn about ickernavigationcontroller:

Shouldcontinueafterselectingperson :( abrecordref) person

Property :( abpropertyid) Property

Identifier :( abmultivalueidentifier) identifier

{

 

If (property = kabpersonphoneproperty ){

Abmutablemultivalueref phonemulti = abrecordcopyvalue (person, property );

 

Int Index = abmultivaluegetindexforidentifier (phonemulti, identifier );

 

Nsstring * phone = (nsstring *) abmultivaluecopyvalueatindex (phonemulti, index );

 

// Do something

 

 

 

 

[Phone release];

 

 

 

 

 

[Commandid icker dismissmodalviewcontrolleranimated: Yes];

 

}

Return no;

}

There may be many fields in the contact information. First, you need to determine whether the selected field is a phone number. when the requirements are met, obtain the contact information, obtain the index of the user-selected number in the contact number list through the identifier, and finally obtain the selected phone number through the index.

Finally, you need to implement the following method to disable the contact selection interface when you click "cancel:

 

-(Void) verify whether ickernavigationcontrollerdidcancel :( abpeoplepickernavigationcontroller *) Then restart icker

{

// Assigning control back to the main controller

[Picker dismissmodalviewcontrolleranimated: Yes];

IPhone obtains the phone number in the address book

2 | font size subscription

Abaddressbookref addressbook = abaddressbookcreate ();
Required learray = (nsmutablearray *) abaddressbookcopyarrayofallpeople (addressbook );
For (ID * people in each learray)
{
Abmultivalueref phones = (abmultivalueref) abrecordcopyvalue (people, kabpersonphoneproperty );
Int ncount = abmultivaluegetcount (Phones );
For (INT I = 0; I <ncount; I ++)
{
Nsstring * phonellable = (nsstring *) abmultivaluecopylabelatindex (phones, I );
Nsstring * phoneno = (nsstring *) abmultivaluecopyvalueatindex (phones, I); // This is the phone number.
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.