2014-04-10 53 views
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");}]; 
} 
+1

它可能是在一個非主線程的線程上調用的,在這個線程中必須進行UI調用。嘗試將'[self successfulSave];'包裝在主隊列的'dispatch_async'塊中。 – erdekhayser

+0

這工作,但使用performSelectorOnMainThread: – SeanLintern88

回答

1

你應該確保你的UI調用主隊列製作,採用兩種

dispatch_async(dispatch_get_main_queue(), ^{ 
    [self successfulSave]; 
} 

或者您可以使用

[self performSelectorOnMainThread: @selector(successfulSave)]; 

我去到一些細節上這在我的教程:http://www.raywenderlich.com/63885/address-book-tutorial-in-ios

目光投向結束。我相信這是我所覆蓋的最後一件事。

相關問題