gpt4 book ai didi

ios - kABPerson 属性 |知道地址簿联系人是否也在使用 iPhone?

转载 作者:行者123 更新时间:2023-11-29 12:47:29 25 4
gpt4 key购买 nike

我正在尝试开发一个应用程序,用户可以在其中通过 iMessage 发送消息。所以我可以从 AddressBook 导入联系人列表,并通过 MessageUI Framework 发送消息,但我想知道哪些导入的联系人也有 iPhone 所以他们可以使用 iMessage 功能。有什么方法可以从 kABPerson...Property 中找出来吗?

这是我的代码:

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);

}

}

最佳答案

您的代码是确定地址簿中的人是否拥有 iMessage 的最佳方式。但是,有一个缺点:只有在用户正确设置他们的联系人时它才有效。字段设置不当通常会使开发应用程序变得困难。

这个问题之前有人问过。 Here,得票最高的答案是,

your heurisitic might be ok but it relies on the USER correctly setting that attribute.

depending on the context it might be good enough / or not .. dont know.

there is no real way to detect which user really uses ios (no API)

关于ios - kABPerson 属性 |知道地址簿联系人是否也在使用 iPhone?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23292049/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com