0
我添加了一個聯繫人到地址簿的標準方式,並且從iOS6更新我的應用程序到iOS7已經有幾個月了我注意到當添加一個我認爲更新用戶界面後,新的聯繫人到地址簿有一段延遲。iOS7添加一個新的聯繫人導致iOS6中沒有發生延遲
我使用彈出庫(LPPopup)
,並在此之前工作完美,並仍然在所有其他控制器。
但現在當我運行我的ABAddressBookSave
NSLog(@"Making Person");
ABRecordRef newPerson = ABPersonCreate();
ABRecordSetValue(newPerson, kABPersonFirstNameProperty,(__bridge CFTypeRef)contact.fname, &error);
ABRecordSetValue(newPerson, kABPersonLastNameProperty, (__bridge CFTypeRef)contact.lname, &error);
ABRecordSetValue(newPerson, kABPersonJobTitleProperty,(__bridge CFTypeRef)contact.post, &error);
ABRecordSetValue(newPerson, kABPersonNoteProperty, (__bridge CFTypeRef)contact.notes, &error);
NSLog(@"Making Number");
//Add my phone number
ABMutableMultiValueRef PhoneVar = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(PhoneVar, (__bridge CFTypeRef)contact.landLine, kABPersonPhoneMainLabel, NULL);
ABMultiValueAddValueAndLabel(PhoneVar, (__bridge CFTypeRef)contact.mobile, kABPersonPhoneMobileLabel, NULL);
ABRecordSetValue(newPerson, kABPersonPhoneProperty, PhoneVar,nil);
CFRelease(PhoneVar);
if(imageView.image){
NSLog(@"Saving contact image");
NSData *dataRef = UIImagePNGRepresentation(imageView.image);
ABPersonSetImageData(newPerson, (__bridge CFDataRef)dataRef, nil);
}
NSLog(@"Making EMAIL");
//Add my email address
ABMutableMultiValueRef EmailVar = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(EmailVar,(__bridge CFTypeRef)contact.email,kABWorkLabel, NULL);
ABRecordSetValue(newPerson, kABPersonEmailProperty, EmailVar,nil);
CFRelease(EmailVar);
NSLog(@"Making Address");
ABMutableMultiValueRef multiAddress = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);
NSMutableDictionary *addressDictionary = [[NSMutableDictionary alloc] init];
[addressDictionary setObject:contact.address1 forKey:(NSString *) kABPersonAddressStreetKey];
[addressDictionary setObject:contact.address2 forKey:(NSString *)kABPersonAddressCityKey];
[addressDictionary setObject:contact.address3 forKey:(NSString *)kABPersonAddressStateKey];
[addressDictionary setObject:contact.zip forKey:(NSString *)kABPersonAddressZIPKey];
ABMultiValueAddValueAndLabel(multiAddress, (__bridge CFTypeRef)(addressDictionary), kABWorkLabel, NULL);
ABRecordSetValue(newPerson, kABPersonAddressProperty, multiAddress,&error);
CFRelease(multiAddress);
//Finally saving the contact in the address book
ABAddressBookAddRecord(iPhoneAddressBook, newPerson, &error);
CFRelease(newPerson);
ABAddressBookSave(iPhoneAddressBook, &error);
if (error != NULL){
NSLog(@"Saving contact failed.");
NSLog(@"ERROR - \n%@",error);
} else {
NSLog(@"Contact Saved Successfully");
[self successfulSave];
CFRelease(iPhoneAddressBook);
}
和彈出
-(void)successfulSave{
NSLog(@"POPUP");
[[LPPopup appearance] setPopupColor:[UIColor blackColor]];
LPPopup *popup = [LPPopup popupWithText:@"Contact Saved"];
[popup setTextColor:[UIColor whiteColor]];
[popup showInView:self.superview
centerAtPoint:self.center
duration:1
completion:^{NSLog(@"Popup Done after");}];
}
它可能是在一個非主線程的線程上調用的,在這個線程中必須進行UI調用。嘗試將'[self successfulSave];'包裝在主隊列的'dispatch_async'塊中。 – erdekhayser
這工作,但使用performSelectorOnMainThread: – SeanLintern88