PusherPlatform (pusher-platform-swift)
目录
安装
CocoaPods
CocoaPods 是 Cocoa 项目的依赖管理器,我们推荐使用它来安装 PusherPlatform 及其依赖项。
如果您还没有安装 Cocoapods gem,请运行以下命令
$ gem install cocoapods
然后运行 pod init
以创建您的 Podfile
(如果您还没有的话)。
然后,将其添加以下行
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0' # change this if you're not making an iOS app!
use_frameworks!
# Replace `<Your Target Name>` with your app's target name.
target '<Your Target Name>' do
pod 'PusherPlatform'
end
然后,运行以下命令
$ pod install
如果您运行 pod install
时发现安装的不是最新版本,请尝试运行以下命令:
$ pod repo update
$ pod install
此外,您还需要确保您的Podfile.lock
文件中没有被锁定到旧版本的PusherPlatform版本。
Carthage
Carthage是一种去中心化的依赖项管理器,它可以自动化为您的Cocoa应用添加框架的过程。
您可以使用以下命令使用Homebrew安装Carthage:
$ brew update
$ brew install carthage
要使用Carthage将PusherPlatform集成到您的Xcode项目中,请指定它位于您的Cartfile
中。
github "pusher/pusher-platform-swift"
Swift Package Manager
Swift Package Manager是一种用于管理Swift代码分布的工具。它与Swift构建系统集成,以自动化下载、编译和链接依赖项的过程。
手动Xcode集成
要使用Swift Package Manager将PusherPlatform集成到您的Xcode项目中,在Xcode中选择文件
> Swift Packages
> 添加包依赖...
,并提供以下URL:
https://github.com/pusher/pusher-platform-swift
Swift Package Manager依赖项
要将自己的包作为PusherPlatform的依赖项添加,请使用以下代码:
dependencies: [
.package(url: "https://github.com/pusher/pusher-platform-swift.git", from: "0.7.3")
]
入门
首先,我们需要有一个Instance
实例。要创建一个Instance
,我们需要传入一个locator
、serviceName
和serviceVersion
。您可以从仪表板获取实例定位器。
let instance = Instance(locator: "instanceLocator", serviceName: "service-name", serviceVersion: "service-version")
Instance
实例允许您使用 Elements 协议与服务进行交互。它公开的高级方法有
- 用于标准 HTTP 请求的
request
和requestWithRetry
- 用于订阅的
subscribe
- 用于可以从最后一个接收的事件 ID 恢复的订阅的
subscribeWithResume
测试
该库有一组测试,可以使用标准方法运行(Xcode 中的 Command-U)。
测试也在 Bitrise 上运行。
通信
许可证
PusherPlatform 在 MIT 许可下发布。有关详细信息,请参阅 LICENSE。
致谢
PusherPlatform 使用以下存储库中的代码
这些库的个别许可证包含在相应的源文件中。