카카오 공유하기 기능을 위해 KakaoSDK 모듈을 추가하면서 많은 에러가 발생했다.
1. 터미널에서 라이브러리 설치 문제
coapods issue : None of your spec sources contain a spec satisfying the dependency
arch -x86_64 pod install
[!] CocoaPods could not find compatible versions for pod "Alamofire":
In snapshot (Podfile.lock):
Alamofire (= 4.9.1, ~> 4.9, ~> 4.9.1)
In Podfile:
Alamofire (~> 4.9.1)
AlamofireImage was resolved to 3.6.0, which depends on
Alamofire (~> 4.9)
KakaoSDKUser was resolved to 2.0.0, which depends on
KakaoSDKCommon (= 2.0.0) was resolved to 2.0.0, which depends on
Alamofire (~> 5.1)
CocoaPods could not find compatible versions for pod "KakaoSDKAuth":
In Podfile:
KakaoSDKAuth
KakaoSDKUser was resolved to 2.0.0, which depends on
KakaoSDKAuth (= 2.0.0)
CocoaPods could not find compatible versions for pod "KakaoSDKUser":
In Podfile:
KakaoSDKUser
There are only pre-release versions available satisfying the following requirements:
'KakaoSDKUser', '>= 0'
You should explicitly specify the version in order to install a pre-release version
카카오 SDK를 사용하려면 5.1 버전 이상의 Alamofire가 필요하다고 하여
기존에 '~> 4.9.1'로 설정이 되어 있던 Alamofire 버전을 5.1로 올려주었다.
pod deintegrate - pod install (Alamofire 버전 ~> 5.1로 바꿔줌)
[!] CocoaPods could not find compatible versions for pod "Alamofire":
In snapshot (Podfile.lock):
Alamofire (= 5.1, ~> 4.9, ~> 4.9.1)
In Podfile:
Alamofire
None of your spec sources contain a spec satisfying the dependencies: `Alamofire, Alamofire (= 5.1, ~> 4.9, ~> 4.9.1)`.
You have either:
* out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`.
* mistyped the name or version.
* not added the source repo that hosts the Podspec to your Podfile.
하라는 대로 pod repo update 해줬는데도 에러...
Looking for related issues on cocoapods/cocoapods...
- CocoaPods 1.10 OneSignal MacAir M1 Issue
https://github.com/CocoaPods/CocoaPods/issues/10684
이렇게 알려주는데 또 M1 이슈인거니..
막 다 찾아보고 하라는 거 다 해도 계속 에러 뜸 ㅠㅠㅠ
그러다가 Podfile.lock 파일이 문제라면 그냥 그 파일 지우고 다시 pod install 하라는 댓글 보고
Podfile.lock 파일 지우고 다시 설치하니깐... 된다..ㅠㅠㅠ ㅋㅋㅋㅋㅋㅋ 휴
참고 : StackOverflow_CocoaPods subspec issue
2. Alamofire 버전 업그레이드 문제
Alamofire 버전을 올렸더니 Xcode 프로젝트에서는 다음과 같은 에러가 발생했다.
Module 'Alamofire' has no member named 'request'
Alamofire.request(...) -> AF.request(...) 로 변경해준다.
그리고 많은 시간을 잡아먹었던 대망의 Alamofire upload multipart form data
기존의 코드로 실행했더니 다음과 같은 에러들이 발생했다.
Argument 'to' must precede argument 'usingThreshold'
: 이거는 그냥 fix 누르면 알아서 순서 바꿔줌
'_' can only appear in a pattern or on the left side of an assignment
Pattern cannot match values of type 'URLRequest'
: 이 두 에러는 버전 5에서 upload multipartFormData를 사용하는 방식이 아예 바뀌어서 뜨는 에러라 새로운 버전에 맞게 코드를 수정해주어야 한다. 사용을 좀 더 간편하게 하기 위해 버전 업그레이드를 했다지만, 기존 코드를 바꿔야 하는 사람은 넘나 귀찮고 짱나는 것 ㅎㅎ
속으로 욕은 좀 했지만 고치고 보니 좀 더 간결해지긴 했구만. 사람들마다 구현 방법이 조금씩 다르고 결과값을 전달해주어야 하는 형식들이 달라 예제들 다 찾아서 살펴보면서 짜집기하고 수정하느라 애먹었다. ㅎㅎㅎ
가장 큰 변화라면 굳이 결과값을 upload.responseJSON으로 받거나 에러를 출력할 일이 없이 response 값이 자동으로 upload 된다는 점인 것 같다.
// Alamofire 4
Alamofire.upload(multipartFormData: { (multipartFormData) in
if let param = parameters {
for (key, value) in param {
multipartFormData.append("\(value)".data(using: .utf8)!, withName: key)
}
}
}, usingThreshold: UInt64.init(), to: url!, method: .post, headers: hTTPHeaders) { (result) in
switch result {
case .success(let upload, _, _):
upload.responseJSON { (responseData) in
switch responseData.result {
case .success(let successData):
response(true,successData)
break
case .failure(let error):
response(false,error)
break
}
}
break
case .failure(let error):
response(false, error)
break
}
}
//Alamofire 5
AF.upload(multipartFormData: { (multipartFormData) in
if let param = parameters {
for (key, value) in param {
multipartFormData.append("\(value)".data(using: .utf8)!, withName: key)
}
}
}, to: url!, usingThreshold: UInt64.init(), method: .post, headers: hTTPHeaders).responseJSON { response in
switch response.result {
case .success(let successData):
result(true,successData)
break
case .failure(let error):
result(false, error)
break
}
}
https://i-colours-u.tistory.com/3
'초보 iOS 개발자의 일상 > 개발 업무' 카테고리의 다른 글
[Swift iOS] 다크모드 방지법 how to prevent dark mode (0) | 2021.06.22 |
---|---|
딥 링크 (0) | 2021.06.15 |
[Swift iOS] 카카오링크로 피드 메시지 공유하기 (0) | 2021.06.08 |
Web View 통신 (0) | 2021.06.07 |
[Swift iOS] Reachability 네트워크 체크 (0) | 2021.06.07 |