在IOS phonegap应用程序中清除数据库和本地存储

时间:2014-06-04 14:30:05

标签: javascript ios cordova

关于应用

我在ios phonegap应用程序中使用corodova 2.1.0

我的应用程序执行了一些注册过程,因为它检查应用程序是否已注册,如果它在数据库或本地存储中找到数据,它会转到仪表板,否则它会要求注册。 在注册过程中,应用程序询问手机号码,如果后端的移动条目是喜欢的,那么应用程序将从数据库下载数据并将其存储在本地存储和数据库中。

期 -

如果是第一次注册的应用程序下载数据并转到仪表板。如果我杀了应用程序,然后打开它,它将要求注册,如果我第二次注册,并在仪表板上,如果我杀了应用程序并再次打开应用程序然后它将显示dasboard后,它没有显示注册屏幕。

我第一次检查了weinre,它还加载了数据库和本地sotrage中的所有数据

我只存储名称和用户的ID。但如果我在首次安装后杀了app,它就会被清除。

 //Here is code which checks that user is registred or not

//这将关注splashscrenn

//$window.location.href = '#/SplashScreen';
function checkregistration(){

 var sqlU = 'SELECT ClubId, MemberId, MemberName FROM  member_master_dtls';
 var obj = {};
 var db = window.openDatabase("ROW_DB", "", "Cordova Demo", 200000);
 try{
    var  MID = localStorage.getItem('MyMemberID');
    console.log("MID befo "+ typeof(MID));

    console.log("MID === "+ (MID));
    if ( MID.length>0)
    {
     console.log("MID"+ MID);
     RowDbService.CheckVersion();
     $window.location.href = '#/Dashboard';
    }else{
   db.transaction(function(tx) {
     //console.log('in db trans');
     tx.executeSql(sqlU, [], SuccessChkMemlst_local, errorCB);
     });
   }
    }
   catch(err){
  db.transaction(function(tx) {
 //console.log('in db trans');
   tx.executeSql(sqlU, [], SuccessChkMemlst_local, errorCB);
    });
 }
}

function SuccessChkMemlst_local(tx, results) {
 //alert("success splash");
 //console.log("successlist = " + results.rows.length);
 if (results.rows.length == 0) {
  //localStorage.setItem('globalx', '1');
  globalx = 1;
  $window.location.href = '#/Register';
  //console.log(results);
 } else {                
  RowDbService.CheckVersion();
  $window.location.href = '#/Dashboard';
 }
}

=================================
//here is function on Register page that download data from webservice and store it in database
//$window.location.href = '#/Register';
function ChkForRegistration(){
 //here some webservices wich downloads th
 localStorage.setItem('ClubID', obj[0].ClubId);
 localStorage.setItem('MyMemberName', obj[0].member_name);
 localStorage.setItem('MyMemberID', obj[0].member_master_id);
 localStorage.setItem('MyClubName', obj[0].club_name);
 localStorage.setItem('NewsCount',0);
 localStorage.setItem('AnnCount',0);
 localStorage.setItem('EventCount',0);
 localStorage.setItem('BdayCount',0);
 localStorage.setItem('EventDate',"");
 localStorage.setItem('BdayDate',"");
  var datarow = {};
 datarow.MemberId = localStorage.getItem('MyMemberID');
 datarow.MemberName = localStorage.getItem('MyMemberName');
 datarow.ClubId = localStorage.getItem('ClubID');
 datarow.ClsfyName = localStorage.getItem('MyClubName');

 var db = window.openDatabase("ROW_DB", "", "Cordova Demo", 200000);      
 db.transaction(function(tx) {  
   var query="insert into member_master_dtls (id,MemberId,MemberName,ClubId,ClsfyName) values(?,?,?,?,?)";
   tx.executeSql("update sqlite_sequence set seq = 0 where name ='member_master_dtls'");
   tx.executeSql("delete from member_master_dtls");
   tx.executeSql(query,[(1),datarow.MemberId,datarow.MemberName,datarow.ClubId,datarow.ClsfyName]);
   tx.executeSql("update sqlite_sequence set seq =1 where name ='member_master_dtls'");
 });
 $window.location.href = '#/Dashboard';
}

0 个答案:

没有答案