1

我是 vue-native 和 vuejs 的新手,想和他们一起做一个应用程序。我想向应用程序添加推送通知。我使用教程添加推送通知并对其进行测试,但出现此错误

创建钩子时出错:“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>

我哪里错了?

4

0 回答 0