Javascript null不是对象(计算';"指数通知.default.cancelAllScheduledNotificationsAsync';)反应本机
我在React本机应用程序和android emulator中评估通知时遇到此错误。CancelAllScheduledNotificationAsync() 错误堆栈Javascript null不是对象(计算';"指数通知.default.cancelAllScheduledNotificationsAsync';)反应本机,javascript,android,react-native,Javascript,Android,React Native,我在React本机应用程序和android emulator中评估通知时遇到此错误。CancelAllScheduledNotificationAsync() 错误堆栈 TypeError: null is not an object (evaluating '_ExponentNotifications.default.cancelAllScheduledNotificationsAsync') cancelAllScheduledNotificationsAsync@http://10.0
TypeError: null is not an object (evaluating '_ExponentNotifications.default.cancelAllScheduledNotificationsAsync')
cancelAllScheduledNotificationsAsync@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:110086:44
_callee$
tryCatch@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:26262:23
invoke@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:26438:32
tryCatch@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:26262:23
invoke@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:26338:30
http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:26368:19
tryCallTwo@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:27627:9
doResolve@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:27791:25
Promise@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:27650:14
callInvokeWithMethodAndArg@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:26367:33
enqueue@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:26372:157
async@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:26389:69
tryCallOne@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:27618:16
http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:27719:27
_callTimer@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:31173:17
_callImmediatesPass@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:31209:19
callImmediates@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:31428:33
callImmediates@[native code]
__callImmediates@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:3238:35
http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:3015:34
__guard@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:3221:15
flushedQueue@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:3014:21
flushedQueue@[native code]
invokeCallbackAndReturnFlushedQueue@[native code]
通知.js
import {Notifications} from 'expo'
import * as Permissions from 'expo-permissions';
import {AsyncStorage} from "react-native";
const notificationsKey = "@questions-flash-cards-key:notifications";
export function clearLocalNotifications() {
return AsyncStorage.removeItem(notificationsKey).then(() => Notifications.cancelAllScheduledNotificationsAsync())
}
const notification = {
title: "You forgot solving quiz today.",
body: "Answer quiz per day to improve yourself.",
ios: {
sound: true
},
android: {
sound: true,
vibrate: true,
},
};
export async function setLocalNotification() {
const {status} = await Permissions.getAsync(Permissions.NOTIFICATIONS);
if (status !== 'granted') {
await Permissions.askAsync(Permissions.NOTIFICATIONS);
}
AsyncStorage.getItem(notificationsKey).then(JSON.parse).then(async (data) => {
if (data === null) {
Notifications.cancelAllScheduledNotificationsAsync().then(() => {
let tomorrow = new Date(Date.now());
tomorrow.setDate(tomorrow.getDate() + 1);
tomorrow.setHours(12);
tomorrow.setMinutes(0);
Notifications.scheduleLocalNotificationAsync(notification, {
time: tomorrow, repeat: "day"
})
})
}
})
}
您是否尝试重新编译该应用程序?@CevaComic是,没有任何更改当库未正确链接到您的项目时,通常会发生这种情况。但你在使用expo,所以一切都应该正常。但是但是,请检查此链接:,此模块在android emulator上尚不受支持:)),对不起。@CevaComic我已看到此页面,并且不支持推送通知
,我正在使用本地通知。@Joffan在您发布答案之前,我已用另一种方法解决了此问题,因此我将其删除。。但很抱歉,我将取消删除它