在 Alamofire 4.0 和 iOS 10 和 Swift 3 中使用 Google 放置 API

Using Google Places API with Alamofire 4.0 and iOS 10 and Swift 3

我的项目目前是在 Xcode 8 和 Swift 3 中使用 Alamofire 4.0 构建的。我使用 CocoaPods 来实现 Alamofire。

我的播客文件如下:

# Uncomment the next line to define a global platform for your project
platform :ios, '10.0'
use_frameworks!

target 'WTB’ do
# Comment the next line if you're not using Swift and don't want to use        dynamic frameworks
pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :tag => ’4.0.0’


pod 'SwiftyJSON', git: 'https://github.com/BaiduHiDeviOS/SwiftyJSON.git',     branch: 'swift3'

pod 'GooglePlaces'    #doesn't work when this line is added
pod 'ChameleonFramework'
end        

我在尝试安装 googlePlaces pod 时在终端中收到以下错误:

- `Alamofire (from `https://github.com/Alamofire/Alamofire.git`, tag    `4.0.0`)` required by `Podfile`
- `Alamofire (= 4.0.0)` required by `Podfile.lock`
- `Alamofire (~> 3.0)` required by `GooglePlaces (1.0.1)`

Google places 可以与以前版本的 Alamofire (3.4.0) 一起使用,但我无法让它与 4.0.0+ 一起使用。我在这里做错了吗?还有其他人遇到同样的问题/找到解决办法了吗?

更新: 干净的 pod 安装后我仍然没有运气

Matthews-MBP:WTB matthewwyeth$ rm -Rf Pods; pod install
Analyzing dependencies
Pre-downloading: `Alamofire` from    `https://github.com/Alamofire/Alamofire.git`, tag `4.0.0`
Pre-downloading: `SwiftyJSON` from    `https://github.com/BaiduHiDeviOS/SwiftyJSON.git`, commit     `de5dc3b1b421805769590d331178551bbb0e5733`
[!] Unable to satisfy the following requirements:

- `Alamofire (from `https://github.com/Alamofire/Alamofire.git`, tag   `4.0.0`)` required by `Podfile`
- `Alamofire (= 4.0.0)` required by `Podfile.lock`
- `Alamofire (~> 3.0)` required by `GooglePlaces (1.0.1)`

[!] Your Podfile has had smart quotes sanitised. To avoid issues in the            future, you should not use TextEdit for editing it. If you are not using            TextEdit, you should turn off smart quotes in your editor of choice.

你应该在你的 pod 文件中将 Google Places 的版本更改为 2.*,这个依赖需要 Alamofire 4.0.

Google Places pod v2.* : https://cocoapods.org/?q=googleplaces

其实问题出在你写的时候

pod 'GooglePlaces'

PodFile 中它没有带来正确的 Pod 但它仍然获取 old GooglePlacesAPI Pod 首先只需在终端中输入 pod search GooglePlaces 它会获取很多结果,因为第一个应该是匹配你会注意到它会是 THE OLD POD 所以..你应该更新你的 pod 存储库

pod update

即使您可能在终端中看不到任何变化,但在 Activity 监视器 -> 网络中您可以监视它,因此需要一些时间才能完成,因此请耐心等待,直到它完成更新,然后重新输入在终端中搜索 GooglePlaces,它会是新的,然后就是 运行

pod install 

再来一次,一切顺利!

*这是我的 Podfile,以备不时之需:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!
target 'YOUR-PROJECT' do
pod 'GoogleMaps', '= 2.1.1'
pod 'GooglePlaces', '= 2.1.1'
pod 'Alamofire',
:git => 'https://github.com/Alamofire/Alamofire.git',
:branch => 'master'
end