vendredi 26 juin 2015

If - else - Localstorage dont work / cordova

I want to check if its the first app start. I run my app via xcode on my iphone on usb. But everytime i close the app on iphone and start it again with clicking the icon on my phone - like a restart - it dont recognize that the app was startet before. What i am doing wrong?

$(document).ready( function() {
if (localStorage.getItem("applaunch")) {
window.localStorage.getItem("callstatus");

}else{
//Local storage is not set, hence first time launch. set the local storage item
window.localStorage.setItem('applaunch',1);
window.localStorage.setItem("vipstatus", "0");
window.localStorage.setItem("callstatus", "0");
  }
function generateUUID() {
                  var d = new Date().getTime();
                  var uuid = 'xxxxxxxxxxxxxxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g,function(c) {
                                                                        var r = (d + Math.random()*16)%16 | 0;
                                                                        d = Math.floor(d/16);
                                                                        return (c=='x' ? r : (r&0x7|0x8)).toString(16);
                                                                        });
                  return uuid.toUpperCase();
                  }


                  window.localStorage.setItem("username",generateUUID());

                  var username = window.localStorage.getItem("username");
                  var vipstatus = window.localStorage.getItem("vipstatus");
                  var callstatus = window.localStorage.getItem("callstatus");



                  $.ajax({
                         type: 'post',
                         url: 'http://ift.tt/1GCAcvy',
                         data: {
                         data: {"username": username, "vipstatus" : vipstatus, "callstatus" : callstatus},
                         },
                         success: function(result) {
                         console.log(result);
                         }
                         });
                  });

Everytime i restart the app on the phone (NOT VIA XCODE BUILDING AGAIN) its making a new entry in my db - see ajax.

Aucun commentaire:

Enregistrer un commentaire