관리 메뉴

꿀맛코딩

iOS 13 NSInternalInconsistencyException statusBar 본문

공부방/iOS

iOS 13 NSInternalInconsistencyException statusBar

soycrab 2019. 10. 17. 17:03

iOS 13 업데이트 이후 Error 가 뿜어져 나온다 ... 

또하나 찾은 Error 내용은 아래와 같다. 

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'App called -statusBar or -statusBarWindow on UIApplication: this code must be changed as there's no longer a status bar or status bar window. Use the statusBarManager object on the window scene instead.'

이전 처럼 UIApplication 에서 status bar 를 가져 올수 없다. 

이전 코드는 아래와 같다. 

UIApplication.shared.value(forKey: "statusBar") as? UIView

 

그럼 이제 어떻게 가져 올수 있을까 ? 

 

해결 코드는 아래와 같다. 

 

       let statusBarView: UIView?

        if #available(iOS 13.0, *) {

            let tag = 38482458385

            if let statusBar = UIApplication.shared.keyWindow?.viewWithTag(tag) {

                statusBarView = statusBar

            } else {

                let statusBar = UIView(frame: UIApplication.shared.statusBarFrame)

                statusBar.tag = tag

                UIApplication.shared.keyWindow?.addSubview(statusBar)

                statusBarView = statusBar

            }

    

        } else {

            statusBarView = UIApplication.shared.value(forKey: "statusBar") as? UIView

    }

참고 : https://stackoverflow.com/questions/57083746/how-can-i-change-status-bar-alpha-in-ios-13

반응형
Comments