ionic-team / capacitor-plugins

Official plugins for Capacitor ⚡️
518 stars 583 forks source link

LocalNotifications Documentation isn't clear to me #836

Open ArturoBarrios opened 2 years ago

ArturoBarrios commented 2 years ago

Using Capacitor V3 According to documentation the following will schedule a local notification. 0 examples on how to do this in JS. How do you initialize LocalNotifications? Nothing on this in docs and all the examples I see on the web are using V2. Please if you can help that would be amazing.

LocalNotifications.schedule({ notifications: [ { title: "Settings", body: "test body message", id: 1, schedule: { at: new Date(Date.now()) }, } ] })

ArturoBarrios commented 2 years ago

V2 documentation was clear about how to initialize LocalNotification:

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

const notifs = await LocalNotifications.schedule({ notifications: [ { title: 'Title', body: 'Body', id: 1, schedule: { at: new Date(Date.now() + 1000 * 5) }, sound: null, attachments: null, actionTypeId: '', extra: null, }, ], });`

ArturoBarrios commented 2 years ago

when I try to build it errors out, obviously because I'm not importing the right libraries and I'm not initializing LocalNotification.

`'default' is not exported by node_modules/@capacitor/local-notifications/dist/esm/index.js, imported by src/routes/connect/index.svelte file: /Users/arturobarrios/Documents/livelyme-symptom-tracker-website/packages/app/src/routes/connect/index.svelte:4:8 2: import BackCancelHeader from '$lib/components/BackCancelHeader/index.svelte'; 3: import ExpandableCard from '$lib/components/ExpandableCard/index.svelte'; 4: import LocalNotifications from "@capacitor/local-notifications"; ^ 5: 6: LocalNotifications.schedule({

'default' is not exported by node_modules/@capacitor/local-notifications/dist/esm/index.js, imported by src/routes/connect/index.svelte at error (/Users/arturobarrios/Documents/livelyme-symptom-tracker-website/packages/app/node_modules/rollup/dist/shared/rollup.js:158:30) at Module.error (/Users/arturobarrios/Documents/livelyme-symptom-tracker-website/packages/app/node_modules/rollup/dist/shared/rollup.js:12423:16) at Module.traceVariable (/Users/arturobarrios/Documents/livelyme-symptom-tracker-website/packages/app/node_modules/rollup/dist/shared/rollup.js:12808:29) at ModuleScope.findVariable (/Users/arturobarrios/Documents/livelyme-symptom-tracker-website/packages/app/node_modules/rollup/dist/shared/rollup.js:11588:39) at FunctionScope.findVariable (/Users/arturobarrios/Documents/livelyme-symptom-tracker-website/packages/app/node_modules/rollup/dist/shared/rollup.js:6953:38) at ChildScope.findVariable (/Users/arturobarrios/Documents/livelyme-symptom-tracker-website/packages/app/node_modules/rollup/dist/shared/rollup.js:6953:38) at MemberExpression.bind (/Users/arturobarrios/Documents/livelyme-symptom-tracker-website/packages/app/node_modules/rollup/dist/shared/rollup.js:9181:49) at CallExpression.bind (/Users/arturobarrios/Documents/livelyme-symptom-tracker-website/packages/app/node_modules/rollup/dist/shared/rollup.js:5076:23) at CallExpression.bind (/Users/arturobarrios/Documents/livelyme-symptom-tracker-website/packages/app/node_modules/rollup/dist/shared/rollup.js:9425:15) at ExpressionStatement.bind (/Users/arturobarrios/Documents/livelyme-symptom-tracker-website/packages/app/node_modules/rollup/dist/shared/rollup.js:5076:23 `

izeryab commented 2 years ago

You can use Local Notification in Capacitor version 3: import { LocalNotifications } from '@capacitor/local-notifications';

scheduleNotification(){
LocalNotifications.schedule({
  notifications:[
    {
      title:'Friendly Remainder',
      body:'Join the twinker family',
      id:2,
      extra:{
        data:'pass your data handler',

      },
      iconColor:'#0000FF',
      actionTypeId:'Chat_msg'
    }
  ]
})
 }

You can refer to official test-app of capacitor plugins : Here