Local Notifications

Has anyone managed to get local notifications working? (Local notifications are identical to push notifications but are strictly local. The difference is push notifications send out the notification to all devices while local stays local).

I don’t have much experience with uno and couldn’t really get anything done for either iOS or Android

Hi Fudge, we haven’t made local notification support yet I’m afraid. It’ll certainly go on THE LIST though :slight_smile:

Thanks for posting.

+1 for me, would really love this right now.

The app I’m working on will be loading geo data on start. The app watches the user’s location, and I would love to send a notification when the user gets near one of the points in the geo data.

Hi Edwin,

You’ll be happy to know it made it’s way to to top of the list recently. It wont be in next week’s release as api freeze for that release is happening today. However progress looks good, and I’ll probably take some more time this week to work on it.

I’ll keep you posted, and it’ll definitely be mentioned in slack community when it’s ready :slight_smile:

Thanks for posting!

@chris thanks this is so awesome, I love how fast you guys work, and I’m assuming this will be through javascript, and perhaps the notification designed through ux? or perhaps a default template, which we just pass an object literal as options for that default markup?

That’s really great to hear! Been waiting for this!

Hey folks!

I’m writing documentation for this feature today. Like with Push Notifications we are starting with a minimal api and working up so we can keep things clean and user driven. Here is an example Fuse program using Local Notifications

<App Theme="Basic" ClearColor="1, 1, 1, 1">
    <FuseJS.LocalNotify ux:Global="LocalNotify" />
    <JavaScript>
        var LocalNotify = require("LocalNotify");

        function sendNow() {
            LocalNotify.now("Boom!", "Just like that", "payload", true);
        }

        function sendLater() {
            LocalNotify.later(4, "Finally!", "4 seconds is a long time", "hmm?", true);
        }

        LocalNotify.onReceivedMessage = function(payload) {
            console.log ("Recieved Local Notification: " + payload);
        };

        module.exports = {
            sendNow: sendNow,
            sendLater: sendLater
        };
    </JavaScript>
    <DockPanel>
        <TopFrameBackground DockPanel.Dock="Top" />
        <ScrollViewer>
            <StackPanel>
                <Button Clicked="{sendNow}" Text="Send notification now" Height="60"/>
                <Button Clicked="{sendLater}" Text="Send notification in 4 seconds" Height="60"/>
            </StackPanel>
        </ScrollViewer>
        <BottomBarBackground DockPanel.Dock="Bottom" />
    </DockPanel>
</App>

Coming soon to a release near you :slight_smile:

This looks perfect and simple, which is exactly what I was hoping for. Thanks a lot for the update

Awesome, but I honestly don’t like those multiple parameters like that. I prefer a one object for params:

LocalNotify.now({
  text: "Boom!",
  text2: "Just like that",
  type: "payload",
  bool: true
})

As you can see idk what to name those properties because I can’t tell, so if you could make it where the object has to have specific name properties then that’d be more awesome and I don’t have to remember what order which parameter goes etc.

Plus we get to take advantage of destructuring in ES6 and more.

Above I chose text and text2 because I have no idea what those paremeters stand for, same thing for type I just thought it’d be a type. Same thing for the last boolean not sure what that parameter sets. So I think you get my point however.

Now for the later method you can just have the first parameter be a timeout, and the rest for options:

LocalNotify.later(4, {
  text : "Finally!",
  text2: "4 seconds is a long time",
  type: "hmm?",
  bool: true
});

See now payload is now hmm? so I’m assuming its not even a type

Or just have all parameters in the object:

LocalNotify.later({
  timeout: 4,
  text : "Finally!",
  text2: "4 seconds is a long time",
  type: "hmm?",
  bool: true
});

For the event handler:

Keep the onReceievedMessage property as a event handler but also have a Promise based one:

LocalNotify.receievedMessage.then(function(payload) {
  console.log ("Recieved Local Notification: " + payload);
});

Where receivedMessage is a Promise. Again Promises is not just about style of code, and too long for me to explain here, but on the Fuse team side I’m sure it can be done

Another thing is optional Buttons, which could easily be done like so:

LocalNotify.now({
 ...,
 buttons: ['one', 'two', 'three, ...] // with a maximum I suppose
}).then(function(buttonText) {
 if(buttonText === 'one') {
   // do something
 } else if(buttonText === 'two') {

 }
 ...
})

As you can see the argument passed buttonText would be a string of which button was clicked, and null if none were pressed. Like if the notification was dismissed

Also another parameter may be a persistive property, and Fuse could allow up to only 1 persistive notification, because that can get really annoying.

All of this is very cool thanks! We will definitely look at this when deciding what goes into v2 of the feature.

We can’t have a promise returned from the notify function as the app may have been closed before the notification fires. Even in the case of now as it is up to the system when it fires the notification in that case. Ive seen it take up to 3 seconds on some android devices. Android is odd like that :slight_smile:

We can definitely pass back button info in the message though.

Also an image option would be really useful, I may want to show a different image for different types of notification, and perhaps a different sound as well:

LocalNotify.now({
  image: 'Assets/notificationIcon.png',
  sound: 'Assets/sound.mp4'
});

Defintitely :slight_smile:

This doesn’t have to do with Fuse, but as you can see what I had in mind for the API, with this example: http://nickersoft.github.io/push.js/ (Simple and clean)

Hey Chris the icon for the notifications shows up inside a circle for me, any idea why? or is this a bug? if it is, is it possible to fix that for the release of 0.20

Hi everybody,

I’m trying to use this LocalNotification feature on my app following the documentation to notify when the geo-localization is not enabled:

var LocalNotify = require("FuseJS/LocalNotifications");

GeoLocation.getLocation(500).then(
        function(currentLocation) {
		console.log("INFO: " + currentLocation.latitude + ", " + currentLocation.longitude);
	}).catch(function(fail) {
		console.log("ERROR: getLocation fail " + fail);
		LocalNotify.now("Geo-Location disabled", "Please enable the geo-location service", "payload", true);
	}); 

When the location service is disabled, the ERROR string is logged but no notification is not displayed.
I’m testing iton a Google Nexus 5X device.

Thanks in advance for the support!

Hi Andrea,

instead of reviving old threads, please post new ones with complete, minimal reproductions.

As for the question itself, a notification is not supposed to be visible (i.e. added to notification tray) when your app is in the foreground.

Hi Uldis,

ok got it.

Thanks!