简体   繁体   English

twilio 在 swift 中获取媒体 url 的完成块不执行

[英]The completion block doesn't execute for twilio get media url in swift

The question is why the completion block not executed at the line imgURL = url ?? ""问题是为什么没有在imgURL = url ?? ""行执行完成块imgURL = url ?? "" imgURL = url ?? "" . imgURL = url ?? ""

When I am debugging, it stops at the line msg.getMediaContentTemporaryUrl and then all the block are skipped executing the return.当我调试时,它停在msg.getMediaContentTemporaryUrl行,然后跳过所有块执行返回。

func getImageURL(_ msg:TCHMessage)->String {
        var imgURL : String = ""
        msg.getMediaContentTemporaryUrl { (result, url) in
            imgURL = url ?? ""
            print("getImage Function: ",imgURL)
        }
        return imgURL
    }

Looking at the examples of the rest of the languages in the official documentation:查看官方文档中其他语言的示例:

Twilio docs for getMediaContentTemporaryUrl getMediaContentTemporaryUrl 的 Twilio 文档

What you are defining inside the curly brackets is a callback executed asynchronously, so you will get there once the request is done.您在大括号内定义的是异步执行的回调,因此一旦请求完成,您就会到达那里。 If you want to stop when you reach that point, you will need to add a breakpoint to the line imgURL = url ?? ""如果您想在到达该点时停止,则需要在imgURL = url ?? "" imgURL = url ?? "" , for example imgURL = url ?? "" ,例如

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM