如何等待 MPMediaLibrary 请求授权响应

How to wait for MPMediaLibrary requestAuthorization response

我正在检查用户在提示访问媒体库时给出的响应。我想知道如何在继续之前等待用户的响应

static func getAuthrization(completionHandler:@escaping (Bool) -> Void)  {
        var authStatus:Bool=false;
        let status = MPMediaLibrary.authorizationStatus()
        if(status == MPMediaLibraryAuthorizationStatus.authorized){
            authStatus = true
        }else{
            MPMediaLibrary.requestAuthorization() { status in
                if status == .authorized {
                    authStatus = true
                }else{
                    print("Auth not granted")
                    authStatus = false
                }
            }
        }
        completionHandler(authStatus)
    }

这是我用来获取用户身份验证的函数。

func setSongs(){
        print("called from set songs")
        songQuery.getAuthrization { (status) in
            print(status)
        }
    }

这是我用来调用该函数的函数

现在,该函数在用户响应系统权限提示之前执行并完成。我想要的是代码在执行之前像 js 或 dart 一样等待,然后得到响应。

感谢任何帮助

调用completionHandler如下,

static func getAuthrization(completionHandler:@escaping (Bool) -> Void)  {
        if MPMediaLibrary.authorizationStatus() == .authorized {
            completionHandler(true)
        } else {
            MPMediaLibrary.requestAuthorization() { completionHandler([=10=] == .authorized) }
        }
    }