相关疑难解决方法(0)

使用Swift 3检查iOS中的API响应时间?

我知道测试API的响应时间基本上是由服务器或后端端完成的,但是因为我正在为一个应用程序工作,我还需要检查来自iOS End的api响应时间.

我怎样才能做到这一点 ?我读了几个链接,它说使用计时器启动和计时器结束,然后通过endTime - startTime找到响应时间, 但这似乎不方便.

我想使用Xcode(即使XCTest在那里).

这是我的API之一(我在ApiManager类的单独类中编写了所有Web服务使用方法):

LoginVC:

//Call Webservice
let apiManager      = ApiManager()
apiManager.delegate = self
apiManager.getUserInfoAPI()
Run Code Online (Sandbox Code Playgroud)

ApiManager:

func getUserInfoAPI()  {
    //Header
    let headers =       [
        "Accept"        : "application/json",
        "Content-Type"  : "application/json",
    ]

    //Call Web API using Alamofire library
    AlamoFireSharedManagerInit()
    Alamofire.request(HCConstants.URL, method: .post, parameters: nil, encoding: JSONEncoding.default, headers: headers).responseJSON {  response in

        do{
            //Checking For Error
            if let error = response.result.error {
                //Stop AcitivityIndicator
                self.hideHud()
                //Call failure delegate method
                //print(error)
                  self.delegate?.APIFailureResponse(HCConstants.EXCEPTION_MESSAGES.SERVICE_FAILURE)
                return
            } …
Run Code Online (Sandbox Code Playgroud)

performance response ios swift3

5
推荐指数
3
解决办法
4737
查看次数

标签 统计

ios ×1

performance ×1

response ×1

swift3 ×1