跳到内容

iOS SDK 快速入门

通过这个快速简单的示例开始使用 Pushwoosh iOS SDK。

前提条件

Anchor link to

要将 Pushwoosh iOS SDK 集成到您的应用中,您需要具备以下条件:

下载示例项目

Anchor link to

从 GitHub 克隆示例项目:

Terminal window
git clone https://github.com/Pushwoosh/pushwoosh-ios-sample.git

配置项目

Anchor link to
  1. 在 Xcode 中打开项目。

  2. https://github.com/Pushwoosh/Pushwoosh-XCFramework 添加为 Swift Package Dependency。

  3. 为主目标 (PushwooshSampleApp) 设置 bundle identifier,以匹配您的 Pushwoosh 项目 (例如,com.pushwoosh.PushwooshSampleApp)。

  4. 为 NotificationService 目标使用相同的 bundle identifier,并附加 .NotificationService (例如,com.pushwoosh.PushwooshSampleApp.NotificationService)。

  5. Info.plist 中,设置:

重要提示: 请确保在您的 Pushwoosh Control Panel 中为令牌授予对正确应用的访问权限。了解更多

运行项目

Anchor link to
  1. 构建并运行项目。
  2. 应用将有两个选项卡:“Actions” 和 “Settings”。导航到 Settings 选项卡。
  3. 点击 Register for Pushes 按钮。
  4. 授予推送通知权限。设备将在 Pushwoosh 注册。

您应该会看到类似这样的日志条目:

Terminal window
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

要了解更多信息,请参阅基本集成指南