iOS SDK 快速入门
通过这个快速简单的示例开始使用 Pushwoosh iOS SDK。
前提条件
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: 6.7.13[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 Control Panel 并向您注册的设备发送推送通知。
后续步骤
Anchor link to要了解更多信息,请参阅基本集成指南