2016-10-19 6 views
0

Ich entwickle Ionic Cordova Hybrid-Anwendung. Wenn ich es mit einem Browser teste, funktioniert die Anwendung sehr gut. Aber ich teste es in meinem echten Gerät es funktioniert nicht sehr persistent. Es bedeutet, dass SQLite manchmal gut funktioniert und manchmal nicht gut funktioniert. Das folgende ist mein Code:Ionic Cordova SQLite funktioniert gut im Browser, funktioniert aber nicht persistent in Android-Gerät

app.js

.run(function($ionicPlatform, $cordovaSQLite) { 
    $ionicPlatform.ready(function() { 
    if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) { 
     cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 
     cordova.plugins.Keyboard.disableScroll(true); 

    } 
    if (window.StatusBar) { 
     StatusBar.styleDefault(); 
    } 

    db = window.openDatabase("chatChannel.db", "1", "Demo SQLite Test", "2000"); 
    $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS chat_channel(id interger primary key, chat_room text, last_text text, username text, chat_channel text unique)"); 
    $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS chat_content(id integer primary key, content text, channel text, chat_flag integer, username text, date timestamp)"); 
    }); 

controller.js

var query = "SELECT * FROM chat_content WHERE channel=? ORDER BY date"; 
    var promise = $cordovaSQLite.execute(db, query, [subscribeChannel]).then(function(result){ 
    for(i=0; i<result.rows.length; i++){ 
     $scope.messages.push(result.rows.item(i)); 
     console.log(result.rows.item(i)); 
     } 
    }); 

Antwort

1

Versuchen Sie Folgendes:

1. Legen Sie ng-cordova-min.js oder ng-cordova.js und cordova.js Dateien zuletzt, indem Sie sie am unteren Rand von yo ur in Ihrer index.html Datei

2. In Ihrer app.js Datei sollte Datenbank Initialisierung die erste Zeile sein heißt

var db = null; 

sollte die erste Zeile an der Spitze sein. Und immer noch in Ihrer app.js Datei,

db = window.openDatabase("chatChannel.db", "1", "Demo SQLite Test", "2000"); 

sollte die erste Zeile in der Plattform bereit Funktion sein. Ihr Code sollte so etwas in der app.js Datei mögen;

.run(function($ionicPlatform, $cordovaSQLite) { 
     $ionicPlatform.ready(function() { 
     db = window.openDatabase("chatChannel.db", "1", "Demo SQLite Test", "2000"); 

     $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS chat_channel(id interger primary key, chat_room text, last_text text, username text, chat_channel text unique)"); 
     $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS chat_content(id integer primary key, content text, channel text, chat_flag integer, username text, date timestamp)"); 

     if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) { 
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 
      cordova.plugins.Keyboard.disableScroll(true); 
     } 
     if (window.StatusBar) { 
      StatusBar.styleDefault(); 
     } 
    }); 
}) 
+0

Problem gelöst. Danke –

+0

Ihre Begrüßung :) –

Verwandte Themen