2013-05-13 5 views
8

In meiner App wird Crashlytics verwendet, um Absturzberichte von Benutzern zu sammeln. Hier ist ein Absturzbericht von einem Benutzer. Es hängt möglicherweise von den Kontaktinformationen des Benutzers ab. Ich kann den Absturz nicht wiederherstellen, da ich nicht weiß, was in seinen Kontakten ist. Hat jemand eine Vorstellung von dieser Situation?Absturzbericht, wenn Benutzer auf das Adressbuch zugreift

com.apple.root.default-priority Crashed 
0 CoreFoundation CFStringCreateCopy + 13 
1 AppSupport CPSqliteDatabaseCreateWithPath + 36 
2 AppSupport CPSqliteDatabaseCreateWithPath + 36 
3 AppSupport CPRecordStoreGetDatabase + 16 
4 AppSupport _getReaderConnection + 10 
5 AppSupport CPRecordStoreProcessQueryWithBindBlock + 22 
6 AppSupport CPRecordStoreCopyAllInstancesOfClassWhereWithBindBlock + 98 
7 AddressBook  ABCCopyArrayOfAllPeopleInSourceWithSortOrdering + 244 
8 SeeYouKee PhoneNumberInputViewController.m line 538-[PhoneNumberInputViewController dofetchContacts:] 
9 AddressBook  __37-[ABTCC accessRequestWithCompletion:]_block_invoke_0 + 26 
10 TCC  __TCCAccessRequest_block_invoke_038 + 316 
11 ... libxpc.dylib _xpc_connection_call_reply + 26 
12 libdispatch.dylib _dispatch_root_queue_drain + 278 
13 libdispatch.dylib _dispatch_worker_thread2 + 92 
14 libsystem_c.dylib _pthread_wqthread + 360 

Der Code für 8 SeeYouKee PhoneNumberInputViewController.m line 538-[PhoneNumberInputViewController dofetchContacts:] ist:

NSArray *contactsInAddressBook = CFBridgingRelease(ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(addressBook, nil, kABPersonSortByLastName)); 

EDIT 1

