0

一つ質問があります。私が彼をクリックすると、彼が新しい連絡先をiPhoneのアドレス帳に入れるボタンを作りたいです。多くのチュートリアルを見ましたが、アドレスブックに連絡先が既に存在するかどうかを確認するチュートリアルは見つかりませんでした。

誰かがこれをプログラムで作成する方法を教えてもらえますか? 誰かがボタンをクリックしたときに、彼が最初に確認するか、アドレスブックに連絡先が既に存在することを望みます。

誰かが私を助けてくれることを願っています。

どうもありがとう ;-)

4

3 に答える 3

0

連絡先が出口かどうかを連絡先番号で確認する

注:checkingPhoneNumber変数を確認用の連絡先番号にのみ置き換えてください

ABAddressBookRef * addressbook = ABAddressBookCreateWithOptions(Nil, Nil);
NSArray *people = (__bridge NSArray*)ABAddressBookCopyArrayOfAllPeople(addressbook);
NSMutableArray *phoneArray=[[NSMutableArray alloc] init];

for(id person in people)
{
    // get person contact number
    ABMultiValueRef phones = (ABMultiValueRef)ABRecordCopyValue((__bridge ABRecordRef)(person), kABPersonPhoneProperty);
    NSString* mobile=@"";
    NSString* mobileLabel;

    for (int i=0; i < ABMultiValueGetCount(phones); i++)
    {
        mobileLabel = (__bridge NSString*)ABMultiValueCopyLabelAtIndex(phones, i);
        if([mobileLabel isEqualToString:(NSString *)kABPersonPhoneMobileLabel]) {
            NSLog(@"mobile:");
        } else if ([mobileLabel isEqualToString:(NSString*)kABPersonPhoneIPhoneLabel]) {
            NSLog(@"iphone:");
        } else if ([mobileLabel isEqualToString:(NSString*)kABPersonPhonePagerLabel]) {
            NSLog(@"pager:");
        }
        mobile = (__bridge NSString*)ABMultiValueCopyValueAtIndex(phones, i);
        NSLog(@"%@", mobile);

        // remove all spaces bracket from contact number
        NSMutableString *newPhoneStr = [[NSMutableString alloc] init];;
        int j = [mobile length];
        for (int i=0; i<j; i++)
        {
            if ([mobile characterAtIndex:i] >=48 && [mobile characterAtIndex:i] <=59)
            {
                [newPhoneStr appendFormat:@"%c",[mobile characterAtIndex:i]];
            }
        }
        //add contact into phoneArray
        [phoneArray addObject:newPhoneStr];
    }
}
NSLog(@"%@",phoneArray);

BOOL identicalStringFound = NO;

// remove all spaces bracket from contact number which is check
NSMutableString *newCheckingPhoneNumberStr = [[NSMutableString alloc] init];
int j = [checkingPhoneNumber length];
for (int i=0; i<j; i++)
{
    if ([checkingPhoneNumber characterAtIndex:i] >=48 && [[profileDetailsDict valueForKey:@"mobile"] characterAtIndex:i] <=59)
    {
        [newCheckingPhoneNumberStr appendFormat:@"%c",[checkingPhoneNumber characterAtIndex:i]];
    }
}

for (NSString *contact in phoneArray)
{
    if ([contact isEqual:newCheckingPhoneNumberStr])
    {
        identicalStringFound = YES;
        break;
    }
}
if(identicalStringFound)
{
    // checkingPhoneNumber is exit 
}
else
{
    // checkingPhoneNumber is not exit 
 }
于 2015-11-06T12:55:08.523 に答える
0
ABAddressBookRef addressbook = ABAddressBookCreateWithOptions(Nil, Nil);
 NSArray *people = (__bridge NSArray*)ABAddressBookCopyArrayOfAllPeople(addressbook);
NSMutableArray *namearray=[[NSMutableArray alloc] init];
for(id person in people){
      NSString *firstNameString = (__bridge NSString*)ABRecordCopyValue((__bridge   ABRecordRef)(person),kABPersonFirstNameProperty);
    NSLog(@"%@",firstNameString);
        [namearray addObject:firstNameString];
  }
    NSLog(@"%@",namearray);
NSString *yourString = name you want to add;
BOOL identicalStringFound = NO;
for (NSString *someString in namearray) {
    if ([someString isEqual:yourString]) {
        identicalStringFound = YES;
        break;
    }
}
if(identicalStringFound)
 {
    //code you want to perform
 }
else
 {
    //code you want to perform
 }
于 2014-05-21T07:25:19.047 に答える