【问题标题】:Remote Interactive Push Notifications - HOW?远程交互式推送通知 - 如何?
【发布时间】:2020-12-28 19:45:59
【问题描述】:

TL;DR 如何通过 Expo 的 Push API 发送交互式通知

请提供以下信息:

SDK 版本:40 平台(Android/iOS/web/all):全部 使用以下代码,我创建了一个类别并使用getNotificationCategoriesAsync,确认了它的存在。

import Constants from "expo-constants";
import * as Notifications from "expo-notifications";

// Set up Category
  Notifications.setNotificationCategoryAsync("basic", [
    { identifier: "Yes", buttonTitle: "Yes ????" },
    { identifier: "No", buttonTitle: "No ????" },
  ])

// Check category is there
  Notifications.getNotificationCategoriesAsync().then((categories) => {
  console.log(categories)});

// Get experienceId
  experienceId = Constants.manifest.id;
  console.log(experienceId);

在 API 方面,我使用了下面的请求并将@username/appName 替换为上面记录的内容(experienceId)。我已经在 ios 和 android 的真实设备和模拟器上尝试过这个,即使通知确实发送了,它也缺少交互方面。

curl -H "Content-Type: application/json" -X POST "https://exp.host/--/api/v2/push/send" -d '{
  "to": "ExponentPushToken[XXXXXXXXXXXXXXXX]",
  "title":"hello",
  "body": "world",
  "_category":"@username/appName:basic",
}'

我还尝试将“_category”替换为“categoryId”或“categoryIdentifier”或“category”。这些都没有奏效。有没有人能够成功地做到这一点!如果有怎么办!提前致谢

【问题讨论】:

    标签: react-native push-notification expo


    【解决方案1】:

    你真的很亲密,experienceId 和 category 用连字符“-”连接起来。在 iOS 上查看源代码可以看到格式字符串:

    https://github.com/expo/expo/blob/fd47709156ed218cd5a8c5093df113918bdb2700/ios/versioned-react-native/ABI40_0_0/Expo/ExpoKit/Core/UniversalModules/EXNotifications/ABI40_0_0EXScopedNotificationBuilder.m#L33

    curl -H "Content-Type: application/json" -X POST "https://exp.host/--/api/v2/push/send" -d '{
      "to": "ExponentPushToken[XXXXXXXXXXXXXXXX]",
      "title":"hello",
      "body": "world",
      "_category":"@username/appName-basic",
    }'
    

    【讨论】:

    • 谢谢 Dillon,在经历了许多痛苦的调试后,这很有效,并且完全让我度过了一周。新年快乐!
    • 这似乎不适用于 android,知道为什么吗?
    • 您的频道设置如何?我知道 android 需要额外的设置:if (Platform.OS === "android") { Notifications.setNotificationChannelAsync("basic", { name: "Basic", importance: Notifications.AndroidImportance.MAX, sound: "default", vibrationPattern: [0, 250, 500, 250], });
    • 我没有在android上测试过,但是看java代码,貌似和iOS不一样:github.com/expo/expo/blob/…
    • Expo 还没有真正记录“类别”api。所以我不确定 curl 中的 "_category" 参数是否特定于 iOS,而 Android 需要其他东西?可能值得向 Expo 提出如何使用类别,因为我在任何地方都找不到它的文档。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-04
    • 1970-01-01
    相关资源
    最近更新 更多