如何将 Alamofire pod 添加到 Apple Watch 扩展?

alx*_*ves 1 cocoapods swift apple-watch

我有一个名为“watchTest”的 Apple Watch 扩展。我正在尝试添加Alamofire此扩展程序,但直到现在还没有成功。

我的播客文件:

source "https://github.com/CocoaPods/Specs.git"

platform :ios, '9.3'

use_frameworks!

target 'buttonExample' do
    pod 'Alamofire'
end

target 'watchTest' do
    pod 'Alamofire'

    target 'watchTest Extension' do
        inherit! :search_paths
    end

end
Run Code Online (Sandbox Code Playgroud)

Pod 安装日志(警告可能是问题的根源):

Analyzing dependencies
Downloading dependencies
Using Alamofire (4.9.0)
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.

[!] The `watchTest [Debug]` target overrides the `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in `Pods/Target Support Files/Pods-watchTest/Pods-watchTest.debug.xcconfig'. This can lead to problems with the CocoaPods installation
    - Use the `$(inherited)` flag, or
    - Remove the build settings from the target.

[!] The `watchTest [Release]` target overrides the `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in `Pods/Target Support Files/Pods-watchTest/Pods-watchTest.release.xcconfig'. This can lead to problems with the CocoaPods installation
    - Use the `$(inherited)` flag, or
    - Remove the build settings from the target.
Run Code Online (Sandbox Code Playgroud)

WatchTest 扩展 InterfaceController.swift:

import WatchKit
import Foundation
import Alamofire

class InterfaceController: WKInterfaceController {

    override func awake(withContext context: Any?) {
        super.awake(withContext: context)

        // Configure interface objects here.
    }

    override func willActivate() {
        // This method is called when watch view controller is about to be visible to user
        super.willActivate()
    }

    override func didDeactivate() {
        // This method is called when watch view controller is no longer visible
        super.didDeactivate()
    }

}
Run Code Online (Sandbox Code Playgroud)

编译出错:

watchTest 扩展:没有这样的模块“Alamofire”

eir*_*vaa 8

请查看链接。它表明您必须添加platform :watchos 'version'到目标。

target 'watchTest Extension' do
    platform :watchos, 'version'
    pod 'Alamofire'
end
Run Code Online (Sandbox Code Playgroud)

  • 仅供参考,您应该将“version”替换为您的 WatchOS 部署版本。 (2认同)