Main Thread Checker: UI API called on a background thread

问题详述

Main Thread Checker: UI API called on a background thread

具体事例:UIError

解决方法

请 pod update 一下,确定 AlicloudUT 版本为 5.2.0.12 ,已经修复该 UI 卡顿问题 。


如还有该问题出现,请参考下面的排查步骤 :

请检查工程中,是否在后台线程(非主线程)调用 AppKit、UIKit 相关的 API,比如 iOS 10+ 请求通知权限时,[application registerForRemoteNotifications]; 在回调非主线程中执行,则 Xcode 9 会报上述提示。

  1. [_notificationCenter requestAuthorizationWithOptions:UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound completionHandler:^(BOOL granted, NSError * _Nullable error) {
  2. if (granted) {
  3. // granted
  4. NSLog(@"User authored notification.");
  5. // 向APNs注册,获取deviceToken
  6. [application registerForRemoteNotifications];
  7. } else {
  8. // not granted
  9. NSLog(@"User denied notification.");
  10. }
  11. }];

应修改为:

  1. [_notificationCenter requestAuthorizationWithOptions:UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound completionHandler:^(BOOL granted, NSError * _Nullable error) {
  2. if (granted) {
  3. // granted
  4. NSLog(@"User authored notification.");
  5. // 向APNs注册,获取deviceToken
  6. dispatch_async(dispatch_get_main_queue(), ^{
  7. [application registerForRemoteNotifications];
  8. };
  9. } else {
  10. // not granted
  11. NSLog(@"User denied notification.");
  12. }
  13. }];