[英]App crashes in iOS 13 when pushing ABPersonViewController
Till iOS 12 code is working fine.直到 iOS 12 代码工作正常。 But the below code is crashing the application on iOS13.但是下面的代码使 iOS13 上的应用程序崩溃。
NOTE: I do not want to upgrade to Contacts framework right now.注意:我现在不想升级到联系人框架。
Sharing my code below:在下面分享我的代码:
ABPersonViewController *vc = [[ABPersonViewController alloc] init];
vc.displayedPerson = person;
vc.addressBook = parser.addressbook;
vc.allowsEditing = YES;
vc.personViewDelegate = self;
[self.navigationController pushViewController:vc animated:YES];
When pushing, app crashes only on iOS 13. sharing below crash stack:推送时,应用程序仅在 iOS 13 上崩溃。在崩溃堆栈下方共享:
*** Terminating app due to uncaught exception 'CNPropertyNotFetchedException', reason: 'Contact 0x7fb020d2bc70 is missing some of the required key descriptors: (
"<CNAggregateKeyDescriptor: 0x600003176be0: kind=+[CNContactContentViewController descriptorForRequiredKeys]>"
)'
*** First throw call stack:
(
0 CoreFoundation 0x000000010e63127e __exceptionPreprocess + 350
1 libobjc.A.dylib 0x000000010deb3b20 objc_exception_throw + 48
2 CoreFoundation 0x000000010e6310bc +[NSException raise:format:] + 188
3 Contacts 0x000000010e03f0fb -[CNContact assertKeysAreAvailable:] + 119
4 ContactsUI 0x000000012a2ded30 +[CNContactViewController viewControllerForContact:] + 137
5 AddressBookUI 0x000000010df62233 -[ABPersonViewController reloadContactViewController] + 858
6 UIKitCore 0x0000000113361aca -[UIViewController loadViewIfRequired] + 172
7 UIKitCore 0x0000000113362277 -[UIViewController view] + 27
8 UIKitCore 0x00000001132b13dd -[UINavigationController _startCustomTransition:] + 1039
9 UIKitCore 0x00000001132c730c -[UINavigationController _startDeferredTransitionIfNeeded:] + 698
10 UIKitCore 0x00000001132c8721 -[UINavigationController __viewWillLayoutSubviews] + 150
11 UIKitCore 0x00000001132a9553 -[UILayoutContainerView layoutSubviews] + 217
12 UIKitCore 0x0000000113ec64bd -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2478
13 QuartzCore 0x000000010ee87db1 -[CALayer layoutSublayers] + 255
14 QuartzCore 0x000000010ee8dfa3 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 517
15 QuartzCore 0x000000010ee998da _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 80
16 QuartzCore 0x000000010ede0848 _ZN2CA7Context18commit_transactionEPNS_11TransactionEd + 324
17 QuartzCore 0x000000010ee15b51 _ZN2CA11Transaction6commitEv + 643
18 UIKitCore 0x0000000113a0a3f4 _afterCACommitHandler + 160
19 CoreFoundation 0x000000010e593867 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
20 CoreFoundation 0x000000010e58e2fe __CFRunLoopDoObservers + 430
21 CoreFoundation 0x000000010e58e97a __CFRunLoopRun + 1514
22 CoreFoundation 0x000000010e58e066 CFRunLoopRunSpecific + 438
23 GraphicsServices 0x0000000117be9bb0 GSEventRunModal + 65
24 UIKitCore 0x00000001139e0d4d UIApplicationMain + 1621
25 QA cleanup dupes 0x000000010bf5ace0 main + 112
26 libdyld.dylib 0x000000010fb72c25 start + 1
27 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I'm using AddressBook framework.我正在使用地址簿框架。 Please help me get through this.请帮助我度过难关。 Thanks谢谢
AddressBook and AddressBookUI Is deprecated AddressBook和AddressBookUI已弃用
Better is to shift to更好的是转移到
@import Contacts;
@import ContactsUI;
-(void)fetchAllContacts:(void(^)(BOOL success, NSError * _Nullable error))completion
{
self.contactArray = [[NSMutableArray alloc] init];
CNContactStore *store = [[CNContactStore alloc] init];
[store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (success)
{
NSArray *keys = @[CNContactNamePrefixKey, CNContactFamilyNameKey, CNContactGivenNameKey,
CNContactPhoneNumbersKey, CNContactImageDataKey, CNContactEmailAddressesKey];
NSString *containerId = store.defaultContainerIdentifier;
NSPredicate *predicate = [CNContact predicateForContactsInContainerWithIdentifier:containerId];
NSError *error;
NSArray *cnContacts = [store unifiedContactsMatchingPredicate:predicate keysToFetch:keys error:&error];
if (error)
{
NSLog(@"ERROR IN FETCHING: %@", error.description);
}
else
{
for (CNContact *contact in cnContacts)
{
@try
{
CMCustomContacts *newContact = [[CMCustomContacts alloc] init];
newContact.phoneArray = [[NSMutableArray alloc] init];
newContact.emailArray = [[NSMutableArray alloc] init];
newContact.firstName = contact.givenName;
newContact.lastName = contact.familyName;
UIImage *image = [UIImage imageWithData:contact.imageData];
newContact.profileImage = image;
for (CNLabeledValue *label in contact.phoneNumbers)
{
NSString *phone = [label.value stringValue];
if ([phone length] > 0)
{
[newContact.phoneArray addObject:phone]; NSLog(@"PHONE NUMBER: %@",phone);
}
}
for (CNLabeledValue *label in contact.emailAddresses)
{
NSString *email = label.value;
if ([email length] > 0)
{
[newContact.emailArray addObject:email]; NSLog(@"EMAIL :: %@",email);
}
}
[self.contactArray addObject:newContact];
}
@catch (NSException *exception)
{
NSLog(@"EXCEPTION IN CONTACTS :: %@", exception.description);
}
@finally
{
NSLog(@"FINALLY");
}
}
NSLog(@"COUNT OF CONTACTS :: %lu", (unsigned long)self.contactArray.count);
}
}
completion(granted, error);
}];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.