简体   繁体   English

react-native 错误:[未处理的 promise 拒绝:错误:获取 Expo 令牌时遇到错误:TypeError:网络请求失败。]

[英]react-native error:[Unhandled promise rejection: Error: Error encountered while fetching Expo token: TypeError: Network request failed.]

Error logs: [Unhandled promise rejection: Error: Error encountered while fetching Expo token: TypeError: Network request failed.]
* [native code]:null in construct
- node_modules\@babel\runtime\helpers\construct.js:19:9 in _construct
- node_modules\@babel\runtime\helpers\wrapNativeSuper.js:26:22 in Wrapper
* [native code]:null in construct
* http://192.168.1.4:19015/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&minify=false&hot=false:107658:321 in _createSuperInternal
- node_modules\@unimodules\react-native-adapter\build\errors\CodedError.js:8:8 in constructor
- node_modules\expo-notifications\build\getExpoPushTokenAsync.js:35:22 in fetch._catch$argument_0
- node_modules\promise\setimmediate\core.js:37:13 in tryCallOne
- node_modules\promise\setimmediate\core.js:123:24 in setImmediate$argument_0
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:135:14 in _callTimer
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:183:16 in _callImmediatesPass
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:446:30 in callImmediates
* [native code]:null in callImmediates
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:396:6 in __callImmediates
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:144:6 in __guard$argument_0
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:373:10 in __guard
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:143:4 in flushedQueue
* [native code]:null in flushedQueue
* [native code]:null in callFunctionReturnFlushedQueue

my code:我的代码:

  import Constants from "expo-constants";
    import * as Notifications from "expo-notifications";
    import * as Permissions from "expo-permissions";
    import React, { useState, useEffect, useRef } from "react";
    import { MainLayout } from "./src/MainLayout";
    //TODO import fonts
    /*var uuid = require('react-native-uuid');
    console.log(uuid.v4())*/
    
    export default function App() {
      registerForPushNotificationsAsync().then((token) => console.log(token));
      return <MainLayout />;
    }
    
    async function registerForPushNotificationsAsync() {
      let token;
      if (Constants.isDevice) {
        const { status: existingStatus } = await Permissions.getAsync(
          Permissions.NOTIFICATIONS
        );
        let finalStatus = existingStatus;
        if (existingStatus !== "granted") {
          const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
          finalStatus = status;
        }
        if (finalStatus !== "granted") {
          alert("Failed to get push token for push notification!");
          return;
        }
        token = (await Notifications.getExpoPushTokenAsync()).data;
        console.log(token);
      } 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;
    }

I wanted to implement a notification push mechanism, took the code from this site https://docs.expo.io/push-notifications/overview/我想实现一个通知推送机制,从这个网站https://docs.expo.io/push-notifications/overview/ 获取代码

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React Native 获取错误:“[未处理的 promise 拒绝:TypeError:网络请求失败]” - React Native fetch error: “[Unhandled promise rejection: TypeError: Network request failed]” Axios 承诺处理 - 在 react-native 中获取“可能未处理的承诺拒绝 - 类型错误:网络请求失败” - Axios Promise Handling - Getting “Possible Unhandled Promise Rejection - TypeError: Network request failed” in react-native 当我发出 Post 请求时,React Native 返回 [未处理的承诺拒绝:类型错误:网络请求失败] - React Native returns [Unhandled promise rejection: TypeError: Network request failed] when I'm making a Post Request 反应原生的未处理承诺拒绝错误? - Unhandled promise rejection error in react native? React Native:可能未处理的承诺拒绝(id:0)TypeError:网络请求失败 - React Native: Possible unhandled promise rejection (id: 0) TypeError: Network request failed React-Native:未处理的 promise 拒绝:错误:对象作为 React 子对象无效 - React-Native: Unhandled promise rejection: Error: Objects are not valid as a React child Infura React Native Expo 未处理的承诺拒绝:错误:在 sendTransaction 上缺少响应 - Infura React Native Expo Unhandled promise rejection: Error: missing response on sendTransaction 未处理的 promise 拒绝:错误:数据库表错误:在本机反应中未定义 - Unhandled promise rejection: Error: Database Table error: undefined in react native React Native - [未处理的 promise 拒绝:错误:注册错误] - React Native - [Unhandled promise rejection: Error: Signup Error] 未处理的承诺拒绝:错误:网络错误 - Unhandled promise rejection: Error: Network Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM