Advertisement
Guest User

Working phoneNumbers getter

a guest
Jul 8th, 2014
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (NSArray *)phoneNumbers {
  2.  
  3.     // The difference is I remove all of the objects
  4.     if (_phoneNumbers) {
  5.         [_phoneNumbers removeAllObjects];
  6.     }
  7.  
  8.     if (!_phoneNumbers) {
  9.         //Create _phoneNumbers array
  10.         _phoneNumbers = [[NSMutableArray alloc]init];
  11.     }
  12.    
  13.     ABMultiValueRef *phoneNumberRef = ABRecordCopyValue(_contactRef, kABPersonPhoneProperty);
  14.    
  15.     NSString *phoneNumber = [[NSString alloc] init];
  16.    
  17.     // Make sure multi value ref exists
  18.     if (phoneNumberRef) {
  19.         CFIndex numberOfPhoneNumbers = ABMultiValueGetCount(phoneNumberRef);
  20.        
  21.         for (CFIndex i = 0; i < numberOfPhoneNumbers; i++) {
  22.             phoneNumber = (__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(phoneNumberRef, i);
  23.             CFStringRef label = ABMultiValueCopyLabelAtIndex(phoneNumberRef, i);
  24.             if (label) {
  25.                
  26.             [_phoneNumbers addObject:phoneNumber];
  27.                 NSLog(@"phoneNumbers count in method: %d", _phoneNumbers.count);
  28.             }
  29.             CFRelease(label);
  30.         }
  31.         CFRelease(phoneNumberRef);
  32.     }
  33.    
  34.     return _phoneNumbers;
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement