TypeError: undefined is not an object (evaluating 'details.date.getTime')
TypeError: undefined is not an object (evaluating 'details.date.getTime')
我使用 https://github.com/zo0r/react-native-push-notification 来显示通知,在我的例子中,我使用带有日期时间选择器的预定通知。我之前在另一个项目中使用过它并且它工作正常没有错误,但是在这个项目中我得到 TypeError: undefined is not an object (evaluating 'details.date.getTime') 在设置后按下确认后出现这个错误时间等等
notifSchedule = (todo, date) => {
PushNotification.localNotificationSchedule({
id: todo.id,
message: todo.title,
date,
allowWhileIdle: true,
priority: 'high',
});
};
这正是我在另一个项目中所做的,所以它应该可以工作。唯一不同的是我现在使用 class 组件,而在另一个项目中仅使用函数。
当我使用日期时:new Date(Date.now() + 60 * 1000), // 在 60 秒内而不是日期,它甚至不会触发任何事情。
编辑2:
完整的错误信息
Possible Unhandled Promise Rejection (id: 3):
TypeError: undefined is not an object (evaluating 'details.date.getTime')
localNotificationSchedule@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:129002:38
notifSchedule
handleChange@http://10.0./index.bundle?platform=android&dev=true&minify=false:129538:16
resolve@http://10.81/index.bundle?platform=android&dev=true&minify=false:129662:19
tryCallOne@http://181/index.bundle?platform=android&dev=true&minify=false:27056:16
http://10.81/index.bundle?platform=android&dev=true&minify=false:27157:27
_callTimer@http://881/index.bundle?platform=android&dev=true&minify=false:30596:17
_callImmediatesPass@http://10.081/index.bundle?platform=android&dev=true&minify=false:30635:17
callImmediates@http://1081/index.bundle?platform=android&dev=true&minify=false:30852:33
__callImmediates@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:2736:35
http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:2522:34
__guard@http://1801/index.bundle?platform=android&dev=true&minify=false:2719:15
flushedQueue@http://1081/index.bundle?platform=android&dev=true&minify=false:2521:21
flushedQueue@[native code]
invokeCallbackAndReturnFlushedQueue@[native code]
传入的 date
参数可能未定义。调试确切传递给 localNotificationSchedule
的内容,这可能是由您在组件生命周期
中犯的一些错误引起的
正如您所说,您正在使用基于 class 的组件,所以我想补充一点,请确保您正确绑定函数,否则它将无法工作。 Class 基于函数需要函数绑定,函数自己完成。有时值似乎是未定义的,因为您没有正确地接近它们。
或
调试要从中提取日期的详细信息或这样做
console.log(details); //if undefined do some action to fill it
details && details.date.getTime; //for conditional rendering
确保您的日期格式符合函数要求,然后使用:date: date
notifSchedule = (todo, date) => {
PushNotification.localNotificationSchedule({
id: todo.id,
message: todo.title,
date: date,
allowWhileIdle: true,
priority: 'high',
});
};
我通过删除待办事项并仅让 (date) 工作来自行修复 (todo, date),
我使用 https://github.com/zo0r/react-native-push-notification 来显示通知,在我的例子中,我使用带有日期时间选择器的预定通知。我之前在另一个项目中使用过它并且它工作正常没有错误,但是在这个项目中我得到 TypeError: undefined is not an object (evaluating 'details.date.getTime') 在设置后按下确认后出现这个错误时间等等
notifSchedule = (todo, date) => {
PushNotification.localNotificationSchedule({
id: todo.id,
message: todo.title,
date,
allowWhileIdle: true,
priority: 'high',
});
};
这正是我在另一个项目中所做的,所以它应该可以工作。唯一不同的是我现在使用 class 组件,而在另一个项目中仅使用函数。
当我使用日期时:new Date(Date.now() + 60 * 1000), // 在 60 秒内而不是日期,它甚至不会触发任何事情。
编辑2: 完整的错误信息
Possible Unhandled Promise Rejection (id: 3):
TypeError: undefined is not an object (evaluating 'details.date.getTime')
localNotificationSchedule@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:129002:38
notifSchedule
handleChange@http://10.0./index.bundle?platform=android&dev=true&minify=false:129538:16
resolve@http://10.81/index.bundle?platform=android&dev=true&minify=false:129662:19
tryCallOne@http://181/index.bundle?platform=android&dev=true&minify=false:27056:16
http://10.81/index.bundle?platform=android&dev=true&minify=false:27157:27
_callTimer@http://881/index.bundle?platform=android&dev=true&minify=false:30596:17
_callImmediatesPass@http://10.081/index.bundle?platform=android&dev=true&minify=false:30635:17
callImmediates@http://1081/index.bundle?platform=android&dev=true&minify=false:30852:33
__callImmediates@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:2736:35
http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:2522:34
__guard@http://1801/index.bundle?platform=android&dev=true&minify=false:2719:15
flushedQueue@http://1081/index.bundle?platform=android&dev=true&minify=false:2521:21
flushedQueue@[native code]
invokeCallbackAndReturnFlushedQueue@[native code]
传入的 date
参数可能未定义。调试确切传递给 localNotificationSchedule
的内容,这可能是由您在组件生命周期
正如您所说,您正在使用基于 class 的组件,所以我想补充一点,请确保您正确绑定函数,否则它将无法工作。 Class 基于函数需要函数绑定,函数自己完成。有时值似乎是未定义的,因为您没有正确地接近它们。 或 调试要从中提取日期的详细信息或这样做
console.log(details); //if undefined do some action to fill it
details && details.date.getTime; //for conditional rendering
确保您的日期格式符合函数要求,然后使用:date: date
notifSchedule = (todo, date) => {
PushNotification.localNotificationSchedule({
id: todo.id,
message: todo.title,
date: date,
allowWhileIdle: true,
priority: 'high',
});
};
我通过删除待办事项并仅让 (date) 工作来自行修复 (todo, date),