首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >世博会推送令牌没有在android独立应用程序中创建。

世博会推送令牌没有在android独立应用程序中创建。
EN

Stack Overflow用户
提问于 2021-12-24 22:53:38
回答 1查看 630关注 0票数 0

我试着解决这个问题很长时间了,但没有什么效果,ExpopushToken不是在安卓独立应用程序中创建的,而它在ios中运行时是预期的。我按照文档的字面意思,用无限制的google云平台键创建了所需的所有东西,键不是自动创建的,我创建了一个令牌,在那里我应该将用户数据保存为android中的空字符串。

代码完全取自文档,google-services文件就像主根目录中提到的那样被添加,并上传到服务器上。

代码语言:javascript
复制
const registerForPushNotificationsAsync = async () => {
    let token;
    if (Constants.isDevice) {
      const { status: existingStatus } =
        await Notifications.getPermissionsAsync();
      let finalStatus = existingStatus;
      if (existingStatus !== "granted") {
        const { status } = await Notifications.requestPermissionsAsync();
        finalStatus = status;
      }
      if (finalStatus !== "granted") {
        alert("Failed to get push token for push notification!");
        return;
      }
      token = (await Notifications.getExpoPushTokenAsync()).data;
    } else {
      alert("Must use physical device for Push Notifications");
    }

    if (Platform.OS === "android") {
      Notifications.setNotificationChannelAsync("default", {
        name: "default",
        importance: Notifications.AndroidImportance.MAX,
        vibrationPattern: [0, 250, 250, 250],
        lightColor: "#FF231F7C",
      });
    }

    return token;
  };

  useEffect(() => {
    registerForPushNotificationsAsync().then((token) =>
      setExpoPushToken(token)
    );

    notificationListener.current =
      Notifications.addNotificationReceivedListener((notification) => {
        setNotification(notification);
      });

    responseListener.current =
      Notifications.addNotificationResponseReceivedListener((response) => {
        console.log(response, "response");
      });


    return () => {
      Notifications.removeNotificationSubscription(
        notificationListener.current
      );
      Notifications.removeNotificationSubscription(responseListener.current);
    };
  }, []);

在app.json中

代码语言:javascript
复制
"plugins": [
  [
    "expo-notifications",
    {
      "icon": "./assets/mainLogo.png",
      "color": "#ffffff",
      "sounds": [
        "./assets/notificationsound.wav",
        "./assets/notificationsoundothers.wav"
      ]
    }
  ],
  ["expo-image-picker"],
  ["expo-camera"]
],
"updates": {
  "fallbackToCacheTimeout": 0
},
"assetBundlePatterns": ["**/*"],
"notification": {
  "icon": "./assets/logo2.png",
  "color": "#e8e8e8",
  "iosDisplayInForeground": true,
  "androidMode": "collapse",
  "androidCollapsedTitle": "New Notification"
},

环境

博览会CLI4.12.0环境信息:系统: OS: Windows 10 10.0.22000二进制文件:节点: 14.16.1 -C:\ Files\nodejs\node.EXE Files\nodejs\npm.CMD npm: 6.14.12-C:\Files\nodejs\npm.CMD SDK: API级: 26,28,29,30个构建工具: 29.0.2,30.0.3系统图片: android-29 Google x86 Atom,Androd-29 Google Play Intel x86 Atom安卓-30谷歌API英特尔x86 Atom IDE: Android :Version4.1.0.0 AI-201.8743.12.41.7199119 npmPackages:~43.0.2 => 43.0.3 react: 17.0.1 => 17.0.1 react dom: 17.0.1 => 17.0.1 react原生: 0.64.3 => 0.64.3 react web: 0.17.1 => 0.17.1博览工作流:托管

EN

回答 1

Stack Overflow用户

发布于 2021-12-25 11:46:49

我想出了世博文档中可能传递给谁的问题。有人提到,您必须检查使用google-services.json文件下载的api密钥,并确保它是您的.它将不是您的,如果您更改为您的api密钥,它将无法工作。把它下载下来,它就能工作了

我在没有结果的情况下花了5天时间搜索后发现了这一点

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70476992

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档