iOS SDK 7.0+ 快速入门
通过这个快速简单的示例开始使用 Pushwoosh iOS SDK。
iOS SDK 7.0+ 的新功能
Anchor link to从 7.0 版本开始,Pushwoosh iOS SDK 经过重新设计,采用了完全模块化的架构。该 SDK 现在分为多个独立的模块:PushwooshFramework、PushwooshCore、PushwooshBridge 和 PushwooshLiveActivities 是基本集成所必需的,而 PushwooshForegroundPush、PushwooshVoIP 和 PushwooshTVOS 则可以根据您的需求选择性添加。
这种模块化的方法允许您只包含应用程序实际使用的功能,从而减小最终二进制文件的大小并缩短构建时间。每个模块都可以独立更新,这使得在不影响其余集成的情况下采用新功能变得更加容易。
此版本引入了对原生 Swift Package Manager 的支持,以便更轻松地管理依赖项,同时改进了所有模块之间的 Swift 互操作性。文档现在直接嵌入到二进制框架中,因此您可以通过 Xcode 中的“快速帮助”和“开发者文档”窗口直接访问 API 参考和代码示例。新功能包括完全支持 iOS 16+ 的 Live Activities(实时活动)与 Dynamic Island(灵动岛)集成、可自定义的前台推送通知(带有动画横幅和触觉反馈)、增强的 VoIP 功能以及专为 Apple TV 应用程序设计的 tvOS 模块。
先决条件
Anchor link to要将 Pushwoosh iOS SDK 集成到您的应用程序中,您需要以下内容:
下载示例项目
Anchor link to从 GitHub 克隆示例项目:
git clone https://github.com/Pushwoosh/pushwoosh-ios-sample.git配置项目
Anchor link to-
在 Xcode 中打开项目。
-
将 https://github.com/Pushwoosh/Pushwoosh-XCFramework 添加为 Swift Package Dependency。
-
为主目标 (PushwooshSampleApp) 设置 bundle identifier,以匹配您的 Pushwoosh 项目 (例如,
com.pushwoosh.PushwooshSampleApp)。 -
为 NotificationService 目标使用相同的 bundle identifier,并附加
.NotificationService(例如,com.pushwoosh.PushwooshSampleApp.NotificationService)。 -
在
Info.plist中,设置:Pushwoosh_APPID键为 Pushwoosh Application CodePushwoosh_API_TOKEN键为 Pushwoosh Device API Token
重要提示: 请确保在您的 Pushwoosh Control Panel 中为令牌授予对正确应用的访问权限。了解更多
运行项目
Anchor link to- 构建并运行项目。
- 该应用程序将有两个选项卡:“Actions”和“Settings”。导航到 Settings 选项卡。
- 点击 Register for Pushes 按钮。
- 授予推送通知权限。设备将在 Pushwoosh 注册。
您应该会看到类似这样的日志条目:
Pushwoosh: Initializing application runtime[PW] BUNDLE ID: __YOUR_BUNDLE_ID__[PW] APP CODE: __YOUR_APP_CODE__[PW] PUSHWOOSH SDK VERSION: 7.0.0[PW] HWID: __YOUR_HWID__[PW] PUSH TOKEN: (null)[PW] [I] -[PWNotificationManagerCompatiOS10] NotificationCenter authorization granted: 1[PW] [I] -[PWPushNotificationsManagerCommon] Registered for push notifications: __YOUR_PUSH_TOKEN__您的设备现已在 Pushwoosh 注册。
发送推送通知
Anchor link to返回 Pushwoosh 控制面板,并向您注册的设备发送一条推送通知。
从 SDK 6.x 迁移
Anchor link to如果您正在从 SDK 6.x 版本升级,主要的变化是访问 Pushwoosh 实例的方式。在 7.0+ 版本中,请使用 Pushwoosh.configure 而不是 Pushwoosh.sharedInstance():
之前 (6.x):
Pushwoosh.sharedInstance().registerForPushNotifications()Pushwoosh.sharedInstance().delegate = self之后 (7.0+):
Pushwoosh.configure.registerForPushNotifications()Pushwoosh.configure.delegate = self所有其他 API 保持不变,因此更新您的代码只需要在整个项目中将 sharedInstance() 替换为 configure。
后续步骤
Anchor link to要了解更多信息,请参阅基本集成指南