内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用
-(void)verifyUserAuthorizationInIOS9andLower{ CNContactStore * contactStore = [[CNContactStore alloc]init]; if ([CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts] == CNAuthorizationStatusNotDetermined) { [contactStore requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * __nullable error) { if (granted==YES) { [self addContactInIOS9andLower]; if ([self addContactInIOS9andLower]) { NSLog(@"Error"); } else{ NSLog(@"Error"); } } else{ NSLog(@"Error"); } }]; } else if ([CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts] == CNAuthorizationStatusAuthorized){ [self addContactInIOS9andLower]; } else { NSLog(@"Error"); } } -(BOOL)addContactInIOS9andLower{ CNContactStore * contactStore = [[CNContactStore alloc]init]; CNMutableContact *mutableContact = [[CNMutableContact alloc]init]; mutableContact.givenName = name; mutableContact.familyName = lastname; mutableContact.phoneNumbers = [[NSArray alloc]initWithObjects:[CNLabeledValue labeledValueWithLabel:CNLabelPhoneNumberiPhone value:[CNPhoneNumber phoneNumberWithStringValue:phone]], nil]; CNSaveRequest * saveRequest = [[CNSaveRequest alloc]init]; [saveRequest addContact:mutableContact toContainerWithIdentifier:nil]; NSError *error = nil; if ([contactStore executeSaveRequest:saveRequest error:&error]){ return NO; } else{ return YES; } }
使用断点进行调试NSLog
给[UIApplication startHangtracer:],
HTStartHangTracing,
这是因为它发生在iOS 9之后,而且它是从内部发生的。UIApplication
,让我对苹果在iOS 9中的新bug报告框架有了强烈的感觉。
这可能只是检测应用程序挂起时的一部分。
当通过TestAir分发时,应该有人调查他们的应用程序错误,以确认HangTracer
也是其中的一部分。