2010-11-24 8 views
10

मैं एक ऐप विकसित कर रहा हूं जो बोनोजर का उपयोग करके किसी अन्य आईफोन से जुड़ता है। इसकी विशेषताओं में से एक यह है कि जब मैं दूसरे डिवाइस से कनेक्ट होता हूं तो यह स्वचालित रूप से जांच करेगा कि मेरे पास अन्य व्यक्तियों का फोन नंबर है या नहीं। तो मेरी समस्या यह है कि मैं अन्य डिवाइस द्वारा प्रदान किए गए फोन नंबर के लिए अपनी एड्रेस बुक कैसे देखूं?एक विशिष्ट फोन नंबर के लिए आईफोन एड्रेस बुक कैसे खोजें?

उत्तर

18

यहां मेरी एक एड्रेस बुक विधियों में से एक उदाहरण निकाला गया है। मैं फोन नंबर से नहीं खोज रहा था, लेकिन यह आपको एक विचार देता है कि आपको क्या चाहिए:

- (void) scanAddressBookSample 
    { 
    NSUInteger i; 
    NSUInteger k; 

    ABAddressBookRef addressBook = ABAddressBookCreate(); 
    NSArray *people = (NSArray *) ABAddressBookCopyArrayOfAllPeople(addressBook); 

    if (people==nil) 
     { 
     NSLog(@"NO ADDRESS BOOK ENTRIES TO SCAN"); 
     CFRelease(addressBook); 
     return; 
     } 

    for (i=0; i<[people count]; i++) 
     { 
     ABRecordRef person = (ABRecordRef)[people objectAtIndex:i]; 

     // 
     // Phone Numbers 
     // 
     ABMutableMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty); 
     CFIndex phoneNumberCount = ABMultiValueGetCount(phoneNumbers); 

     for (k=0; k<phoneNumberCount; k++) 
      { 
      CFStringRef phoneNumberLabel = ABMultiValueCopyLabelAtIndex(phoneNumbers, k); 
      CFStringRef phoneNumberValue = ABMultiValueCopyValueAtIndex(phoneNumbers, k); 
      CFStringRef phoneNumberLocalizedLabel = ABAddressBookCopyLocalizedLabel(phoneNumberLabel); // converts "_$!<Work>!$_" to "work" and "_$!<Mobile>!$_" to "mobile" 

      // Find the ones you want here 
      // 
      NSLog(@"-----PHONE ENTRY -> %@ : %@", phoneNumberLocalizedLabel, phoneNumberValue); 

      CFRelease(phoneNumberLocalizedLabel); 
      CFRelease(phoneNumberLabel); 
      CFRelease(phoneNumberValue); 
      } 
     } 

    [people release]; 
    CFRelease(addressBook); 
    } 
+2

की तरह लेता है AlBeebe का उपयोग कर संपर्क प्राप्त कर सकते हैं, दुर्भाग्यवश यह डिवाइस (आईफोन 4, 4.2) पर बहुत अधिक समय लेता है। मैंने 3000 की एड्रेसबुक के लिए 15 सेकंड लिया) – Rabih

+0

आईफोन 3 जीएस आईओएस 4.2.2 => 2000 संपर्कों के लिए 40 सेकंड लेता है। यह अच्छा नहीं है। – ChangUZ

+0

बहुत धन्यवाद महान काम – wod

-1

इसका उपयोग करें। यह मेरा कोड है।

NSLog(@"=====Make People Array with Numbers. Start."); 
     peopleWithNumber = [[NSMutableDictionary alloc] init]; 
     for (int i=0; i < [people count]; i++) { 
      NSInteger phoneCount = [self phoneCountAtIndex:i]; 
      if (phoneCount != 0) { 
       NSMutableArray *phoneNumbers = [[NSMutableArray alloc] init]; 
       for (int j=0 ; j < phoneCount ; j++) { 
        [phoneNumbers addObject:[self phoneNumberAtIndex:i phoneIndex:j]]; 
       } 
       [peopleWithNumber addEntriesFromDictionary: 
       [NSDictionary dictionaryWithObjectsAndKeys: 
        [NSArray arrayWithArray:phoneNumbers], [self fullNameAtIndex:i], nil]]; 
      } 
     } 
     NSLog(@"=====Make People Array with Numbers. End.\n"); 

खोज विधि। यह सरणी

"NSArray * people = (NSArray *) ABAddressBookCopyArrayOfAllPeople (पता पुस्तिका) का उपयोग करने से तेज़ होगा;"

- (NSArray *)searchNamesByNumber:(NSString *)number { 

    NSString *predicateString = [NSString stringWithFormat:@"%@[SELF] contains '%@'",@"%@",number]; 
    NSPredicate *searchPredicate = [NSPredicate predicateWithFormat:predicateString,peopleWithNumber,number]; 
    NSArray *names = [[peopleWithNumber allKeys] filteredArrayUsingPredicate:searchPredicate]; 

    return names; 
} 
5
-(void)createQuickAccessContacts{ 

    NSMutableDictionary contactDictionary= [[NSMutableDictionary alloc]init]; 


    CFArrayRef all = ABAddressBookCopyArrayOfAllPeople(addressBook); 
    CFIndex n = ABAddressBookGetPersonCount(addressBook); 

    NSDate *date=[NSDate date]; 

    for(int i = 0 ; i < n ; i++) 
    { 
     ABRecordRef ref = CFArrayGetValueAtIndex(all, i); 
     ABMultiValueRef phones = (ABMultiValueRef)ABRecordCopyValue(ref, kABPersonPhoneProperty); 

     for(CFIndex j = 0; j < ABMultiValueGetCount(phones); j++) 
     { 

      CFStringRef phoneNumberRef = ABMultiValueCopyValueAtIndex(phones, j); 
      NSString *phoneNumber = (__bridge NSString *)phoneNumberRef; 
      [contactDictionary setObject:(__bridge id)(ref) forKey:phoneNumber]; 


     } 
    } 

    NSLog(@" Time taken %f for %i contacts",[[NSDate date] timeIntervalSinceDate:date],[contactDictionary count]); 

} 

यह को भरने के लिए 2.5k संपर्कों के लिए 0.5 सेकंड की तरह लेता है तो आप संख्या

ABRecordRef ref= [contactDictionary objectForKey:@"89xxxxxxx"]; 

अपने सुपर तेज 0.000x सेकंड

संबंधित मुद्दे