问题详述
Main Thread Checker: UI API called on a background thread
具体事例:
解决方法
请 pod update 一下,确定 AlicloudUT 版本为 5.2.0.12 ,已经修复该 UI 卡顿问题 。
如还有该问题出现,请参考下面的排查步骤 :
请检查工程中,是否在后台线程(非主线程)调用 AppKit、UIKit 相关的 API,比如 iOS 10+ 请求通知权限时,[application registerForRemoteNotifications];
在回调非主线程中执行,则 Xcode 9 会报上述提示。
[_notificationCenter requestAuthorizationWithOptions:UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (granted) {
// granted
NSLog(@"User authored notification.");
// 向APNs注册,获取deviceToken
[application registerForRemoteNotifications];
} else {
// not granted
NSLog(@"User denied notification.");
}
}];
应修改为:
[_notificationCenter requestAuthorizationWithOptions:UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (granted) {
// granted
NSLog(@"User authored notification.");
// 向APNs注册,获取deviceToken
dispatch_async(dispatch_get_main_queue(), ^{
[application registerForRemoteNotifications];
};
} else {
// not granted
NSLog(@"User denied notification.");
}
}];
文档内容是否对您有帮助?