watch OS 2 上的 AFNetworking 使用 cocoapods
Posted
技术标签:
【中文标题】watch OS 2 上的 AFNetworking 使用 cocoapods【英文标题】:AFNetworking on watch OS 2 using cocoapods 【发布时间】:2016-01-08 17:51:51 【问题描述】:下面的 Podfile
platform :ios, ‘8.0’
link_with ‘Chill’, ‘Chill WatchOS 2 Extension’
pod ‘AFNetworking’, ‘~> 3.0.0’
source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/anodamobi/ANODA-CocoaPods.git'
use_frameworks!
workspace 'Chill.xcworkspace'
target "Chill" do
pod 'SCLAlertView-Objective-C'
pod 'ANHelperFunctions'
pod 'FastEasyMapping', '~> 1.0.1'
end
target "Chill WatchOS 2 Extension" do
platform :watchos, '2.0'
pod 'AFNetworking'
end
安装正常,但在 Watch Extension 文件中出现以下错误:“AFNetworking/AFNetworking.h”未找到。上线了
#import <AFNetworking/AFNetworking.h>
但是在这个文件中使用 AFNetworking 的所有方法都有效。我也可以通过 cmd-click 来查看 AFNetworking 的委托。 有什么想法吗?
运行pod update --verbose
后出现一些警告:
Sending stats
- AFNetworking, 3.0.4
- FastEasyMapping, 1.0.1
- SCLAlertView-Objective-C, 0.8.0
Failed to send stats: SSL_connect returned=1 errno=0 state=SSLv2/v3 read
server hello A: sslv3 alert handshake failure
[!] 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.
[!] There are duplicate dependencies on `AFNetworking` in `Podfile`:
- AFNetworking (~> 3.0.0)
- AFNetworking
[!] CocoaPods did not set the base configuration of your project because your project already has a custom config set. In order for CocoaPods integration to work at all, please either set the base configurations of the target `Chill` to `Pods/Target Support Files/Pods-Chill/Pods-Chill.release.xcconfig` or include the `Pods/Target Support Files/Pods-Chill/Pods-Chill.release.xcconfig` in your build configuration.
[!] CocoaPods did not set the base configuration of your project because your project already has a custom config set. In order for CocoaPods integration to work at all, please either set the base configurations of the target `Chill WatchOS 2 Extension` to `Pods/Target Support Files/Pods-Chill WatchOS 2 Extension/Pods-Chill WatchOS 2 Extension.release.xcconfig` or include the `Pods/Target Support Files/Pods-Chill WatchOS 2 Extension/Pods-Chill WatchOS 2 Extension.release.xcconfig` in your build configuration.
[!] The `Chill WatchOS 2 Extension [Release]` target overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Target Support Files/Pods/Pods.release.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.
[!] The `Chill WatchOS 2 Extension [Release]` target overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Target Support Files/Pods-Chill WatchOS 2 Extension/Pods-Chill WatchOS 2 Extension.release.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.
【问题讨论】:
我正在使用 XCode 7,顺便说一句。 您可以在运行pod update --verbose
时发布详细消息吗?您使用的是哪个 cocoapods 版本?
我使用的是 0.38.2 版本。当然,请查看问题的更新。
【参考方案1】:
为了解决这个问题,我重写了 Podfile 如下:
platform :ios, '7.0'
pod "AFNetworking", "~> 2.6.3"
pod 'SCLAlertView-Objective-C'
pod 'ANHelperFunctions'
pod 'FastEasyMapping', '~> 1.0.1'
source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/anodamobi/ANODA-CocoaPods.git'
workspace 'Chill.xcworkspace'
target "Chill WatchOS 2 Extension" do
platform :watchos, '2.0'
pod 'AFNetworking'
end
所以现在我应该在 platform :ios, '7.0'
和
source 'https://github.com/CocoaPods/Specs.git'
行并在 target "Chill WatchOS 2 Extension" do
行下对 watchOS 目标执行相同操作。
【讨论】:
【参考方案2】:从你的 pod update 详细消息中,我发现了
"The Chill WatchOS 2 Extension [Release]" target overrides the "OTHER_LDFLAGS" build setting defined in "Pods/Target Support Files/Pods/Pods.release.xcconfig". This can lead to problems with the CocoaPods installation
请检查这个 SO 问题,看看它是否能解决您的问题:
The target ... overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Pods.xcconfig
还有一件事:似乎没有必要在您的监视目标中重新声明pod 'AFNetworking'
,因为它已经在全球范围内声明了。
【讨论】:
以上是关于watch OS 2 上的 AFNetworking 使用 cocoapods的主要内容,如果未能解决你的问题,请参考以下文章
如何从 Watch App(Watch OS 2)与非活动的 IOS 应用程序通信
Watch OS 2:是不是可以获得配对的 iPhone 和 Apple Watch 之间连接的蓝牙信号强度?
使用 CoreData 时如何与 Watch OS 2 共享数据以显示在 WKInterfaceTable 中