错误:请求失败:swift中的错误请求(400)afnetworking批处理

时间:2016-07-12 03:42:32

标签: swift afnetworking

我正在尝试批量通过swift将通知推送到我的应用。我试图通过swift转换下面这个站点中的curl命令,这样我就可以通过swift请求批量推送通知:

https://batch.com/doc/api/transactional.html

这是我在swift中的尝试:

let manager = AFHTTPRequestOperationManager()
            manager.requestSerializer.setValue("REST API KEY", forHTTPHeaderField: "X-Authorization")
            manager.requestSerializer.setValue("application/json", forHTTPHeaderField: "Content-Type")

        var param: [String:AnyObject] = [
                "group_id": "welcome",
                "recipients": [
                    "tokens": ["USER_TOKEN"]
                ],
                "message": [
                    "title": "Hello",
                    "body": "Hi!"
                ],
                "custom_payload": "{\"tag\":\"wake up push\", \"landing_screen\":\"greeting\"}",
                "sandbox":true
        ]

        manager.POST( "https://api.batch.com/1.0/"API KEY"/transactional/send",
        parameters: param,
        success: { (operation: AFHTTPRequestOperation!,responseObject: AnyObject!) in
        print("Push Notification Successfully sent!")
        print("JSON:" + responseObject.description)
        },
        failure: { (operation: AFHTTPRequestOperation!,error: NSError!) in
        print("Error:" + error.localizedDescription)
        })

我一直在收到错误:

  

错误:请求失败:错误请求(400)

欢迎任何想法/方向谢谢!

1 个答案:

答案 0 :(得分:0)

您最好使用此Swift client for the Batch.com Transactional API

此API的所有HTTP响应错误代码都在the documentation中说明,但400 Bad request错误不应该发生,它必须是Batch.com结束时的临时错误。

我认为您已将REST API KEYUSER_TOKENAPI KEY替换为有效值?