clearing app pages from device background logging out automatically titanium studio - titanium

After login into App my App running fine in background mode But after If I clear App from background mode it automatically logged out from App. But i want it should be logged in until user manually logged out from App. How i can make it possible ?
My code:
results = {
iuser_id: response.iuser_id,
signup_ids: response.signup_ids,
staff_id : response.staff_id,
vusername: response.vusername,
vfirst_name: response.vfirst_name,
vlast_name: response.vlast_name,
vemail : response.vemail,
vpwd : response.vpwd
};
Ti.App.Properties.setObject("user_session",results);
results = null;
var flag = '';
if (!Ti.App.Properties.hasProperty('installed'))
{
Ti.App.Properties.setBool('app:isLoggedIn', true);
Ti.App.Properties.hasProperty('installed');
Ti.App.Properties.setBool('installed', true);
var th_sign = Alloy.createController('login').getView();
th_sign.open();
}
else
{
var th_sign = Alloy.createController('home').getView();
th_sign.open();
}
}

Related

while i refresh the page the cookies get expire i don't see any data

i used the local Storage to but after the logout if i hit the same URL the user is able to login again even i checked with the session Storage i am facing the same issue, is there any way that i can handle a cookie/session so that after the page refresh or the user logout and hit the same URL user should not be able to login.
logout() {
this.cookie.delete("token");
this.cookie.delete("userId");
this.cookie.delete("accountId");
}
this is how i am clearing the cookie.
I have written a function for this
function deleteCookies(removeCookies) {
var cookies = document.cookie.split(";");
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i];
var eqPos = cookie.indexOf("=");
var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
if(name in removeCookies)
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
}
}
var removeCookieSet = ["token","userId","accountId"] ;
deleteCookies(removeCookieSet)
this set has been taken from i have rewritten so you can use it. Clearing all cookies with JavaScript
Above is direct , if you want to work with angular JS
angular.module('cookiesExample', ['ngCookies'])
.controller('ExampleController', ['$cookies', function($cookies) {
var removeCookieSet = ["token","userId","accountId"];
for(i=0;i<removeCookieSet.length;i++)
// Setting a cookie
$cookies.remove(removeCookieSet[i]);
}]);
Using angular JS , you will have to inject ngcookies
and using typescript
https://tutorialedge.net/typescript/angular/angular-cookies-tutorial/

How to check if a user device is using fingerprint/face as unlock method. [ReactNative] [Expo]

