I'm having problems with notifications in my app.
I've seen some pages reference to the AlarmAPI in Firefox OS and how to handle notifications:
https://developer.mozilla.org/en-US/docs/WebAPI/Alarm
https://developer.mozilla.org/en-US/Apps/Developing/Control_the_display/Using_Alarms_to_notify_users
http://rootslabs.net/blog/199-firefox-os-dev-tips-2
The code is basically the same in both cases and it only works when my app is open or in background. If I close my app it doesn't show notifications. I've tested the example app from the second link and it works when the app is closed.
What could the problem be and how can I fix it?
Thanks.
you must use navigator.mozSetMessageHandler()
https://developer.mozilla.org/en-US/docs/Web/API/Navigator.mozSetMessageHandler
if(navigator.mozSetMessageHandler) {
navigator.mozSetMessageHandler("alarm", function (alarm) {
// only launch a notification if the Alarm is of the right type for this app
if(alarm.data.task) {
// Create a notification when the alarm is due
new Notification("Your task " + alarm.data.task + " is now due!");
updateNotified(alarm.data.task);
}
});
}
Related
I am developing an electron + ionic application and using electron notifications. I have packaged the application using electron builder and installed it on my PC. The notification comes with the text 'electron.app.Electron' instead of the app name from the package. This is the sample notification code:
click: function() {
const notification = {
title: 'Basic Notification',
body: 'Notification from the Main process',
icon:path.join(__dirname, 'favicon.ico'),
silent : false
}
new Notification(notification).show()
}
How can I get the notification to display the app name instead of electron.app.Electron? When I used the tray displayBalloon option instead, it displayed the name correctly but unfortunately, it's not supported in Mac and I had to shift to using electron notification.
Please have a look at these two answers to more or less the same question:
Electron app notification states the app sending notification is electron.app.<App Name> even after packaging
how can you overwrite or remove the signature “electron.app.Electron” from the desktop notification
Basically, you need to call app.setAppUserModelId() on Windows:
if (process.platform === 'win32')
{
app.setAppUserModelId(app.name);
}
I have a finished application which I would like to make available to run on the iOS and Android platforms. I have tested the application as much as possible and it works without problem. But I know there is always the chance that something might go wrong and I could get an exception.
My question is how can I deal with this or what should I do. What happens on the phone, if a Forms application is deployed and there is an exception.
Would appreciate any advice or even links as to how this is handled.
If an exception is thrown and not handled by your code, the app will stop working (i.e. crash).
In order to handle these crashes we are using MS AppCenter (the successor to HockeyApp/Xamarin AppInsights).
You'll have to create a project there (one for each platform), and add the NuGet package to your projects. Afterwards you can initialize it with
AppCenter.Start("ios={Your App Secret};android={Your App Secret}",
typeof(Crashes)); // you'll get the app secrets from appcenter.ms
Crashes will be logged to AppCenter now and you'll be informed whenever there is a new crash.
Please note that it's best practice (if not required by law), that you ask the user for consent before sending the crash report (see here). You are using the delegate Crashes.ShouldAwaitUserConfirmation for that matter. You could for example show an action sheet with Acr.UserDialogs
private bool AwaitUserConfirmation()
{
// you should of course use your own strings
UserDialogs.Instance.ActionSheet(
new ActionSheetConfig
{
Title = "Oopsie",
Message = "The app crashed. Send crash to developers.",
Options = new List<ActionSheetOption>
{
new ActionSheetOption("Sure", () => Crashes.NotifyUserConfirmation(UserConfirmation.Send)),
new ActionSheetOption("Yepp, and don't bug be again.", () => Crashes.NotifyUserConfirmation(UserConfirmation.AlwaysSend)),
new ActionSheetOption("Nope", () => Crashes.NotifyUserConfirmation(UserConfirmation.DontSend))
}
});
return true;
}
Im creating an Electron app. I save the user progress in a file. I want the app to show the usual 'Save changes before closing' when the user has not saved and tries to close the App.
I could show a custom dialog, however, I would want to do it the native way.
(Example: On macOS, when you edit a file, the red button changes, letting know the user that the app has unsaved content)
I know this has to be done probably inside the Electron's listener for a closing app:
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
... preventing quit() from being called. And instead handling the unsaved file state and dialog.
PD: I already handle the logic to know whether the user has saved its progress or not. I just want to know how to set the 'Unsaved' state to my electron app and correctly handle it.
(The example is Visual Studio Code, which is also an Electron App)
I usually use a global variable to indicate changes had occured and for example in the case of closing the app:
Code in the main:
mainWindow.on('close', function (event) {
if (global.savetoask== 'Yes') {
event.preventDefault();
//send a ipc message to request a confirm dialog
.............
} else {
app.exit();
}
});
the push badge stays on the app what ever I did! even the push notification function well, and I do open the app normally, but the BADGE stay all time there and never goes away.
I did try this method below (which didn't help)
Titanium.UI.iPhone.appBadge = 0;
After reading your question I guess you want to reset the app badge displayed over your app icon. I think you are using Cloud.PushNotifications to send push notification. If so it will store the number of badges on the ACS which will be updated each time you call the Cloud.PushNotifications.notify method and it will be set to app icon each time you receive the push.
To reset the badge in ACS try the following
Cloud.PushNotifications.resetBadge({
device_token: device_token //Give your device token here
}, function (e) {
if (e.success) {
Ti.UI.iPhone.setAppBadge(0); //Resetting the badge in device
}
else {
Ti.API.error(e);
}
});
Now when you receive a new notification the badge will be set to (depending upon the value of badge property in push payload received).
Hope it helped you.
I am using the pro library.
But I just found doc for free library
I cannot find any doc for pro version.
Also, I don't know how to implement the background mode even using the pro sample.
Here are the steps:
Build the pro sample project
start the iBeacon source(using iPad) and it can be detected
start the application and then press home button the make it in
background
Turn off the iBeacon source
Turn on the iBeacon source
However, more than 5 minutes, the application does not launch
So, can anyone verify the step I did?
How can I test the background mode more easily?
Also, for the BootstrapNotifier, is it just work only first time when the device reboot?
After that, even I put application in background, the application will not launch when it detect iBeacon?
Your testing method sounds fine. I think the issue is that the reference app for the pro library only auto launches the app on the first detection after boot. After that, it sends a notification instead, and tapping on that notification launches the app.
This is purely for demonstration purposes. You can change it to auto launch on every detection if you wish. Simply alter the haveDetectedIBeaconsSinceBoot logic in this code:
#Override
public void didEnterRegion(Region arg0) {
// In this example, this class sends a notification to the user whenever an iBeacon
// matching a Region (defined above) are first seen.
Log.d(TAG, "did enter region.");
if (!haveDetectedIBeaconsSinceBoot) {
Log.d(TAG, "auto launching MainActivity");
// The very first time since boot that we detect an iBeacon, we launch the
// MainActivity
Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// Important: make sure to add android:launchMode="singleInstance" in the manifest
// to keep multiple copies of this activity from getting created if the user has
// already manually launched the app.
this.startActivity(intent);
haveDetectedIBeaconsSinceBoot = true;
} else {
// If we have already seen iBeacons and launched the MainActivity before, we simply
// send a notification to the user on subsequent detections.
Log.d(TAG, "Sending notification.");
sendNotification();
}
}
The javadoc link was missing from the main documentation page when you posted this question. That is fixed now.