ionic-team / capacitor

Build cross-platform Native Progressive Web Apps for iOS, Android, and the Web ⚡️
https://capacitorjs.com
MIT License
12.04k stars 999 forks source link

bug: LocalNotification missing identifier #2980

Closed robertnicjoo closed 4 years ago

robertnicjoo commented 4 years ago

Bug Report

Capacitor Version

npx cap doctor output:

Latest Dependencies:

  @capacitor/cli: 2.1.0
  @capacitor/core: 2.1.0
  @capacitor/android: 2.1.0
  @capacitor/electron: 2.1.0
  @capacitor/ios: 2.1.0

Installed Dependencies:

  @capacitor/ios not installed
  @capacitor/cli 2.1.0
  @capacitor/core 2.1.0
  @capacitor/android 2.1.0

Affected Platform(s)

Current Behavior

I'm trying to receive local notifications but it returns this error:

LocalNotification missing identifier
    Error: LocalNotification missing identifier
        at Object.fromNative (capacitor-runtime.js:230:14)
        at <anonymous>:1:18

Expected Behavior

Receiving notifications.

Sample Code or Sample Application Repo

app.components.ts

import {
  Plugins,
  LocalNotificationScheduleResult, //here
  NetworkStatus,
  PluginListenerHandle,
  PushNotification,
  PushNotificationToken,
  PushNotificationActionPerformed } from '@capacitor/core';

export class AppComponent implements OnInit, OnDestroy {

  notifs: LocalNotificationScheduleResult; //here
  pendingNotifs: LocalNotificationScheduleResult; //here

  constructor(...){...}

  async ngOnInit() {
    // local notifications
    await Plugins.LocalNotifications.requestPermissions();
    try {
      Plugins.LocalNotifications.addListener('localNotificationReceived', (notification) => {
        console.log('Notification: ', notification);
      });

      Plugins.LocalNotifications.addListener('localNotificationActionPerformed', (notification) => {
        console.log('Notification action performed', notification);
      });

    } catch (e) {
      console.log(e);
    }
  }

myTab.page.ts that pushes notifications

import { Plugins } from '@capacitor/core';
const { Toast } = Plugins;

ngOnInit() {
  this.socket.fromEvent('message').subscribe(async (message: any) => {
    // notif (should push notifications)
      const notifs = await Plugins.LocalNotifications.schedule({
        notifications: [
          {
            title: 'Local Notifications',
            body: message.msg.message,
            id: message.msg.id,
            schedule: { at: new Date(Date.now() + 1000 * 2) },
            sound: 'beep.aiff',
            attachments: null,
            actionTypeId: 'OPEN_CHAT',
            extra: null
          }
        ]
      });
      console.log('scheduled notifications', notifs);
  });
}

Reproduction Steps

Other Technical Details

npm --version output: 6.9.0

node --version output: v12.5.0

pod --version output (iOS issues only):

Other Information

Any idea how to solve this issue?

jcesarmobile commented 4 years ago

can you provide a sample app?

robertnicjoo commented 4 years ago

can you provide a sample app?

thanks for responding, i tracked the error and found out it was referring to id value so i fixed that and I don't get that error anymore but the bigger issue is that I don't get notification at all! unless both users are online and in same chat then notifications will fire which is pointless, the whole purpose of having notification is to receive when user is in another page or app is closed fully.

any idea in that?

ps: about sample app I don't have any but even if i make fresh app for sample the code placement will be the same on app.components.ts and tab1.page.ts :/

jcesarmobile commented 4 years ago

No idea, but looks like a problem in your app. Closing since you fixed the id problem

ionitron-bot[bot] commented 1 year ago

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.