I have a PWA application where I check whether the application is in standalone mode(code snippet below) else prompt user with the Install Banner.
let windowNav: any = window.navigator;
if (window.matchMedia('(display-mode:standalone)').matches || windowNav.standalone) {
this.isStandAlone = true;
}
Recently, I have also created a TWA app for the same. Now when I install the APP from the playstore the below check fails though the app is in standalone mode. Is there a different way to check the standalone mode in TWA applications?Or a way to check that the APP is a TWA app?
Thanks
Standalone is not so useful in case of TWA.
if u want to know that your application is running on TWA,
What you can do is set a sessionStorage as a flag,
If certain conditions met. When ever a TWA app is open u can get the package name like com.example inside document.reffer property and also you can pass some value in query Param to check ur app. Is opened.
So, this will look like this.
If(document.referrer == 'android-app://com.example' && location.href.includes('?twa=true')){
sessionStorage.isTwa = 1;
}
When app opens, a session starts, and isTwa will be set as 1, when app is closed that session ends as well. Same as a chrome tab session.
Related
How can I clear my Safari history and data for the iPhone simulator in an XCUITest before running the test?
I am trying to test the login features of an app and would like the login credentials not to be saved i.e. google sign in. For this I need to clear the safari history and data in the iPhone simulator settings. Is there a way of doing this in code in the setup or tear down methods?
You could do that by having a setup function that wipes the Safari data through Settings. Something like this:
func clearSafariData() {
let settingsApp = XCUIApplication(bundleIdentifier: "com.apple.Preferences")
settingsApp.launch()
settingsApp.cells["Safari"].tap()
settingsApp.cells["Clear History and Website Data"]
settingsApp.buttons["Clear History and Data"].tap()
settingsApp.terminate()
}
Simple solution: use Private mode in Safari
I am developing a mac application in which I am showing some count on app icon symbol (Similar to notification count). It work fine when app is in foreground and is active. But as an when I minimise the app or app goes into background. I am not able to see any message count on icon symbol.
let app = NSApplication.sharedApplication()
app.dockTile.showsApplicationBadge = true
app.dockTile.badgeLabel = String(unrdcount)
This method is called when I am getting data from a particular API. Can anyone suggest me how to let a particular API work for infinite time, so that if the application is ON user can get this unrdcount from API.
I am using google places api in ionic app.I places google places api script in index.html. The app allow the user to access wifi within specific place. User get internet access after login with our app. When application launch and user is connecting with our network, user do not have access to the internet. So i get error:
Application Error connection to the server was unsuccessful.
Is there anyway to call the google places api after user has access to the internet to avoid the error?
This has been quickly tested in ionic 1 and it works, no reason it shouldn't in ionic 2. But if you know a proper way to add the script tag in angular, just replace this part. The logic is simply to add your resource on the fly to index.html. Don't forget that connexion can appear while app is already started, and that you don't need to add the tag twice (verifications have to be done). Some edits might be done to adapt to ionic 2, sorry my version was made on the 1.
the function to add the script:
function addScriptTag(){
//STORE HERE VALUE TO VERIFY SCRIPT HAS ALREADY BEEN ADDED
var script = document.createElement('script');
script.src = 'http://maps.google.com...';
script.type = 'text/javascript';
document.head.appendChild(script);
}
in $ionicPlatform.ready (network is not available before that)
//CONNECTED AT APP LOADING
var networkState = navigator.connection.type;
if(networkState !== Connection.NONE){
addScriptTag();
}
//IN CASE CONNEXION ARRIVES LATER
$rootScope.$on('$cordovaNetwork:online', function(event, networkState){
if( /* VERIFY SCRIPT NOT ADDED BEFORE */ ){
addScriptTag();
}
}, false);
i'am trying to made cordova application that need user login to (google + or Facebook)
so i show button for sign in to (google+ or Facebook)
but after i close the app and open it again i need the sign in button hide depending on last signed in account
i need to know how i can check if user signed after closing my application?
ie check if user subscribe with data login to my app or no?
You can check this when your application gets loaded in
function onDeviceReady() {
// Now safe to use device APIs
//Create small function which check for is access toke valid or not
//which returns Boolean true or false
// Else you can use localStorage.isSignInned and once logged in set it as true.
if(isSignInned)
{
//hide buttons
}
}
You can check facebook javascript api here and google javascript api here
It depends upon how you want your application to work.
I am attaching working sample which i created for Facebook for GooglePlus
hope this helps.!
I am developing iPhone application which loads login page of my website. I am able to load my login page using phonegap/childbrowser. I am newbie to JS, Phonegap.
How do my native/phonegap application should handle logout and login event has performed on the webpage? Please guide me how to know user has logged out.
Also is it possible to add support for Push Notification in phonegap/childbrowser application ? How?
So far have seen facebook login-logout questions around but hard to understand and couldnt simulate similar approach.
does your whole app run using the childbrowser? If so why not just have the login log out as piece of your app?
Also if you have to use the childbrowser best bet is to set up a locationchange event and if the location equals a login success page then append some arguments and store those using localstorage.
example -
client_browser.onLocationChange = function(loc){
locationchange(loc);
};
function locationchange(loc){
if(loc.indexOf("http://www.example.com/success?login=true&user=foo") > -1){
var user = loc.match(/user=(.*)$/)[1]; // grab user info
localStorage.setItem('login','true'); // set login as true
localStorage.setItem('user',user); // set username
}
}
that will save to your app locally that the user is logged in and their username, which you can use later if you need to use the childbrowser by passing that in the url you open and on the server side you'll have to look for those arguments.
to log out just open the childbrowser and send a logout argument
www.example.com/logout?user=foo
and in your localStorage
localStorage.setItem('login','false');
Honestly this is kind of a vague question, it would really help to understand why you're wanting to do this in the childBrowser vs your app...