简体   繁体   English

react-native expo 错误:未处理 promise 拒绝:TypeError:null 不是 object(正在评估“RNAlarmNotification.scheduleAlarm”)

[英]react-native expo error: Unhandled promise rejection: TypeError: null is not an object (evaluating 'RNAlarmNotification.scheduleAlarm')

I'm trying to use a notification package (react-native-alarm-notification) in my React Native project, but am running into some issues.我正在尝试在我的 React Native 项目中使用通知 package (react-native-alarm-notification),但遇到了一些问题。 After installing, trying to run scheduleAlarm() results in the following error:安装后,尝试运行 scheduleAlarm() 会导致以下错误:

[Unhandled promise rejection: TypeError: null is not an object (evaluating 'RNAlarmNotification.scheduleAlarm')]. [未处理的 promise 拒绝:TypeError:null 不是 object(正在评估“RNAlarmNotification.scheduleAlarm”)]。

I'm not entirely certain what the issue is, as the 'required' parameters of scheduleAlarm are filled and I am uncertain as to what null object is throwing an error.我不完全确定问题是什么,因为 scheduleAlarm 的“必需”参数已填充,我不确定 null object 抛出的错误。 Attempting to fill every possible parameter in scheduleAlarm still returns with null, as does giving only an alarm date and assuming default values are assigned.尝试在 scheduleAlarm 中填充每个可能的参数仍然会返回 null,就像只给出警报日期并假设已分配默认值一样。 Tracing the error location however shows the error coming from the regenerator-runtime and react-native modules that came from the default React project build, not from the notification package.然而,跟踪错误位置显示错误来自 regenerator-runtime 和来自默认 React 项目构建的 react-native 模块,而不是来自通知 package。

Does anyone have a solution to the problem?有没有人能解决这个问题?

Function.js: Function.js:

import { StatusBar } from 'expo-status-bar';
import React, {useState} from 'react';
import { StyleSheet, Text, View, TextInput, Button } from 'react-native';

import ReactNativeAN from 'react-native-alarm-notification';


export default function ShowTasks() {

  async function alarmTest(){
    console.log("Alarm test start");

    const fireDate = ReactNativeAN.parseDate(new Date(Date.now() + 10000));
    
    const alarmNotifData = {
      title: "My Notification Title",
      message: "My Notification Message",
      channel: "my_channel_id",
      small_icon: "../icon.png",
      scheduleType:"once",

      data: { foo: "bar" },
      fire_date:fireDate,
    };

    const alarm = await ReactNativeAN.scheduleAlarm({...alarmNotifData});

    console.log("Alarm test finish");
  }

  return (
    <View>
      <Button onPress={() => {alarmTest();}} 
        title= 'Click here to test alarm.'>
      </Button>
      <StatusBar style="auto" />
    </View>
  
  );
}

Rebuilding the App solved my issue:重建应用程序解决了我的问题:

npx react-native run-android

For android, the package will be linked automatically on the build.对于 android,package 将在构建时自动链接。 but if it doesn't then You need to link it manually.但如果没有,则您需要手动链接它。

Make following changes:进行以下更改:

android/app/src/main/java//MainApplication.java android/app/src/main/java//MainApplication.java

add import com.emekalites.react.alarm.notification.ANPackage; on the imports section
add packages.add(new ANPackage()); in List<ReactPackage> getPackages();

android/app/build.gradle android/应用程序/build.gradle

add implementation project(':react-native-alarm-notification') in the dependencies block

android/settings.gradle机器人/设置.gradle

add:添加:

include ':react-native-alarm-notification'
project(':react-native-alarm-notification').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-alarm-notification/android')

Checkout the documentation here此处查看文档

暂无
暂无

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

相关问题 react-native 错误:[未处理的 promise 拒绝:错误:获取 Expo 令牌时遇到错误:TypeError:网络请求失败。] - react-native error:[Unhandled promise rejection: Error: Error encountered while fetching Expo token: TypeError: Network request failed.] 未处理的 promise 拒绝:TypeError: undefined is not an object(评估 '_context.t0.data.error')在 expo - Unhandled promise rejection: TypeError: undefined is not an object (evaluating '_context.t0.data.error') in expo React Native:未处理的promise promise:TypeError:undefined不是对象(评估&#39;response.json&#39;) - React Native: Unhandled promise rejection: TypeError: undefined is not an object (evaluating 'response.json') 反应本地可能未处理的诺言拒绝 - Possible unhandled promise rejection in react-native React Native:可能的未处理的承诺拒绝(id:0):TypeError:undefined不是对象 - React Native: Possible Unhandled Promise Rejection (id: 0): TypeError: undefined is not an object Expo:未处理的 promise 拒绝:TypeError:未定义不是 object(评估“props.navigation”)] - Expo: Unhandled promise rejection: TypeError: undefined is not an object (evaluating 'props.navigation')] 反应原生:未处理的承诺拒绝:类型错误:未定义不是对象 - React native: Unhandled promise rejection: TypeError: undefined is not an object Axios 承诺处理 - 在 react-native 中获取“可能未处理的承诺拒绝 - 类型错误:网络请求失败” - Axios Promise Handling - Getting “Possible Unhandled Promise Rejection - TypeError: Network request failed” in react-native 未处理的承诺拒绝:TypeError:未定义不是一个函数,当在react native中为setState映射时会发生&#39;departureloc.map&#39;评估 - Unhandled promise rejection: TypeError: undefined is not a function evaluating 'departureloc.map' occurs when mapping for setState in react native [未处理的承诺拒绝:TypeError: null is not an object (evaluating &#39;_reactNativeImageCropPicker.default.openPicker&#39;)] - [Unhandled promise rejection: TypeError: null is not an object (evaluating '_reactNativeImageCropPicker.default.openPicker')]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM