0

사용자가 처음 APP를 사용한 경우 자동 로그인을하고 싶습니다. alloy.js 및 Ti.App.Properties.getString ('login_token')에 유지하려고했으나 작동하지 않았습니다. 내 커피티타늄으로 서버에서 로컬 장치에 데이터를 저장하는 방법은 무엇입니까?

:

result = JSON.parse this.responseText 
console.info result.token #"dsfdsfds2142fds3r32rf32e3dfefwedf" 
Ti.App.Properties.setString "token",result.token 
console.info Ti.App.Properties.getString "token" # it's blank 
+0

몇 가지 코드를 보여 주시겠습니까? – WeMakeSoftware

+0

전체 코드를 붙여 넣고 수행해야 할 작업을 자세히 알려주십시오. –

답변

0

가 나는이 작업을 수행하는 방법에 내장 찾을 수 없습니다 그래서 난 그냥 getter 및 setter 메소드를 작성 alloy.js에 넣어. 매우 해킹되고 더러운 느낌이지만 작동하지 않습니다.

//retrieves the value of the token 
// also checks if the token is valid and sets logged_in accordingly 
function getToken(){ 
    var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'api.txt'); 
    var content = f.read(); 

    //if we can read this return it, otherwise return a blank value 
    if (content){ 
     return content.text; 
    } 
    else { 
     return ''; 
    } 
} 

//persists and sets the value of token to the new value 
function setToken(key){ 
    var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'api.txt'); 
    f.deleteFile(); 
    var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'api.txt'); 
    f.write(key); 
    token = key; 
} 
관련 문제