我是vue-native和vuejs的新手,想与他们一起创建一个应用程序。我想向应用程序添加推送通知。我使用this教程来添加推送通知并对其进行测试,但出现此错误
创建的挂钩中出现错误:“ TypeError: this.registerForPushNotificationsAsync不是一个函数。 (在 'this.registerForPushNotificationsAsync()', 'this.registerForPushNotificationsAsync'未定义)“
我在app.vue文件中像这样在我的项目中添加这段代码
<template>
<view class="container">
<text class="text-color-primary">{{JSON.stringify(notification.data)}}</text>
</view>
</template>
<script>
export default {
data: function() {
return {
notification: {}
};
},
created: function() {
this.registerForPushNotificationsAsync();
this._notificationSubscription = Notifications.addListener(
this._handleNotification
);
},
methods:{
_handleNotification: function(notification) {
this.notification = notification;
},
registerForPushNotifications: async function() {
const { status: existingStatus } = await Permissions.getAsync(
Permissions.NOTIFICATIONS
);
let finalStatus = existingStatus;
// only ask if permissions have not already been determined, because
// iOS won't necessarily prompt the user a second time.
if (existingStatus !== "granted") {
// Android remote notification permissions are granted during the app
// install, so this will only ask on iOS
const { status } = await Permissions.askAsync(
Permissions.NOTIFICATIONS
);
finalStatus = status;
}
// Stop here if the user did not grant permissions
if (finalStatus !== "granted") {
return;
}
// Get the token that uniquely identifies this device
Notifications.getExpoPushTokenAsync().then(token => {
console.log(token);
});
}
}
};
</script>
我哪里出错了?