Kirit Modi
Kirit Modi

Reputation: 23407

Twitter warning log "TwitterKit must be used only from the main thread" Fabric SDK?

I am integrate twitter using fabric SDK. I am successfully integrate it in my apps also login and get token,names of user from twitter. But in my apps one Warning is display when checking of twitter session for login.

   if (Twitter.sharedInstance().session() == nil)
   {
       twitterToken = ""
       twitterSecret = ""
   }
   else
   {
       twitterToken = Twitter.sharedInstance().session().authToken
       twitterSecret = Twitter.sharedInstance().session().authTokenSecret     
   }

The warning log display on console shows:

TwitterKit must be used only from the main thread. Use from background threads will lead to unexpected behavior and crashes. Set a symbolic breakpoint in +[TWTRMultiThreadUtil warnForBackgroundThreadUsage] to debug this.

Upvotes: 2

Views: 625

Answers (1)

Michael Dautermann
Michael Dautermann

Reputation: 89569

Why not wrap those lines in code that's called on the main thread?

E.G:

dispatch_async(dispatch_get_main_queue(),{
    if (Twitter.sharedInstance().session() == nil)
    {
          twitterToken = ""
          twitterSecret = ""
    }
    else
     {
          twitterToken = Twitter.sharedInstance().session().authToken
          twitterSecret = Twitter.sharedInstance().session().authTokenSecret     
     }
     ...
     ...
})

where twitterToken and twitterSecret either get used/referred to on the main thread, or you set them as optional properties of your object.

If the warning doesn't go away, do what the warning says and set an Xcode breakpoint on "+[TWTRMultiThreadUtil warnForBackgroundThreadUsage]", so you can see where the warning is really coming from.

Upvotes: 2

Related Questions