最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】Xcode9提示:runtime UI API called from background thread UIApplication currentUserNotificationSettings must be used from main thread only

Xcode crifan 6444浏览 0评论

Xcode9中,调试运行iOS的app,看到提示:

runtime: UI API called from background thread: -[UIApplication currentUserNotificationSettings] must be used from main thread only

但是点击后,无法找到具体是哪里的代码。

且项目中也搜不到:

currentUserNotificationSettings

runtime: UI API called from background thread UIApplication currentUserNotificationSettings

Main Thread Checker: UI API called on a background thread: -[UIApplication setNetworkActivityIndicatorVisible:] · Issue #677 · mixpanel/mixpanel-iphone · GitHub

Main Thread Checker: UI API called on a background thread: -[UIApplication applicationState] · Issue #271 · intercom/intercom-ios · GitHub

Xcode 9 – Main Thread Sanitizer · Issue #69 · firebase/firebase-ios-sdk · GitHub

XCode 9: Main Thread Checker: UI API called from background thread: -[UIApplication applicationIconBadgeNumber] must be called from main thread only · Issue #1146 · parse-community/Parse-SDK-iOS-OSX · GitHub

swift – Main Thread Checker: UI API called on a background thread: -[UIApplication applicationState] – Stack Overflow

集成JPush报警告must be used from main thread only – 极光技术 / JPush – 极光社区

ios – Swift 4 – UIApplication.registerForRemoteNotifications() must be called from main thread only – Stack Overflow

去项目里搜:

UIApplication.

没找到JPUSH方面的

原来是:

Xcode9中引入了一个

Main Thread Checker 

用于运行时期间检测,是否有其他非主UI线程中,去更新UI元素的代码。

有的话,就警告

当然,如果取消警告,可以取消勾选,但是很明显不推荐。

后来看到:

#0    0x0000000100d22f7f in -[JPUSHAPNSStateReport init] ()

#14    0x0000000182d72c38 in thread_start ()

去搜:

JPUSHAPNSStateReport UIApplication

UI API called on a background thread,UI没再主线程刷新,是不是JPush框架的问题? – Bug 报告 / 已修复 – 极光社区

好像是JPush的bug

JPush iOS SDK v3.0.6 最近更新 – 极光文档

后来去Xcode的log输出中,找到了:

Main Thread Checker: UI API called on a background thread: -[UIApplication currentUserNotificationSettings]
PID: 820, TID: 444196, Thread name: org.hxhg.jiguang.thread, Queue name: com.apple.root.default-qos.overcommit, QoS: 21
Backtrace:
4   SRTDev                              0x0000000100d22f80 -[JPUSHAPNSStateReport init] + 232
5   SRTDev                              0x0000000100d26d68 -[JPUSHClientController UDPReportAPNSState] + 44
6   SRTDev                              0x0000000100d26610 -[JPUSHClientController setup] + 484
7   Foundation                          0x0000000183b37a50 <redacted> + 340
8   CoreFoundation                      0x00000001830f0358 <redacted> + 24
9   CoreFoundation                      0x00000001830f02d8 <redacted> + 88
10  CoreFoundation                      0x00000001830efb60 <redacted> + 204
11  CoreFoundation                      0x00000001830ed738 <redacted> + 1048
12  CoreFoundation                      0x000000018300e2d8 CFRunLoopRunSpecific + 436
13  CoreFoundation                      0x000000018305d12c CFRunLoopRun + 116
14  SRTDev                              0x0000000100cf2154 -[JPUSHThread clientThreadMain] + 100
15  Foundation                          0x0000000183b37860 <redacted> + 996
16  libsystem_pthread.dylib             0x0000000182d7432c <redacted> + 308
17  libsystem_pthread.dylib             0x0000000182d741f8 <redacted> + 0
18  libsystem_pthread.dylib             0x0000000182d72c38 thread_start + 4
2017-09-22 11:16:32.041279+0800 SRTDev[820:444196] [reports] Main Thread Checker: UI API called on a background thread: -[UIApplication currentUserNotificationSettings]
PID: 820, TID: 444196, Thread name: org.hxhg.jiguang.thread, Queue name: com.apple.root.default-qos.overcommit, QoS: 21
Backtrace:
4   SRTDev                              0x0000000100d22f80 -[JPUSHAPNSStateReport init] + 232
5   SRTDev                              0x0000000100d26d68 -[JPUSHClientController UDPReportAPNSState] + 44
6   SRTDev                              0x0000000100d26610 -[JPUSHClientController setup] + 484
7   Foundation                          0x0000000183b37a50 <redacted> + 340
8   CoreFoundation                      0x00000001830f0358 <redacted> + 24
9   CoreFoundation                      0x00000001830f02d8 <redacted> + 88
10  CoreFoundation                      0x00000001830efb60 <redacted> + 204
11  CoreFoundation                      0x00000001830ed738 <redacted> + 1048
12  CoreFoundation                      0x000000018300e2d8 CFRunLoopRunSpecific + 436
13  CoreFoundation                      0x000000018305d12c CFRunLoopRun + 116
14  SRTDev                              0x0000000100cf2154 -[JPUSHThread clientThreadMain] + 100
15  Foundation                          0x0000000183b37860 <redacted> + 996
16  libsystem_pthread.dylib             0x0000000182d7432c <redacted> + 308
17  libsystem_pthread.dylib             0x0000000182d741f8 <redacted> + 0
18  libsystem_pthread.dylib             0x0000000182d72c38 thread_start + 4

所以,去升级JPush

资源下载 – 极光文档

-》

https://sdkfiledl.jiguang.cn/jpush-ios-3.0.6-release.zip?t=1506059605006

放到项目中,替换旧版本

之前版本是:

<code>--------------------------- JPush Log ----------------------------
--------------------JPush SDK Version:3.0.1--build:21----------
--------------------JCore Lib Version:1.1.0--build:8—————
</code>

结果换成3.0.6的库后,链接失败:

【已解决】Xcode9中JPush从3.0.1升级到3.0.6后链接出错:Undefined symbols for architecture x86_64 _OBJC_CLASS_$_JPUSHRegisterEntity

【总结】

把JPush从3.0.1升级到3.0.6,好像上述警告就没了。

(但是貌似回退到3.0.1,貌似也没有问题?先不去管了。。。)

转载请注明:在路上 » 【已解决】Xcode9提示:runtime UI API called from background thread UIApplication currentUserNotificationSettings must be used from main thread only

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.163 seconds, using 22.10MB memory