Alamofire Post请求后,如何设置完成处理程序/阻止?

编程入门 行业动态 更新时间:2024-10-12 12:32:44
本文介绍了Alamofire Post请求后,如何设置完成处理程序/阻止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个方法来处理 Apple Push Notification Service 远程通知。执行此方法后,我希望它调用服务器并使用 Alamofire 库执行 HTTP POST 请求。我想执行另一种方法来处理POST请求的响应。

I have a method which handles a Apple Push Notification Service remote notification. When this method is executed, I want it to call my server and do a HTTP POST request using the Alamofire library. I want to execute another method that will handle the response of the POST request.

对我来说,问题是我正在使用现有的 API 以在此POST请求中从服务器获取配置文件。因此,我需要使用现有的API并确定何时从远程通知中专门触发了此配置文件获取。

The problem for me is that I am using an existing API to fetch a profile from the server in this POST request. So I need to use this existing API and figure out when this profile fetch is specifically triggered from the remote notification.

由于 Alamofire 请求是在后台队列中完成的,从服务器收到配置文件后,我该如何执行方法的执行?

Since Alamofire requests are done in a background queue, how would I go about doing an execution of a method after receiving the profile back from the server?

谢谢!

推荐答案

由于Alamofire请求是在后台队列中完成的,因此从服务器接收到配置文件后,我该如何执行方法的执行?

Since Alamofire requests are done in a background queue, how would I go about doing an execution of a method after receiving the profile back from the server?

Alamofire内置了响应处理功能。您可以执行以下操作(改编自文档):

Response handling is built in to Alamofire. You can do something like this (adapted from the docs):

Alamofire.request(.POST, "httpbin/get", parameters: ["foo": "bar"]) .response { (request, response, data, error) in println(request) println(response) println(error) }

请注意 .response 方法调用,该方法将完成处理程序添加到请求对象;请求完成(或失败)时,Alamofire将调用完成处理程序。

Note the .response method call, which adds a completion handler to the request object; the completion handler is invoked by Alamofire when the request completes (or fails).

更多推荐

Alamofire Post请求后,如何设置完成处理程序/阻止?

本文发布于:2023-11-26 02:01:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1632203.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何设置   程序   Alamofire   Post

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!