dart-native/dart_native

请问可以在原生的主线程调用原生函数吗?

ruiq opened this issue · 1 comments

ruiq commented

大佬好。
我在调用iOS的方法时,方法内部使用了一些UIView,但是报错了,说是不在主线程。
所以想问一下,dart -> native,默认会在非主线程调用吗?怎么样可以让这个调用发生在主线程呢?

默认是同步调用到 Native,那么此时是在 flutter-ui 线程,并不是 iOS 的主线程。所以 DartNative 也支持切线程(GCD),比如这个例子:

.performAsync(SEL('currentThread'), onQueue: DispatchQueue.global())