18

我正在使用 Contact Framework(只是添加一个联系人)。它被保存没有任何问题(我在联系人列表中再次检查)但最近我注意到此消息出现在控制台上:

2015-06-12 09:57:39.723AddingContactToAddressBook[819:291346] HangTracer 间隔为 0,强制为 1s

2015-06-12 09:57:39.725 添加ContactToAddressBook [819:291346] 建立了新的hangtracer 连接:0x332e10

我在谷歌上搜索了一下,只在 Twitter 上找到了一条关于“这是什么新魔法?”的内容。

实际上,我不知道我的代码是否是导致此问题的原因。

 -(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;
}
}
4

1 回答 1

17

使用断点进行调试NSLog会调用[UIApplication startHangtracer:]. 这发生在 下的线程中HTStartHangTracing

它从 iOS 9 开始出现,并且来自内部UIApplication,这让我对 Apple 在 iOS 9 中的新错误报告框架有强烈的感觉。

这可能只是关于检测应用程序何时挂起的部分。

当通过 TestFlight 分发时,有人应该调查他们的应用程序错误报告,以确认这HangTracer是其中的一部分。

于 2015-06-13T20:06:12.880 回答