2014-04-25 60 views
1

我試圖開發一個應用程序,用戶可以通過iMessage發送消息。因此,我可以從AddressBook導入聯繫人列表,並通過MessageUI Framework發送消息,但我想知道哪些聯繫人導入了iPhone,因此他們可以使用iMessage功能。有沒有什麼辦法可以從kABPerson找到......房產?kABPerson物業|要知道AddressBook聯繫人是否也在使用iPhone?

這裏我的代碼:

ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL); 

    if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) { 
     ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) { 
      ABAddressBookRef addressBook = ABAddressBookCreate(); 
     }); 
    } 
    else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) { 

CFErrorRef *error = NULL; 
     ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, error); 
     CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook); 
     CFIndex numberOfPeople = ABAddressBookGetPersonCount(addressBook); 

     for(int i = 0; i < numberOfPeople; i++) { 

      ABRecordRef person = CFArrayGetValueAtIndex(allPeople, i); 

      NSString *firstName = (__bridge NSString *)(ABRecordCopyValue(person, kABPersonFirstNameProperty)); 
      NSString *lastName = (__bridge NSString *)(ABRecordCopyValue(person, kABPersonLastNameProperty)); 

      //Something like this ? 
      BOOL *doeshaveiPhone = (__bridge BOOL *)(ABRecordCopyValue(person, kABPersonPhoneIPhoneLabel)); 


      NSLog(@"Name:%@ Surname: %@", firstName, lastName); 


      ABMultiValueRef phones = ABRecordCopyValue(person, kABPersonPhoneProperty); 

      for(CFIndex j = 0; j < ABMultiValueGetCount(phones); j++) 
      { 
       CFStringRef phoneNumberRef = ABMultiValueCopyValueAtIndex(phones, j); 
       CFStringRef locLabel = ABMultiValueCopyLabelAtIndex(phones, j); 
       NSString *phoneLabel =(__bridge NSString*) ABAddressBookCopyLocalizedLabel(locLabel); 

       NSString *phoneNumber = (__bridge NSString *)phoneNumberRef; 
       CFRelease(phoneNumberRef); 
       CFRelease(locLabel); 
       NSLog(@" - %@ (%@)", phoneNumber, phoneLabel); 

      } 

     } 

回答

1

你的代碼,以確定是否人在地址簿中有iMessage的最好的方式。但是,有一個缺點:它只適用於用戶正確設置他們的聯繫人。通常情況下,字段設置不當會導致開發應用程序困難。

此問題已被提問。 Here,得票最多的回答說,

您heurisitic可能是好的,但它依賴於用戶正確 設置該屬性。

取決於上下文它可能是足夠好/不是。不要 知道。

存在是能夠檢測到用戶真正使用的IOS(無API)

沒有真正的方法
相關問題