관심있는 연락처를 찾기 위해 주소록 데이터를 읽을 필요가있는 앱을 쓰고 있습니다. 앱은 요즘 (Viber, Whatsapp, Tango ...와 같이) 할 수 있습니다. 나는 데이터를 서버에 보내고 클라이언트에 응답하여 연락처에 동일한 앱이 장치에 설치되도록 일치 작업을 수행해야합니다.주소록을 다른 앱처럼 빨리 읽는 법 (Viber, Whatsapp ...)
나는 논리 또는 아이디어의 메커니즘에 아무 문제가 없다, 내 문제는 속도이다! 내가 원하는 것을 할 수 있었지만 iPhone4에서 500 초가 걸린 27 초가 걸렸습니다. 동일한 기기에서 Viber 또는 Whatsapp (또는 유사한 앱)을 시도하면 프로세스가 5 초 이내에 완료됩니다.
내 방법은 매우 간단합니다. for 루프를 수행하고 모든 것을 읽습니다. 다른 앱처럼 어떻게 똑같은 일을 할 수 있습니까?
//variable definitions
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFMutableArrayRef peopleMutable = CFArrayCreateMutableCopy(kCFAllocatorDefault, CFArrayGetCount(people), people);
//sort the contents of the Mutable Array
CFArraySortValues(peopleMutable, CFRangeMake(0, CFArrayGetCount(peopleMutable)), (CFComparatorFunction) ABPersonComparePeopleByName, (void*) ABPersonGetSortOrdering());
//read the Address Book
NSString *fullName, *number;
ABRecordRef record = ABPersonCreate();
ABMutableMultiValueRef multi;
int contactID;
int nameCount=0;//used to count the names in the string to send to server
NSMutableString *strNamesToSend = [[NSMutableString alloc] init];
for(CFIndex i=0; i< CFArrayGetCount(people); i++)
{
record = CFArrayGetValueAtIndex(people, i);
multi = ABRecordCopyValue(record, kABPersonPhoneProperty);
//Contact ID
contactID = (int)ABRecordGetRecordID(record);
//Full Name
fullName = [NSString stringWithFormat:@"%@ %@", (NSString *)ABRecordCopyValue(record, kABPersonFirstNameProperty), (NSString *)ABRecordCopyValue(record, kABPersonLastNameProperty)];
fullName = [fullName stringByReplacingOccurrencesOfString:@" (null)" withString:@""];
//fill data into AddressBook Table
if(dbOpen == SQLITE_OK)
{
//pure sqlite3 work to save the names in my app
}
//Get multiple numbers from each user (if any)
for(CFIndex j=0; j<ABMultiValueGetCount(multi); j++)
{
number = (NSString *)ABMultiValueCopyValueAtIndex(multi, j);
nameCount++;
//fill data into AllNumbers Table
if(dbOpen == SQLITE_OK)
{
//another sqlite3 work to save the numbers
}
}
//send to the server every 29 numbers so we don't send all the 500 numbers at once
if(nameCount > 29)
{
//send to server
}
시간을 어디에서 사용했는지보기 위해 프로파일을 만들었습니까? 데이터를 서버에 동 기적으로 보내시겠습니까? –