我有一个对象,其中有一些辅助函数,这些函数将根据时间安排通知。用户按下按钮安排通知后,我将在redux动作中调用该函数。
我收到错误消息“未定义不是对象(正在评估_'ScheduleNotification.default.startReminder')”
我尝试在按下按钮以及操作中调用它,两次都收到相同的错误。
我的日程通知对象-
let blurRadius = 6.0;
let asset = AVAsset.assetWithURL(streamURL);
let item = AVPlayerItem.alloc().initWithAsset(asset);
item.videoComposition = AVVideoComposition.videoCompositionWithAssetApplyingCIFiltersWithHandler(asset, request => {
let blurred = request.sourceImage.imageByClampingToExtent().imageByApplyingGaussianBlurWithSigma(blurRadius);
let output = blurred.imageByClampingToRect(request.sourceImage.extent);
request.finishWithImageContext(output, null);
});
然后在我要调用该函数的地方执行操作-
export const scheduleNotification = {
startReminder: {
async function(item) {
const permission = await registerForPushNotificationsAsync();
if (permission) {
Notifications.scheduleLocalNotificationAsync(
{
title: 'Reminder:',
body: `${item.text} now`
},
{
time: item.date
}
);
} else {
console.log('cannot send notification without permission.');
}
}
},
}
不是按预定的通知时间,而是按下按钮,而是显示错误消息。如果需要,我可以提供更多代码。谢谢您的帮助。
答案 0 :(得分:2)
您已将scheduleNotification.startReminder
做成一个具有一个属性的对象-一个未命名的函数。您的代码中花括号过多。您想要的可能是这样:
export const scheduleNotification = {
async startReminder(item) {
const permission = await registerForPushNotificationsAsync();
if (permission) {
Notifications.scheduleLocalNotificationAsync({
title: 'Reminder:',
body: `${item.text} now`
}, {
time: item.date
});
} else {
console.log('cannot send notification without permission.');
}
},
}