2018. 1. 1. 00:27ㆍ아이폰 개발
Swift에서 쉽게 multipart/formdata 형식으로 이미지 파일을 업로드(POST 방식)할 수 있는 라이브러리가 있어서 적용해보니 생산성이 무척 좋다.
import Alamofire
Alamofire.upload(multipartFormData: { (multipartFormData) in
multipartFormData.append(UIImageJPEGRepresentation(UIImage(named: "1.png")!, 1)!, withName: "image", fileName: "swift_file.jpeg", mimeType: "image/jpeg")
for (key, value) in parameters {
multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key)
}
}, to:"http://127.0.0.1:3000/picture")
{ (result) in
switch result {
case .success(let upload, _, _):
upload.uploadProgress(closure: { (Progress) in
print("Upload Progress: \(Progress.fractionCompleted)")
})
upload.responseJSON { response in
//self.delegate?.showSuccessAlert()
print(response.request) // original URL request
print(response.response) // URL response
print(response.data) // server data
print(response.result) // result of response serialization
// self.showSuccesAlert()
//self.removeImage("frame", fileExtension: "txt")
if let JSON = response.result.value {
print("JSON: \(JSON)")
}
}
case .failure(let encodingError):
print(encodingError)
}
}
* 아카이브 빌드를 하고 앱스토어에 등록하려고 하니 "이 빌드가 유효하지 않습니다."라면서 등록이 안되는 문제가 발생했다. 그리고 다음과 같은 메일이 날라왔다.
Dear developer,
We have discovered one or more issues with your recent delivery for "AppName". To process your delivery, the following issues must be corrected:
Invalid Bundle - One or more dynamic libraries that are referenced by your app are not present in the dylib search path.
Once these issues have been corrected, you can then redeliver the corrected binary.
Regards,
The App Store team
이에 대한 해결 방법은 다음과 같다. 예전에도 이와 비슷하게 외부 라이브러리 관련된 에러가 있었는데 비슷한 유형인 듯하다.
After adding the custom Swift framework to my project I got this email after uploading the app to iTunes connect.
I got this email from iTunes store,
Invalid Bundle - One or more dynamic libraries that are referenced by your app are not present in the dylib search path.
The fix is simple for this issue,
Step 1: Make sure your Custom framework is added to Embedded Binaries in General tab of your target.
Step 2: Under build settings,
Set Always Embed Swift Standard Libraries = Yes
for your main project target.
And Set Always Embed Swift Standard Libraries = No
for your custom framework target.
This solved my problem and I was able to upload binary to iTunes connect.
--------------------
Alamofire is an HTTP networking library written in Swift.
https://github.com/Alamofire/Alamofire
세련된 HTTP 프레임워크 Alamofire
https://outofbedlam.github.io/swift/2016/02/04/Alamofire/
[Raywenderlich - iOS/Swift] Alamofire 사용하기
http://rhammer.tistory.com/115
* git의 서브 모듈은 처음 써보는데, 다음과 같이 처리하면 된다.
--------------------------