2017-07-19 40 views
1

使用xcode 9.3 beta实现flurry会导致在后台线程上调用UI API的警告。只能从主线程调用。iOS Flurry:从后台线程调用的UI API

任何想法该怎么做才能避免这种情况 - 它只是为了解决问题吗?在应用程序委托使用

代码:

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 
} 
+0

添加屏幕截图,而不是链接。 – KKRocks

+0

通过链接添加屏幕截图 – RSN

+0

API的开发有望在iOS 11上线时使更新不会使用后台线程。 – RSN

回答

5

试试这个:

目标C

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

斯威夫特

DispatchQueue.main.async { 
// add UI related changes here 
} 
+0

谢谢,我添加了应用程序委托中使用的代码:如何重写此代码以使用主线程? – RSN

+0

你不需要在appdelegate中添加。你需要在块中添加UI相关的代码,我提到添加UI相关的变化。 – KKRocks

+0

我不知道你会如何做到这一点与乱舞? – RSN

0

UI操作不应该发生在后台线程上。它应该在主线程上。

将您的UI更新代码移到主队列中。您可以使用NSOperationQueueGCDNSOperationQueue vs GCD

NSOperationQueue

目标C:

[[NSOperationQueue mainQueue] addOperationWithBlock:^{ 
     // UI update code here. 
}]; 

夫特

OperationQueue.main.addOperation { 
    // UI Update code here 
} 

GCD

目标C

dispatch_async(dispatch_get_main_queue(), ^{ 
     // UI update code here. 
}); 

斯威夫特

DispatchQueue.main.async { 
    // UI Update code here 
} 
+0

谢谢,我添加了应用程序委托中使用的代码:如何重写此代码以使用主线程? – RSN

0

API的开发者承诺将进行更新,使得当iOS的11正式上线它不使用后台线程。

+0

参考https://github.com/flurry/flurry-ios-sdk/issues/91 –