-(void)dofetchContacts:(ABAddressBookRef)addressBook{ 
NSMutableArray *contactMutArr = [NSMutableArray array]; 
NSMutableString *mStrOfContacts = [NSMutableString string]; 

NSArray *contactsInAddressBook = CFBridgingRelease(ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(addressBook, nil, kABPersonSortByLastName)); 

if (ABPersonGetCompositeNameFormat() == kABPersonCompositeNameFormatLastNameFirst) { 

    for (id aPerson in contactsInAddressBook) { 

     ABRecordRef person = (__bridge ABRecordRef)(aPerson); 

     ABMultiValueRef phoneMultiValue = ABRecordCopyValue(person, kABPersonPhoneProperty); 
     ABMultiValueRef emailMultiValue = ABRecordCopyValue(person, kABPersonEmailProperty); 
     int countPhone = 0; 
     int countEmail = 0; 
     NSMutableArray *phoneStrArr; 
     NSMutableArray *emailStrArr; 

     if (phoneMultiValue != NULL) { 
      countPhone = ABMultiValueGetCount(phoneMultiValue); 
     } 

     if (emailMultiValue != NULL) { 
      countEmail = ABMultiValueGetCount(emailMultiValue); 
     } 

     if (countEmail>0) { 
      emailStrArr = [NSMutableArray array]; 
      for (int i = 0; i < countEmail; i++) { 
       CFStringRef anEmailCF = ABMultiValueCopyValueAtIndex(emailMultiValue, i); 
       NSString *anEmail = (__bridge NSString *)anEmailCF; 
       [emailStrArr addObject:anEmail]; 
       if (anEmailCF != NULL)CFRelease(anEmailCF); 
      } 
     } 

     if (countPhone > 0) { 

      phoneStrArr = [NSMutableArray array]; 
      for (int i = 0; i < countPhone; i++) { 
       CFStringRef anPhoneCF = ABMultiValueCopyValueAtIndex(phoneMultiValue, i); 
       NSString *anPhone = (__bridge NSString *)anPhoneCF; 
       NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:@""] invertedSet]; 
       NSString *anPhonePureNumber = [[anPhone componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""]; 
       [phoneStrArr addObject:anPhonePureNumber]; 
       if (anPhoneCF != NULL)CFRelease(anPhoneCF); 
      } 

     } 
     //    if (arrRefOfEmails != NULL)CFRelease(arrRefOfEmails); 


     CFStringRef lastNameMultiValueCF = ABRecordCopyValue(person, kABPersonLastNameProperty); 
     CFStringRef firstNmaeMultiValueCF = ABRecordCopyValue(person, kABPersonFirstNameProperty); 
     CFStringRef middleNmaeMultiValueCF = ABRecordCopyValue(person, kABPersonMiddleNameProperty); 
     NSString *lastNameMultiValue = (__bridge NSString *)lastNameMultiValueCF; 
     NSString *firstNmaeMultiValue = (__bridge NSString *)firstNmaeMultiValueCF; 
     NSString *middleNmaeMultiValue = (__bridge NSString *)middleNmaeMultiValueCF; 

     NSString *name = [NSString stringWithFormat:@"%@%@%@",(![lastNameMultiValue length])[email protected]"":lastNameMultiValue, (![middleNmaeMultiValue length])[email protected]"":middleNmaeMultiValue, (![firstNmaeMultiValue length])[email protected]"":firstNmaeMultiValue]; 

     if (lastNameMultiValueCF != NULL)CFRelease(lastNameMultiValueCF); 
     if (firstNmaeMultiValueCF != NULL)CFRelease(firstNmaeMultiValueCF); 
     if (middleNmaeMultiValueCF != NULL)CFRelease(middleNmaeMultiValueCF); 
     CFDataRef anAvatarCF = ABPersonCopyImageDataWithFormat(person, kABPersonImageFormatThumbnail); 

     NSData *anAvatarData = (__bridge NSData *)anAvatarCF; 
     UIImage *anAvatar = [UIImage imageWithData:anAvatarData]; 

     if (anAvatarCF != NULL)CFRelease(anAvatarCF); 

     NSDictionary *aPersonDict = [NSDictionary dictionaryWithObjectsAndKeys:name, @"name", [phoneStrArr componentsJoinedByString:@"; "], @"phoneNumber", [emailStrArr componentsJoinedByString:@"; "], @"email", anAvatar, @"avatar", nil]; 
     [contactMutArr addObject:aPersonDict]; 

     NSLog(@"------phoneStrArr :%@",phoneStrArr); 
     NSString *enPhoneNumber = @""; 
     if (phoneStrArr) { 
      enPhoneNumber = [EncryptWithMD5 encryptWithMD5: [phoneStrArr componentsJoinedByString:@"; "]]; 
     } 
     [mStrOfContacts appendString:enPhoneNumber]; 
     [mStrOfContacts appendString:@", "]; 
     if (phoneMultiValue != NULL)CFRelease(phoneMultiValue); 
     if (emailMultiValue != NULL)CFRelease(emailMultiValue); 

    } 

}else{ 

    for (id aPerson in contactsInAddressBook) { 
     ABRecordRef person = (__bridge ABRecordRef)(aPerson); 
     ABMultiValueRef phoneMultiValue = ABRecordCopyValue(person, kABPersonPhoneProperty); 
     ABMultiValueRef emailMultiValue = ABRecordCopyValue(person, kABPersonEmailProperty); 
     int countEmail = 0; 
     NSMutableArray *emailStrArr; 
     NSMutableArray *phoneStrArr; 

     if (emailMultiValue != NULL) { 
      countEmail = ABMultiValueGetCount(emailMultiValue); 
     } 

     if (countEmail>0) { 
      emailStrArr = [NSMutableArray array]; 
      for (int i = 0; i < countEmail; i++) { 
       CFStringRef anEmailCF = ABMultiValueCopyValueAtIndex(emailMultiValue, i); 
       NSString *anEmail = (__bridge NSString *)anEmailCF; 
       [emailStrArr addObject:anEmail]; 
       if (anEmailCF != NULL)CFRelease(anEmailCF); 
      } 
     } 

     int count = ABMultiValueGetCount(phoneMultiValue); 

     if (count > 0) { 
      phoneStrArr = [NSMutableArray array]; 
      for (int i = 0; i < count; i++) { 
       CFStringRef anPhoneCF = ABMultiValueCopyValueAtIndex(phoneMultiValue, i); 
       NSString *anPhone = (__bridge NSString *)anPhoneCF; 
       NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:@""] invertedSet]; 
       NSString *anPhonePureNumber = [[anPhone componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""]; 
       [phoneStrArr addObject:anPhonePureNumber]; 
       if (anPhoneCF != NULL)CFRelease(anPhoneCF); 
      } 
     } 

     CFStringRef lastNameMultiValueCF = ABRecordCopyValue(person, kABPersonLastNameProperty); 
     CFStringRef firstNmaeMultiValueCF = ABRecordCopyValue(person, kABPersonFirstNameProperty); 
     CFStringRef middleNmaeMultiValueCF = ABRecordCopyValue(person, kABPersonMiddleNameProperty); 
     NSString *lastNameMultiValue = (__bridge NSString *)lastNameMultiValueCF; 
     NSString *firstNmaeMultiValue = (__bridge NSString *)firstNmaeMultiValueCF; 
     NSString *middleNmaeMultiValue = (__bridge NSString *)middleNmaeMultiValueCF; 

     NSString *name = [NSString stringWithFormat:@"%@%@%@", (![firstNmaeMultiValue length])[email protected]"":firstNmaeMultiValue, (![middleNmaeMultiValue length])[email protected]"":middleNmaeMultiValue,(![lastNameMultiValue length])[email protected]"":lastNameMultiValue]; 

     if (lastNameMultiValueCF != NULL)CFRelease(lastNameMultiValueCF); 
     if (firstNmaeMultiValueCF != NULL)CFRelease(firstNmaeMultiValueCF); 
     if (middleNmaeMultiValueCF != NULL)CFRelease(middleNmaeMultiValueCF); 

     CFDataRef anAvatarCF = ABPersonCopyImageDataWithFormat(person, kABPersonImageFormatThumbnail); 

     NSData *anAvatarData = (__bridge NSData *)anAvatarCF; 
     UIImage *anAvatar = [UIImage imageWithData:anAvatarData]; 

     if (anAvatarCF != NULL)CFRelease(anAvatarCF); 

     NSDictionary *aPersonDict = [NSDictionary dictionaryWithObjectsAndKeys:name, @"name", [phoneStrArr componentsJoinedByString:@"; "], @"phoneNumber", [emailStrArr componentsJoinedByString:@"; "], @"email", anAvatar, @"avatar", nil]; 
     [contactMutArr addObject:aPersonDict]; 

     NSString *enPhoneNumber = [EncryptWithMD5 encryptWithMD5: [phoneStrArr componentsJoinedByString:@"; "]]; 
     [mStrOfContacts appendString:enPhoneNumber]; 
     [mStrOfContacts appendString:@", "]; 

     if (phoneMultiValue != NULL)CFRelease(phoneMultiValue); 
     if (emailMultiValue != NULL)CFRelease(emailMultiValue); 

    } 


} 
self.contactArr = [[NSArray alloc] initWithArray: contactMutArr]; 
strOfContacts = [NSString stringWithString:mStrOfContacts]; 
} 

