ionic-team / capacitor

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

LocalNotifications does not have web implementation #1355

Closed cassiano-r closed 5 years ago

cassiano-r commented 5 years ago

Description of the problem:

ERROR Error: Uncaught (in promise): LocalNotifications does not have web implementation. at c (polyfills.js:3) at Function.t.reject (polyfills.js:3) at CapacitorWeb.pluginMethodNoop (web-runtime.js:31) at new HomePage (home.ts:76) at createClass (core.js:12449) at createDirectiveInstance (core.js:12284) at createViewNodes (core.js:13742) at createRootView (core.js:13631) at Object.createProdRootView [as createRootView] (core.js:14324) at ComponentFactory_.create (core.js:11236)

Affected platform

OS of the development machine

Other information:

Capacitor version:

node version:

npm version:

CocoaPods version:

Steps to reproduce:

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

//Schedule LocalNotifications.schedule({ notifications: [ { title: "Title", body: "Body", id: 1, schedule: { at: new Date(Date.now() + 1000 * 5) }, sound: null, attachments: null, actionTypeId: "", extra: null } ] });

Link to sample project:

cassiano-r commented 5 years ago

use ionic serve

rdlabo commented 5 years ago

Local Notifications support ios and android only, not support web(pwa). https://capacitor.ionicframework.com/docs/apis/local-notifications

You should try native build.

karol-depka commented 5 years ago

Hi. I think in principle it could be possible to implement this for web as well. What do You think? I would like to help implementing it.

Desktop notification could be done via new Notification(...). https://developer.mozilla.org/en-US/docs/Web/API/notification/Notification

Sound (if the one from Notification is not enough) could be done via new Audio(...). https://developer.mozilla.org/en-US/docs/Web/API/HTMLAudioElement

I would like to develop a proof-of-concept, but first, please let me know what You think.

karol-depka commented 5 years ago

I think I can make a PoC based on capacitor/core/src/web/toast.ts. Comments are welcome!

jcesarmobile commented 5 years ago

Sure, pull requests are always welcome

mlynch commented 5 years ago

Hey all, just pushed a very basic implementation of local notifications of the web: https://github.com/ionic-team/capacitor/blob/master/core/src/web/local-notifications.ts

What's missing is support for actions and all the different options for notifications, such as images and sound (though not sure that stuff is even possible).

@karol-depka if you'd like to expand on what I've built here that could be easier and also very welcome!