2

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
}
ugo
  • 2,705
  • 2
  • 30
  • 34
RSN
  • 21
  • 1
  • 7

3 Answers3

6

Try this :

Objective C

dispatch_async(dispatch_get_main_queue(), ^{
 // add UI related changes here
    });

Swift

DispatchQueue.main.async {
// add UI related changes here
}
KKRocks
  • 8,222
  • 1
  • 18
  • 84
  • Thanks, I added the code used in app delegate: how would you rewrite this to use the main thread? – RSN Jul 20 '17 at 07:17
  • you dont need to add in appdelegate . you need to add UI related code inside the block where i mentioned that add UI related changes. – KKRocks Jul 20 '17 at 07:22
  • I have no idea how you would do that with flurry? – RSN Jul 20 '17 at 11:25
2

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
}
Subramanian P
  • 4,365
  • 2
  • 21
  • 25
  • Thanks, I added the code used in app delegate: how would you rewrite this to use the main thread? – RSN Jul 20 '17 at 07:16
0

The developers of the API are promising to make updates making it not use background threads when iOS 11 goes live.

RSN
  • 21
  • 1
  • 7