ios - Alamofire 上传仅在 iphone 6s plus 上崩溃

标签 ios iphone swift alamofire

我的应用程序在除 iphone 6s plus 之外的所有设备上使用 alamofire 4.0.1 完美上传照片。(在 iphone 4s、5、5s、6、7、7plus 上测试,版本 9.2 和 10.1)

        let image = profileimage
        Alamofire.upload( multipartFormData: { multipartFormData in
                // import image to request
                if let imageData = UIImageJPEGRepresentation(image!, 1) {

                    multipartFormData.append(imageData, withName: "user_profile.profile_picture", fileName: "profile_picture"+NSUUID().uuidString, mimeType: "image/png")
                }      
            },
            usingThreshold: SessionManager.multipartFormDataEncodingMemoryThreshold,
            to:  baseURL+String(currentUser.id)+"/",
            method: .put,
            headers: headers,
            encodingCompletion: { encodingResult in
                switch encodingResult {
                case .success(let upload, _, _):
                    upload.responseJSON { response in
                        let user = createUserFromJSON(response.result.value as! NSDictionary) //crashes here, response is nil
                        completion(user, nil)
                    }
                case .failure(let encodingError):
                    let error = encodingError
                    completion(nil, error)
                }
        })

在 iphone 6s plus 上它崩溃了:

2016-12-02 13:26:04.391264 app[22207:366529] [] nw_socket_get_input_frames recvmsg(fd 14, 1024 bytes): [54] Connection reset by peer
2016-12-02 13:26:04.393678 app[22207:366529] [] nw_endpoint_flow_prepare_output_frames [3.1 52.17.90.251:443 ready socket-flow (satisfied)] Failed to use 1 frames, marking as failed
2016-12-02 13:26:04.394564 app[22207:366529] [] nw_socket_write_close shutdown(14, SHUT_WR): [57] Socket is not connected
2016-12-02 13:26:04.394945 app[22207:366529] [] nw_endpoint_flow_service_writes [3.1 52.17.90.251:443 ready socket-flow (satisfied)] Write request has 0 frame count, 0 byte count
2016-12-02 13:26:04.396875 app[22207:366613] [] __tcp_connection_write_eof_block_invoke Write close callback received error: [89] Operation canceled

最佳答案

这与 Alamofire 无关! NGINX 具有最大文件上传大小。我通过打印 responseString 而不是 JSON 发现了这一点。它说“请求实体太大”。

          upload.responseString { response in
             print(response.result.value)
            }

关于ios - Alamofire 上传仅在 iphone 6s plus 上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40932482/

相关文章:

ios - RGB颜色不正确?

ios - 在 Swift 中更改 UITabBarItem 上的 selectedImage

ios - 如何从主视图中 ScrollView 内的 subview 中关闭 IOS Swift 中的键盘?

iphone - 将 UITextView 的大小调整为其内容不起作用

ios - 如何将数据从 UITableViewCell 传递到 ViewController?

ios - 在 ScrollView subview 中添加自定义 UIButton subview 会导致 CUICatalog : Invalid asset name supplied

ios - iOS 是否查找特定于区域的 .lproj 目录(例如 en_US.lproj)?

iphone - 如何公开类成员或如何实现对那些成员起作用的方法

swift - 我在 swift playgrounds 上添加了 uiview 约束,但约束不起作用,为什么?

ios - CALayer 不会针对不同的方向使用渐变颜色自动调整大小