bearbeiten 2

-(void)beginFetchContacts{ 
// Request authorization to Address Book 
ABAddressBookRef addressBookRef = NULL; 

if (ABAddressBookRequestAccessWithCompletion) { 
    CFErrorRef *aError=nil; 
    addressBookRef = ABAddressBookCreateWithOptions(NULL, aError); 

    if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) { 
     ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) { 
      // First time access has been granted, add the contact 
      if (granted) { 
       [self dofetchContacts:addressBookRef]; 
      }else{ 
       //    [self alertActionSwitchOnTheContactsAccess]; 
       [self buttonCancelPressed:nil]; 
      } 
     }); 
    } 
    else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) { 
     // The user has previously given access, add the contact 
     [self dofetchContacts:addressBookRef]; 
    } 
}else{ 
    addressBookRef = ABAddressBookCreate(); 
    [self dofetchContacts:addressBookRef]; 
} 

if (addressBookRef != NULL)CFRelease(addressBookRef); 
} 
+0

Wenn möglich könnten Sie bitte Ihren Quellcode angeben, wo Sie Kontakte aus dem Adressbuch holen? Vor ein paar Tagen bekam ich einen Absturz und es stellte sich heraus, dass es sich um die falsche Version des Core Foundation-Objekts handelte. –

+0

@Depesh Bitte überprüfen Sie das Update. –

+0

@Depesh Ich dachte, ich hätte den Grund. Es ist auf dem ABPersonGetCompositeNameFormat. –

Antwort

5

Könnte es sein, dass Sie ABAddressBookCreateWithOptions() und/oder ABAddressBookRequestAccessWithCompletion() auf einem anderen Thread, von wo aus Sie anrufen ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering() sind nennen?

Bitte beachten Sie die folgenden von der Apple-API-Dokumentation:

Der Abschluss Handler wird auf einer beliebigen Warteschlange bezeichnet. Wenn Ihre App in der gesamten App ein Adressbuch verwendet, müssen Sie dafür sorgen, dass die gesamte Verwendung dieses Adressbuchs in einer einzigen Warteschlange ausgeführt wird, um den korrekten threadsicheren Betrieb zu gewährleisten.

Quelle: http://developer.apple.com/library/ios/#documentation/AddressBook/Reference/ABAddressBookRef_iPhoneOS/Reference/reference.html

Alternativ überprüfen, um sicherzustellen, dass Sie nicht vorzeitig die ABAddressBookRef Freigabe Sie von ABAddressBookCreateWithOptions zurückbekommen(). Denken Sie daran, dass ABAddressBookRequestAccessWithCompletion() asynchron ist.

+0

Ich habe den Beitrag bearbeiten, kann das Problem sein, wenn if (addressBookRef! = NULL) CFRelease (addressBookRef); –

