NativeScript - how to decrement application icon badge number for iOS - javascript

Using Nativescript I want to be able to decrement the icon badge number when specific actions are done in the app.
I've started with this code (example):
if (app.ios) {
app.getNativeApplication().applicationIconBadgeNumber = 5;
}
I've read that for iOS 10+ I need to get an authorization from the UNUserNotificationCenter. I tried using an app delegate when the app starts to ask for the authorization and it doesn't seem like I can have access to the authorization class from Nativescript.
I tried looking for plugins and can't seem to find any ...
If anyone knows how I could access the Authorization api or even deal with icon badge update from NativeScript it would be appreciated.

You could use the nativescript-local-notifications for requesting permissions.

I made some progress, in my AppDelegate I updated to:
appDelegate.prototype.applicationDidFinishLaunchingWithOptions = function (application, launchOptions) {
var center = coreUtils.ios.getter(UNUserNotificationCenter, UNUserNotificationCenter.currentNotificationCenter);
center.delegate = this;
const authorizationOptions = UNAuthorizationOptions.Badge;
center.requestAuthorizationWithOptionsCompletionHandler(authorizationOptions, (granted, error) => {
if(!error) {
application.applicationIconBadgeNumber = 5;
} else {
console.log("Error", error);
}
});
Now the problem is that when I open the app, the applicationIconBadgeNumber gets set to 0. I was able to test that by putting an event listener on the applicationDidEnterBackground event and setting applicationIconBadgeNumber to 5. I was then able to see the badge icon. Now I have to figure out why the applicationIconBadgeNumber gets set to 0 on app open.

Related

Disable/Enable ApplicationInsights Telemetry dynamically

I implemented Application Insigths in the frontend applciation and I want to disable/enable it based on a variable that can change over the lifetime of the applications. (e.g. user declined Application Insights consent => Disable Telemetry)
What I tried is:
appInsights.appInsights.config.disableTelemetry = true
however if I try to enable it back setting disableTelemetry =false this is not working anymore.
Is anything else that I need to make to persist this change or is there another way of doing this?
You could use a telemetry filter for that:
var filteringFunction = (envelope) => {
if (condition) {
return false; // Do not send telemetry
}
return true; // Do send the telemetry
};
Register the filter like this:
appInsights.addTelemetryInitializer(filteringFunction);
While Peter's answer is correct, I have different approach where instead of using telemetry filters we can stop the application insights object itself from starting to log to app insights.
Here in the following code based on the value of the variable a it will start the app insight service.
So, we will run appInsights.start(); only for a particular for value of variable a.
import { createRequire } from "module";
const require = createRequire(import.meta.url);
let appInsights = require('applicationinsights');
appInsights.setup("<Your connection String>")
.setAutoCollectConsole(true, true);
var a = 10 ;
if(a==10)
{appInsights.start();}
console.log("Hello World ");
Here I am running the code twice but with different value of variable a.
Here in application insights one log appear.

Ionic Schedule a Popover page to display every N days

I am looking to display a page every N days or for example every 3/4 days which will just popover the screen
So far from digging about I see ionics local notifications offers a really nice way to schedule standard notifications within an app but it does not allow you to change the notification data to use a page.
Is there a way to do this kind of thing natively within ionic ?
Does it need to be a popover? Couldn't you just keep a record of the last time the page was show to the user using localStorage or Storage and when the app is launched check if it's time to show the page again and then redirect to that page. If you do want it to be a popover it's pretty simple. You create the page like normal then add it as the component in your poperover constructor. Something like this in your platform.ready():
const daysSinceLastShown = parseint(localStorage.get('daysSinceLastShown'), 10);
if (daysSinceLastShown < 4) {
daysSinceLastShown++;
localStorage.put('daysSinceLastShown', daysSinceLastShown);
} else {
localStorage.put('daysSinceLastShown', 0);
presentPopover();
}
async presentPopover() {
const popover = await this.popoverCtrl.create({
component: MyPopoverPage,
});
return await popover.present();
}

Rails ActionCable / Turbolinks chat issue: posting duplicate messages

I'm having an issue with an ActionCable and Turbolinks. I've set up a chat app similar to the example chat app shared by DHH.
In order to have multiple chat rooms and pass a chat room ID to the ActionCable subscription initializer, I have something like this:
$(document).on("turbolinks:load",function(){
var pod_slug = $("#pod_slug_value").val();
App.pods = App.cable.subscriptions.create(
{ channel: 'PodsChannel', pod_slug: pod_slug },
{
received: function(data) {
if ( $(".chat-stream").length ){
$(data.message).appendTo($(".chat-stream"));
$(".chat-stream").scrollTop($(".chat-stream")[0].scrollHeight);
}
},
speak: function(message, pod_slug) {
return this.perform('speak',{
message: message,
pod_slug: pod_slug
});
}
});
// captures text input from input field
captureMessage();
});
However, when I click around the app and come back to the page, Turbolinks seems to be binding the subscription handler multiple times and now when I submit a message, I get duplicate messages in the chat stream.
I've tried slicing this problems in every which way. I don't have the problem when I don't preface the subscription handler with:
$(document).on("turbolinks:load",function(){...
But then I am unable to get the chat room id (pod_slug), because the document DOM doesn't load before the javascript executes.
It seems like this problem would have a simple solution as both ActionCable and Turbolinks are heavily supported by Basecamp. Many of the demo chat tutorials suggest setting up chat in exactly this way. Am I missing something here?
I have had the same issue and fixed it in this way
if (!App.pods) {
App.pods = App.cable.subscriptions.create(
{ channel: 'PodsChannel', pod_slug: pod_slug },
{ ... /* and so on */ }
}
Every time you reload page, 'turbolinks:load' event works, so you have to check whether App.pods object has been already created.
Hope this will help you.
You can use App.cable.subscriptions.remove to remove a subscription returned by App.cable.subscriptions.create. So maybe check if App.pods is set, and if so remove it before you subscribe again.
I like your approach, MaruniakS. Digging into the consumer object, it looks like it has a test to see if it's disconnected. Changing just the first line, we could also do:
if (!App.pods || App.pods.consumer.connection.disconnected) {
App.pods = App.cable.subscriptions.create(
{ channel: 'PodsChannel', pod_slug: pod_slug },
{ ... /* and so on */ }
}

Windows 8 Metro Inapp purchases for Dummies

am ready to deploy my second windows 8 metro style javascript app and i would love to include in app purchases.
I tried implementing it with the following code i got from here
http://msdn.microsoft.com/en-us/library/windows/apps/hh694067.aspx
function appInit()
{
// some app initialization functions
// Get current product object
// Execute only one of these statements.
// The next line is commented out for testing.
// currentApp = Windows.ApplicationModel.Store.CurrentApp;
// The next line is commented out for production/release.
currentApp = Windows.ApplicationModel.Store.CurrentAppSimulator;
// We should have either a real or a simulated CurrentProduct object here.
// Get the license info
licenseInformation = currentApp.licenseInformation;
// other app initializations function
}
function buyFeature1() {
if (!licenseInformation.productLicenses.lookup("featureName").isActive)
{
currentApp.requestProductPurchaseAsync("featureName", false).then(
function () {
// the in-app purchase was successful
},
function () {
// The in-app purchase was not completed because // there was an error.
});
}
else
{
// The customer already owns this feature.
}
}
But nothing seems to happen.i know this is a novice question. but i'l be glad if someone can provide a full simple working solution.Btw i've read the docs and downloaded the sample.i also have my storeproxy.xml file setup.
You might try changing:
currentApp.requestProductPurchaseAsync("featureName", false).then(
Into:
currentApp.requestProductPurchaseAsync("featureName", false).done(
That is what I use and it works for me.

Tridion 2011 SP1 : Tridion GUI Javascript error with Translation Manager and Powertools 2011 installed

I recently installed Tridion 2011 SP1 with SDL module Translation Manager enabled.
Everything was working fine. Then I installed the Tridion 2011 Powertools, following the installation procedure.
When trying to reload the GUI (browser cache emptied and modification parameter instanciated for server element in WebRoot\Configuration\System.Config) I'm getting the following Javascript error :
SCRIPT5007: Unable to get value of the property 'getItemType': object is null or undefined
Dashboard_v6.1.0.55920.18_.aspx?mode=js, line 528 character 851
And here is the concerned JS line:
Tridion.TranslationManager.Commands.Save.prototype._isAvailable=function(c,a){var
e=c.getItem(0),f=$models.getItem(e),b=f.getItemType(),d=$models.getItem(this.getTmUri ())
The preceding Javascript lines are dealing with other TranslationManager commands, so I suppose it is a kind of TranslationManager commands registration or somehting.
Trying to browse my Tridion publications by selecting any folder/strucutreGroup will also give the same error and the right frame (content frame) will not display any Tridion items but simply display:
Loading ...
Has anyone already experienced similar issue ?
For now I have no other choice than commenting out the Powertools sections file
Tridion_Home\web\WebUI\WebRoot\Configuration\System.Config
Thank you,
François
Strange thing here is that it refers to Save command which is not intended to be called or used from Dashboard.
I`d suggest to disable JS minification (JScriptMinifier filter in System.config), as it will probably show more correct details.
Another useful thing would be this error call stack.
--
I was not able to reproduce an issue from initial question, but had following error when I installed PT:
PowerTools is not defined
which appears in
*\PowerTools\Editor\PowerTools\Client\Shared\Scripts\ProgressDialog\ProgressDialog.js where it tries to register PowerToolsBase namespace, instead of PowerTools.
I`ll be surprised if adding
Type.registerNamespace("PowerTools");
at the top of the file will fix a problem, as in my case it was breaking entire GUI no matter if TM included or no.
I did check *\PowerTools\Editor\PowerTools\Client\Shared\Scripts\ProgressDialog\ProgressDialog.js, but the line
Type.registerNamespace("PowerTools");
was already there, so not the problem here.
Also, I disabled the JS minification. Here are the main methods the UI is loading before getting the error:
...
PowerTools.Commands.ItemCommenting.prototype.isValidSelection = function (selection) {
//Use the existing Save command from the CME
return $cme.getCommand("Save")._isEnabled(selection);
}
...
/**
* Executes this command on the selection.
* Override this method to implement the actual functionality.
* #param {Tridion.Core.Selection} selection The current selection.
*/
Tridion.TranslationManager.Commands.SendForTranslation.prototype._execute = function SendForTranslation$_execute(selection)
{
var selectedItems = selection.getItems();
if (selectedItems.length == 1)
{
var job = $models.getItem(selectedItems[0]);
if (job)
{
if (job.isLoaded())
{
job.saveAndSend();
}
else
{
$log.warn("Unable to send an unloaded job?! {0}".format(job.getId()));
}
}
else
{
$log.warn("Unable to execute save-and-send-for-translation for this selection: {0}".format(selectedItems));
}
}
else
{
$log.warn("Unable to save-and-send-for-translation multiple items at a time.");
}
};
...
Tridion.TranslationManager.Commands.Save.prototype._isAvailable = function Save$_isAvailable(selection, pipeline)
{
var itemUri = selection.getItem(0);
var item = $models.getItem(itemUri);
var itemType = item.getItemType(); !!!!!!!!! fails on this line !!!!!! item is null or not an object
var config = $models.getItem(this.getTmUri());
if (pipeline)
{
pipeline.stop = false;
}
if (config && config.hasChanged() && (itemType == $const.ItemType.CATEGORY || itemType == $const.ItemType.FOLDER || itemType == $const.ItemType.STRUCTURE_GROUP || itemType == $const.ItemType.PUBLICATION))
{
if (pipeline)
{
pipeline.stop = true;
}
return true;
}
return this.callBase("Tridion.Cme.Command", "_isAvailable", [selection, pipeline]);
};
Ok. It`s clear now.
PowerTools.Commands.ItemCommenting is used in Dashboard Toolbar.
This command uses Save to check its availability.
In the same time TM thinks that "Save" will only be used on an ItemToolbar.
The difference between this toolbars which cause an issue is that Dashboard view could have any-length selection, when Item view will always have selection having one item (currently opened).
Opening empty dashboard selection is not yet made, ItemCommenting tries to check its availability, by calling Save, which calls all its extensions. And so far as selection is empty
var itemUri = selection.getItem(0);
will return null, as well as
$models.getItem(null)
What you can do, is to remove ItemCommenting extension command as it is done in tridion powertool trunk editor.config.
http://code.google.com/p/tridion-2011-power-tools/source/browse/trunk/PowerTools.Editor/Configuration/editor.config?spec=svn942&r=903 [592]

Categories