Expo React Native 通知侦听器 addNotificationResponseReceivedListener 在 Android“开发版本”中工作,但不适用于“发布”版本

问题描述 投票:0回答:1

我的代码与here基本相同。 我正在关闭应用程序的情况下进行测试,点击收到的通知。在生产应用程序中未命中 addNotificationResponseReceivedListener 下注册的函数。点击通知会导致应用程序启动(进入前台),但不会调用已注册的通知侦听器。

我将代码移至 App 组件,行为是相同的。

“开发构建”是使用以下方式完成的:

eas build --profile development --platform android

“发布”构建是使用以下命令完成的:

eas build -p android

我的eas.json看起来像:

{
  "cli": {
    "version": ">= 3.7.2",
    "appVersionSource": "local"
  },
  "build": {
    "development": {
      "developmentClient": true,
      "distribution": "internal",
      "ios": {
        "resourceClass": "m1-medium"
      }
    },
    "preview": {
      "distribution": "internal",
      "ios": {
        "resourceClass": "m1-medium"
      }
    },
    "production": {
      "autoIncrement": false,
      "ios": {
        "resourceClass": "m1-medium"
      }
    }
  },
  "submit": {
    "production": {}
  }
}

我的app.json(我删除了一些数据,用“...”替换):

{
  "expo": {
    "name": "...",
    "slug": "...",
    "version": "1.0.25",
    "orientation": "default",
    "icon": "./assets/big-head.png",
    "userInterfaceStyle": "light",
    "splash": {
      "image": "./assets/big-head.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": [
      "**/*"
    ],
    "ios": {
      "buildNumber": "4",
      "supportsTablet": true,
      "config": {
        "usesNonExemptEncryption": false
      },
      "infoPlist": {
        "NSFaceIDUsageDescription": "Allow $(PRODUCT_NAME) to use Face ID."
      }
    },
    "android": {
      "versionCode": 36,
      "adaptiveIcon": {
        "foregroundImage": "./assets/big-head.png",
        "backgroundColor": "#FFFFFF"
      },
      "package": "...",
      "permissions": [
        "android.permission.CAMERA",
        "android.permission.RECORD_AUDIO",
        "android.permission.USE_BIOMETRIC",
        "android.permission.USE_FINGERPRINT"
      ],
      "googleServicesFile": "./google-services.json"      
    },
    "web": {
      "favicon": "./assets/favicon.png",
      "bundler": "metro"
    },
    "extra": {
      "eas": {
        "projectId": "..."
      }
    },
    "plugins": [
      [
        "expo-camera",
        {
          "cameraPermission": "Allow $(PRODUCT_NAME) to access your camera."
        }
      ],
      [
        "expo-local-authentication",
        {
          "faceIDPermission": "Allow $(PRODUCT_NAME) to use Face ID."
        }
      ],
      [
        "expo-document-picker",
        {
          "iCloudContainerEnvironment": "Production"
        }
      ],
      "expo-localization",
      "expo-secure-store",
      [
        "expo-notifications",
        {
          "icon": "./assets/big-head.png",
          "color": "#ffffff"
        }
      ]
    ],
    "owner": "...",
    "scheme": "..."
  }
}

我最好的猜测是我在“发布”配置中遗漏了一些内容,但我不知道。据说我遵循了文档中的所有步骤(https://docs.expo.dev/versions/latest/sdk/notifications/#usage),它按预期在开发模式下工作。 我做的唯一不同的事情是不在 App.js 中挂钩侦听器,而是在其始终处于打开状态的直接子组件 Main.js 中挂钩...

android react-native push-notification expo eas
1个回答
0
投票

经过大量测试和构建(并在 Expo 的免费队列中等待...)看起来唯一能按预期工作的是 useLastNotificationResponse() 挂钩。

提供的示例(参见此处)既可以在开发版本中使用,也可以在生产版本中使用,并对点击通知做出反应。

无论如何,这个答案看起来更像是一个解决方法,而不是一个好的答案,因为......

...为什么这些听众没有被召唤...?

© www.soinside.com 2019 - 2024. All rights reserved.