在 Swift 中判断是否在主线程

2021-02-04  本文已影响0人  lenbolan
    func getState() -> UIApplication.State {
        if Thread.isMainThread {
            return UIApplication.shared.applicationState
        } else {
            var state: UIApplication.State?
            DispatchQueue.main.async {
                state = UIApplication.shared.applicationState
            }
            return state!
        }
    }
上一篇 下一篇

猜你喜欢

热点阅读