Implementing flurry using xcode 9.3 beta causes warning about UI API called on background thread. Must be called from main thread only.
Any idea what to do to avoid this - is it only for flurry to solve?
Code used in app delegate:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let builder = FlurrySessionBuilder.init()
.withAppVersion("1.0")
.withLogLevel(FlurryLogLevelAll)
.withCrashReporting(true)
.withSessionContinueSeconds(10)
// Replace YOUR_API_KEY with the api key in the downloaded package
Flurry.startSession("YOUR_API_KEY", with: builder)
return true
}
Try this :
Objective C
dispatch_async(dispatch_get_main_queue(), ^{
// add UI related changes here
});
Swift
DispatchQueue.main.async {
// add UI related changes here
}
UI operation should not happen on the background thread. It should be on main thread.
Move your UI update codes inside the main queue. You can use NSOperationQueue
or GCD
. NSOperationQueue
vs GCD
NSOperationQueue
Objective C:
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
// UI update code here.
}];
Swift
OperationQueue.main.addOperation {
// UI Update code here
}
GCD
Objective C
dispatch_async(dispatch_get_main_queue(), ^{
// UI update code here.
});
Swift
DispatchQueue.main.async {
// UI Update code here
}
该API的开发人员承诺进行更新,以使其在iOS 11上线时不使用后台线程。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.