6

Ich sehe, dass die abgestürzt Thread „com.apple.root.default-Priorität“

ABAddressBook ist nicht Thread-sicher, so dass, wenn Sie es von zwei verschiedenen Threads aufrufen, es eine Ausnahme auslöst und stürzt die App.

Auch wenn Sie Ihre Aufrufe an DISPATCH_QUEUE_PRIORITY_DEFAULT immer senden, kann es auf zwei verschiedenen Threads ausgeführt werden, da DISPATCH_QUEUE_PRIORITY_DEFAULT keine serielle Warteschlange ist.

verwenden Ihre Serien Warteschlange zu erstellen, die DISPATCH_QUEUE_PRIORITY_DEFAULT entsendet:

dispatch_queue_t abQueue = dispatch_queue_create("myabqueue", DISPATCH_QUEUE_SERIAL); 
dispatch_set_target_queue(abQueue, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)); 

Denken Sie daran, versenden (sync oder async) alle Anrufe Buch an diese Warteschlange zu adressieren.

EDIT:

Es sieht aus wie Sie dofetchContacts in einem Abschluss-Handler-Block übergeben in die Funktion ABAddressBookRequestAccessWithCompletion anrufen. Achten Sie darauf, diesen Anruf auf dem Hauptthread zu versenden!

Die Dokumentation sagt:

Der Abschluss-Handler auf einer beliebigen Warteschlange aufgerufen wird. Wenn Ihre App in der App ein Adressbuch verwendet, sind Sie dafür verantwortlich, dass sichergestellt wird, dass die gesamte Verwendung dieses Adressbuchs an eine einzige -Warteschlange gesendet wird, um den korrekten threadsicheren Betrieb sicherzustellen.

+0

Eigentlich läuft "dofetchContacts:" im Hauptthread. "Com.apple.root.default-priority" ist ein Hinweis von CrashLytics. –

+1

Nein, eigentlich läuft dieser Code nicht auf dem Hauptthread, da der Completion-Handler von a aufgerufen wird Hintergrund Queue – Felix

0
- (IBAction)btn_addprofile:(id)sender 
{ 
    // creating the picker 
    ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init]; 
    // place the delegate of the picker to the controll 
    picker.peoplePickerDelegate = self; 

    // showing the picker 

    app.appstart=0; 
    [self presentModalViewController:picker animated:YES]; 
    // releasing 
    [picker release]; 
} 

- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker 
{ 
    // assigning control back to the main controller 
    [self dismissModalViewControllerAnimated:YES]; 
} 

- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person { 

    add_profile_screen *viewcontroller=[[add_profile_screen alloc]initWithNibName:@"add_profile_screen" bundle:nil]; 



    // setting the first name 

    NSString *str_f =(NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty); 
    NSString *str_l=(NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty); 

    NSLog(@"%@",str_f); 
    NSLog(@"%@",str_l); 

    if([str_f isEqualToString:@""] || [str_l isEqualToString:@""] || !str_f || !str_l) 
    { 
     if([str_f isEqualToString:@""] || !str_f) 
     { 
      viewcontroller.strfirstname=[NSString stringWithFormat:@"%@",str_l]; 
     } 
     else 
     { 
      viewcontroller.strfirstname=[NSString stringWithFormat:@"%@ ",str_f]; 
     } 
    } 
    else 
    { 
     viewcontroller.strfirstname=[NSString stringWithFormat:@"%@ %@",str_f,str_l]; 
    } 

    // viewcontroller.strname=[NSString stringWithFormat:@"%@",(NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty)]; 



    ABMutableMultiValueRef multi = ABRecordCopyValue(person, kABPersonEmailProperty); 
    if (ABMultiValueGetCount(multi) > 0) 
    { 
     // collect all emails in array 
     // for (CFIndex i = 0; i < ABMultiValueGetCount(multi); i++) 
     for (CFIndex i = 0; i <1; i++) 
     { 
      CFStringRef emailRef = ABMultiValueCopyValueAtIndex(multi, i); 
      viewcontroller.strlastname= (NSString *)emailRef; 
      CFRelease(emailRef); 
     } 
    } 

    // setting the number 
    ABMultiValueRef multi1 = ABRecordCopyValue(person, kABPersonPhoneProperty); 
    viewcontroller.strnumber=[NSString stringWithFormat:@"%@",(NSString*)ABMultiValueCopyValueAtIndex(multi1, 0)]; 
    NSLog(@"%@",viewcontroller.strnumber); 


    [self.navigationController pushViewController:viewcontroller animated:YES]; 
    [viewcontroller release]; 


     // remove the controller 
    [self dismissModalViewControllerAnimated:YES]; 

    return NO; 
} 

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier 
{ 
    return NO; 
}