I'm using ReactNative based on Expo Toolkit to develop a App and I want know how I can check if the user is using the fingerprint (TouchID on iPhone) or face detection (FaceID on iPhone X>) to unlock the device.
I already know how to check if device has the required hardware using Expo SDK, as follow:
let hasFPSupport = await Expo.Fingerprint.hasHardwareAsync();
But I need check if the user choose the fingerprint/face as unlock method on your device, instead pattern or pin.
Thanks
Here's an update to Donald's answer that takes into account Expo's empty string for the model name of the new iPhone XS. It also takes into account the Simulator.
const hasHardwareSupport =
(await Expo.LocalAuthentication.hasHardwareAsync()) &&
(await Expo.LocalAuthentication.isEnrolledAsync());
let hasTouchIDSupport
let hasFaceIDSupport
if (hasHardwareSupport) {
if (Constants.platform.ios) {
if (
Constants.platform.ios.model === '' ||
Constants.platform.ios.model.includes('X')
) {
hasFaceIDSupport = true;
} else {
if (
Constants.platform.ios.model === 'Simulator' &&
Constants.deviceName.includes('X')
) {
hasFaceIDSupport = true;
}
}
}
hasTouchIDSupport = !hasFaceIDSupport;
}
EDIT: Expo released an update that fixes the blank model string. However you might want to keep a check for that just in case the next iPhone release cycle causes the same issue.
Currently, you could determine that a user has Face ID by checking Expo.Fingerprint.hasHardwareAsync() and Expo.Fingerprint.isEnrolledAsync(), and then also checking that they have an iPhone X using Expo.Constants.platform (docs here).
So:
const hasHardwareSupport = await Expo.Fingerprint.hasHardwareAsync() && await Expo.Fingerprint.isEnrolledAsync();`
if (hasHardwareSupport) {
const hasFaceIDSupport = Expo.Constants.platform.ios && Expo.Constants.platform.ios.model === 'iPhone X';
const hasTouchIDSupport = !hasFaceIDSupport;
}
Incase you tried the above answer and it's not working please note as at the time of my post expo's documentation has changed
- import * as LocalAuthentication from 'expo-local-authentication';
- let compatible = await LocalAuthentication.hasHardwareAsync()
We can check if device has scanned fingerprints:
await Expo.Fingerprint.isEnrolledAsync()
So, this can be used to reach the objective as follow:
let hasFPSupport = await Expo.Fingerprint.hasHardwareAsync() && await Expo.Fingerprint.isEnrolledAsync();

stop sounds after going back to the previous tab

I have a simple tabbed app where the user can click a button and then a view will load in the active tab where a picture is displayed and a sound is being played.
However if the user tabs on the back button the sound doesn't stop playing.
How can I make the sound stop when I go to the previous view?
Thanks in advance!
My index.js:
function viewSelectedItem() {
var args = { image : 'images/photo/farm/chicken1.jpg', title : 'kip' };
var win = Alloy.createController('viewItem', args).getView();
Alloy.Globals.tabgroup.activeTab.open(win);
}
my viewItem.js
var args = arguments[0] || {};
$.itemImage.image = args.image;
$.itemTextLabel.text = args.title;
var sound = Ti.Media.createSound({
url: 'sounds/farm/chicken1.mp3'
});
sound.play();
I assume you target Android with this and that each Alloy Controller represents a Window.
You need to set allowBackground to true to allow the audio to continue when the Activity the Window belongs to is stopped because the Window closed.
http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.Media.AudioPlayer-property-allowBackground
I fixed it like this:
$.itemView.addEventListener('close', windowClosed);
function windowClosed() {
sound.stop();
}

navigateToURL failed open up browser on iPad (Adobe Air)

Quick question, I am using Adobe AIR to develop an app under iPad. Why navigateToURL not open up the Safari under iPad? it works under Android.
if(e == 'pdf')
{
loader.addEventListener(Event.COMPLETE, function(e)
{
var variables:URLVariables = new URLVariables(e.target.data);
var url:String = 'http://files.au2.schneider-electric.com/locator/index.php?controller=pdfGenerator&action=fetchroom&roomid=' + variables.roomid + '&userid=0';
var request:URLRequest = new URLRequest(url);
try
{
navigateToURL(request, '_blank'); // second argument is target
}
catch(e:Error)
{
trace("Error occurred!");
}
});
}
Just wondering is it Adobe Air can't open browsers on Mobiles Devices at all?
I don't think you can expect that PDFs load like regular webpages on iOS. This is untested, but the idea is to create a StageWebView instance, using it to load the PDF:
var swv:StageWebView = new StageWebView();
swv.viewPort = new Rectangle(0,0,wid,ht);
swv.stage = stage;
swv.loadURL( someUrl );
EDIT:
See the Adobe docs on StageWebView as well.

Titanium TabGroup: How to close window and then display the tab Group?

I have following flow of app :
First screen is Login screen and if Login gets success the tab-group opens.
here is code :
app.js
var win = Titanium.UI.createWindow
({
title:'User Login',
url:'Login.js',
tabBarHidden:true,
backgroundColor:'gray',
navBarHidden:false
});
win.open();
Login.js
var win = Ti.UI.currentWindow;
// some UI controls
loginBtn.addEventListener('click', function(e)
{
//calling web service
if(isSuccess == 1)
{
var tabGroup = Titanium.UI.createTabGroup();
// code to create Tab
tabGroup.open();
}
}
Now if I hide the currentWindow (win) every thing works fine But Login view is get displayed in background of all the time !!! So I want to close Login window and then open the tab group. So I tried :
win.close();
tabGroup.open();
But doesn't work application gets crashed.
So, How to close window and then display the tab Group ???
Thanks....
Solved !!! As slash197 has suggested in Login.js I was trying to close win which was the root window. So I used a dummy window inside the Login.js and close it and the open tabGroup . Like :
Login.js
var win = Ti.UI.currentWindow;
var loginView = Ti.UI.createWindow
({
backgroundColor:'transparent'
});
And added all the UI component into the loginView instead of win.
Then for Android
loginView.open();
And for iPhone
loginView.open();
win.add(loginView);
After success :-
loginBtn.addEventListener('click', function(e)
{
//calling web service
if(isSuccess == 1)
{
var tabGroup = Titanium.UI.createTabGroup();
// code to create Tab
//for Android
loginView.close();
//for iPhone
win.remove(loginView);
tabGroup.open();
}
}
Note:- Not sure that it is best approach. But it works for me.
If that window is the first than it's the root element and can't be closed. You could try removing all of it's children and set it's background to transparent then open your tabGroup.