2013-01-16 34 views
0

我需要將25000個聯繫人插入到iPhone聯繫人,只要我編碼它可以在模擬器上正常工作,這可以在幾分鐘內完成。但是,當我在iPhone 4s上導入時,需要超過3個小時,並且只保存部分聯繫人,然後關閉應用程序。如何將多個聯繫人插入ABAddressbook?

幫我一個簡單的方法來插入多條記錄到地址簿...

這裏是我的代碼...

for (int i = 0; i < [contactNameArray count]; i++) { 
    //Create new person and save to this group 
    ABRecordRef record = ABPersonCreate(); 
    BOOL isSuccess ; 
    NSString *firstname = [NSString stringWithFormat:@"%@",[contactNameArray objectAtIndex:i]]; 
    isSuccess = ABRecordSetValue(record, kABPersonFirstNameProperty,(__bridge CFStringRef)firstname, &error); 
    isSuccess = ABRecordSetValue(record, kABPersonLastNameProperty,CFSTR("Custom Contacts"), &error); 

    ABMutableMultiValueRef copyOfPhones = ABMultiValueCreateMutable(kABPersonPhoneProperty); 
    NSString *phonenumber = [NSString stringWithFormat:@"%@",[contactPhoneArray objectAtIndex:i]]; 
    CFTypeRef phone= (__bridge CFStringRef)phonenumber; 
    ABMultiValueAddValueAndLabel(copyOfPhones, phone,kABPersonPhoneMobileLabel,NULL); 
    isSuccess = ABRecordSetValue(record, kABPersonPhoneProperty, copyOfPhones, &error); 
    CFRelease(copyOfPhones); 

    ABMutableMultiValueRef multiEmail = ABMultiValueCreateMutable(kABMultiStringPropertyType); 
    NSString *emailid = [NSString stringWithFormat:@"%@",[contactEmailArray objectAtIndex:i]]; 
    CFTypeRef email= (__bridge CFStringRef)emailid; 
    ABMultiValueAddValueAndLabel(multiEmail, email, kABWorkLabel, NULL); 
    ABRecordSetValue(record, kABPersonEmailProperty, multiEmail, &error); 
    CFRelease(multiEmail); 

    isSuccess = ABAddressBookAddRecord(ab, record, &error); 
    isSuccess = ABAddressBookSave(ab, &error); 

    ABGroupAddMember(group, record, &error); 

    NSLog(@"is success %d", isSuccess); 

    ABAddressBookSave(ab, &error); 
} 

在此先感謝....

+0

不要忘記,模擬器具有Mac的全部功能和內存,而iPhone則不具備。 – tomasmcguinness

+0

是的,我知道,但我需要一種在任何iOS設備上以快速方式插入的方式...... – Arvind

回答

1

首先使用快速枚舉。

然後在批處理中保存聯繫並在批處理結束時將計數器編號保存到userdefaults或任何位置。這將阻止您再次重新啓動應對程序。

+0

根據你的想法,它的工作很棒......我很好。 – Arvind

相關問題