Pusher Beams iOS & macOS SDK
示例代码
构建和运行
最低要求
- Swift 4.0+
- Xcode - 获取 Xcode 的最简单方法是访问 App Store,但是如果您有一个注册了 Apple 开发者账户的 AppleID,还可以从 developer.apple.com 下载。
安装
CocoaPods
CocoaPods 是 Cocoa 项目的依赖管理器。您可以使用以下命令安装它:
$ gem install cocoapods
建议使用 CocoaPods 版本 1.3.1 或更高版本来构建 Pusher Beams。
要使用 CocoaPods 将 Pusher Beams 集成到您的 Xcode 项目中,请在您的 Podfile
中指定它
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!
# Replace `<Your Target Name>` with your app's target name.
target '<Your Target Name>' do
pod 'PushNotifications', '~> 3.0.4'
end
然后运行以下命令:
$ pod install
Carthage
Carthage 是一个去中心化的依赖管理器,它构建您的依赖并为您提供二进制框架。
建议使用 Carthage 版本 0.26.2 或更高版本来构建 Pusher Beams。
您可以使用 Homebrew 通过以下命令安装 Carthage:
$ brew update
$ brew install carthage
要使用 Carthage 将 Pusher Beams 集成到您的 Xcode 项目中,请在您的 Cartfile
中指定它
github "pusher/push-notifications-swift"
根据您要构建的平台的类型继续按照以下步骤操作:
Swift 包管理器
Swift Package Manager 是用于管理 Swift 代码分发的一个工具。它与 Swift 构建系统集成,以自动化下载、编译和链接依赖项的过程。
手动 Xcode 集成
要将 Pusher Beams 集成进您的 Xcode 项目中并使用 Swift 包管理器,请按以下步骤操作:在 Xcode 中选择 文件
> Swift 包管理器
> 添加依赖项...
,并输入以下 URL
https://github.com/pusher/push-notifications-swift
Swift 包管理器依赖项
要将 Pusher Beams 作为您自己包的依赖项,请使用下列代码
dependencies: [
.package(url: "https://github.com/pusher/push-notifications-swift.git", from: "3.0.4")
]
从 2.x.x 迁移到 3.x.x
现在在使用库之前,您必须先启动 beams,例如注册任何兴趣。这意味着以下代码将不再有效并会在控制台记录错误
try! PushNotifications.shared.addDeviceInterest("donuts")
PushNotifications.shared.start("YOUR_INSTANCE_ID")
您需要将其替换为以下代码:
PushNotifications.shared.start("YOUR_INSTANCE_ID")
try! PushNotifications.shared.addDeviceInterest("donuts")
我们推荐始终在 application didFinishLaunchingWithOptions
回调中调用 start。注意,您仍然可以控制何时显示推送通知提示,start 不会调用此提示。
运行测试
生成测试覆盖率报告
我们使用 Slather 在本地生成测试覆盖率报告,在提交拉取请求时使用 Codecov。
使用 Slather
运行以下命令来创建静态 HTML 页面格式的报告
slather coverage --html --scheme PushNotifications --workspace PushNotifications.xcworkspace/ PushNotifications/PushNotifications.xcodeproj/
请打开 HTML 报告
open 'html/index.html'
推拉梁参考
通讯
鸣谢
Pusher Beams 由 Pusher 拥有和维护。
许可证
Pusher Beams 采用 MIT 许可证发布。详情请参阅 LICENSE。