【问题标题】:Alamofire upload crashing only on iphone 6s plusAlamofire 上传仅在 iphone 6s plus 上崩溃
【发布时间】:2016-12-02 12:41:18
【问题描述】:

我的应用使用 alamofire 4.0.1 在除 iphone 6s plus 之外的所有设备上完美上传照片。(在 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

【问题讨论】:

  • iPhone 6 plus 中哪个 ios 版本?
  • 它在 IOS 版本 10.1 和 9.2 上崩溃
  • 您已经针对所有这些设备测试了您的应用程序,这意味着您使用的是 iPhone 模拟器还是实际设备?一张典型的图片有多大?
  • 确实大部分是模拟器!测试设备:iphone 6、7 和 5s。崩溃最早出现在6s plus设备上,但也发生在6s plus模拟器上

标签: ios iphone swift alamofire


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-19
    • 2016-04-22
    • 2020-10-31
    • 2016-06-07
    • 2015-10-10
    • 1970-01-01
    • 1970-01-01
    • 2015-12-06
    相关资源
    最近更新 更多