I have the following code that only fires if serviceworker is not yet installed, if I reload the page, it no longer fires, I did not add the code yet to install the PWA (deferredprompt does nothing). I'm using Chrome. I am not declining the prompt, I am not even displaying the prompt at the moment.
let deferredPrompt = null;
window.addEventListener('beforeinstallprompt', (e) => {
// Prevent Chrome 67 and earlier from automatically showing the prompt
e.preventDefault();
consolelog('=== before install prompt fired ===', 3)
// Stash the event so it can be triggered later.
deferredPrompt = e as any;
});
The event fires immediately on load (if you have a serviceworker installed), and I was wiring up the event too late, so I missed it.
Related
So my game wants the players to have the ability to subscribe to a game bot and I'm using FBInstant.player.canSubscribeBotAsync() method. But everytime, it will return an error that state
Uncaught TypeError: FBInstant.player.canSubscribeBotAsync is not a function
here is my code
FBInstant.player.canSubscribeBotAsync().then(function(yes){
if(yes){
FBInstant.player.subscribeBotAsync().then(function(){
console.log('sub');
}).catch(function(e)){}
}
});
I tried using this code from FB developer doc
FBInstant.player.canSubscribeBotAsync().then(
can_subscribe => console.log(can_subscribe)
);
but the result still the same.
It seems that I tried to let the player subscribe when they click the button and this error appears.
But when I switch it from letting the player click the subscribe button to asked when player finished loading the game, the error disappears. The program's flow look like this
window.onload = async () => {
FBInstant.initializeAsync().then(()=>{
FBInstant.startGameAsync().then((res)=>{
FBInstant.player.canSubscribeBotAsync().then((canSub)=>{
//Ask for sub or something
}).catch(()=>console.log("Error"))
})
})
But for me, this is a temporary fix since normally you should be able to call a function anywhere you want (working or not isn't my problem) and my problem is that I can only call FBInstant.player.canSubscribeBotAsync() inside FBInstant.initializeAsync() or FBInstant.startGameAsync() but not outside of them
As part of the functionality of the app we are developing, when an android alarm is fired, a dialog box is to appear with an "Accept" or "Reject" button. Selecting reject does nothing, but selecting "Accept" triggers a callback from the plugin, which I have passed a function into. This function causes the ionic app to navigate to the root page of the app.
The issue I am having is, when I then navigate to another page after that where the user selects a value, and this value is displayed back to them and a button is enabled, the value display is not updating, and the button is not becoming enabled. Nothing seems to be updating.
What I have found is that pressing the back button on my android device will cause the page to update, which is not ideal.
This functionality works without the callback from the plugin.
What is happening here? And how do I fix it?
Passing the function into the plugin.
alarms_plugin.onAlarmRecieved = (alarmId) =>{
this.events.publish('alarmRecieved', alarmId);
}
Plugin-side functions
alarmRecieved: function(alarmId){
alarms_plugin.onAlarmRecieved(alarmId);
}
onAlarmRecieved: null
Navigating to root page on alarmRecieved
this.events.subscribe('alarmRecieved', (alarmId) =>{
if(alarmId != 'TIMEOUT')
this.nav.setRoot(HomePage);
});
Fix found by surrounding the this.nav.setRoot(HomePage) in this.zone.run(..).
Supposedly calling navigation within a subscription event causes issues like I was having.
Having this function in a controller:
$scope.$on('$ionicView.enter', function() {
seemed to be good. Everytime I open the app in the real device, this functions is actually triggered. But then, after a while I realized that this is not always true.
If I open my app, and then close it. And then some time goes, maybe a few minutes. And I open the app again. Well, then the app doesnt start from scratch. It goes back to latest screen/controller I was. And, worst of all, the $ionicView.enter is NOT fired.
If the app is closed and I open again after a while (maybe 5 minutes) then it starts from beginning (showing splash etc).
So, is there a way to solve this issue? How to make the app react going into $ionicView.enter each time it is opened again? Even if picked up from background?
You could use resume event when the app picked up from background, like below:
document.addEventListener("resume", onResume, false);
function onResume() {
setTimeout(function() {
// TODO: do your thing
}, 0);
}
I am using TinyMCE 4 but the documentation is terrible. I am trying to provide a live preview of the content in another div (outside of the editor). Right now I am listening to these events:
$(document).on('tinymce:changed tinymce:init', ...)
This is working when text is entered, but it does not trigger when commands are executed (changing existing text to bold for example).
It looks like in TinyMCE 3.x there is an onExecCommand event that does what I want. But I can't find any documentation on how to listen to the global jQuery event like I am doing with with change and init. Does anyone know what event it is firing?
In the migration guide you can find the following example:
// Old event
editor.onInit(editor, args) {
// Custom logic
});
// New event
editor.on('init', function(args) {
// Custom logic
});
So the one problem is to get right event name and the right editor instance :)
The onExecCommand() event becomes 'ExecCommand' in v4.
So adding a handler on command execution should be like this (be sure that editors are already initialized when executing code below):
for (ed_id in tinymce.editors) {
tinymce.editors[ed_id].on('ExecCommand', function(args) {
alert(1);
});
}
For some reason this event fires twice when command is executed. I think you will overcome this issue.
Though this method does not uses jQuery bindings, it works for me and possibly will solve your problem too.
In case this helps anyone else, here is a list of all the events tinymce 4 allows:
http://www.tinymce.com/wiki.php/api4:class.tinymce.Editor
I'm trying to build a mobile-safari/iphone web-app using jQuery code I already wrote for the desktop version of the app. The problem I'm having is that when my phone goes to sleep with the web-app running, when I wake it up (slide to unluck) the JavaScript event handlers no longer function. In this case meaning when I click on a link that used to perform an AJAX update via an onclick event it actually follows the link by opening the page in a new Safari window, breaking the appearance of the native iPhone app.
The code that stops working:
$(function() {
var ajaxLoad;
var ajaxClick = function(e) {
e.preventDefault();
e.stopPropagation();
$("body").load( $(this).attr("href"), ajaxLoad );
}
ajaxLoad = function() {
$(this).find("a").click( ajaxClick );
}
$("a").bind( "click", ajaxClick );
});
When the code works the result of the link will open in the web-app frame, when it breaks, the code will open in a new safari window, breaking the look of an actual app.
Not tested - but would it help to add 'return false' to the end of the ajaxClick function so that the link does not activate.