跳到内容

Flutter SDK 快速入门

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

前提条件

Anchor link to

要将 Pushwoosh Flutter SDK 集成到您的应用中,您需要以下内容:

下载示例项目

Anchor link to
Terminal window
# 克隆 SDK 仓库并导航到示例项目
git clone https://github.com/Pushwoosh/pushwoosh-flutter
# 导航到示例目录
cd pushwoosh-flutter/Source/pushwoosh/example

配置项目

Anchor link to

安装依赖项:

Terminal window
flutter pub get

打开 lib/main.dart 并更新 Pushwoosh.initialize 调用:

Pushwoosh.initialize({"app_id": "XXXXX-XXXXX", "sender_id": "XXXXXXXXXXXX"});

app_idsender_id 值替换为您的 Pushwoosh 应用代码Firebase 项目编号

1. 安装依赖项
Anchor link to

导航到 ios 目录并安装依赖项:

Terminal window
cd ios && pod install --repo-update
2. 设置 Bundle Identifier
Anchor link to

在 Xcode 中打开 ios/Runner.xcworkspace 文件。

为每个目标设置 Bundle Identifier

  • Runner:您的应用包名。(例如 com.example.pushwoosh
  • NotificationService:您的应用包名,带有 .NotificationServiceExtension。(例如 com.example.pushwoosh.NotificationServiceExtension
  • StopwatchWidgetExtension:您的应用包名,带有 .StopwatchWidget。(例如 com.example.pushwoosh.StopwatchWidget
3. 设置 API Token
Anchor link to

在您的 ios/Runner/Info.plist 中,将 Pushwoosh_API_TOKEN 键设置为 Pushwoosh Device API Token

1. 设置 google-services.json
Anchor link to

将您的 google-services.json 文件复制到 android/app 目录。

2. 设置包名
Anchor link to

打开 android/app/build.gradle 并将 applicationId 设置为您的应用包名。(例如 com.example.pushwoosh

3. 设置 API Token
Anchor link to

打开您的 android/app/src/main/AndroidManifest.xml 文件,并在 <application> 标签内添加以下元数据:

AndroidManifest.xml
<meta-data android:name="com.pushwoosh.apitoken" android:value="__YOUR_PUSHWOOSH_DEVICE_API_TOKEN__" />

__YOUR_PUSHWOOSH_DEVICE_API_TOKEN__ 替换为您的 Pushwoosh Device API Token

运行项目

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

发送推送通知

Anchor link to

返回 Pushwoosh 控制面板,并向您的注册设备 发送推送通知