2016-04-01 17 views
0

我在應用程序中使用plotprojects插件進行基於位置的通知:http://www.plotprojects.com/。 該應用程序建立在離子科爾多瓦框架上。
我在$ ionicPlatform.ready()函數內調用plot.init()。
然而,plot.isEnabled()函數在啓動應用程序後有時會禁用繪圖,因此會提供輸出。它隨機發生。我是否應該稍後在代碼中調用plot.isEnabled()方法來獲得正確的繪圖狀態?陰謀項目 - Plot插件未在應用程序中成功初始化

$ionicPlatform.ready(function() { 
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard 
    // for form inputs) 
    if (window.cordova && window.cordova.plugins.Keyboard) { 
    cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 
    cordova.plugins.Keyboard.disableScroll(true); 

    } 
    if (window.StatusBar) { 
     //org.apache.cordova.statusbar required 
     StatusBar.styleDefault(); 
    } 
    //window.localStorage.setItem("IsLaunched","YES"); 
    var plot = cordova.require("cordova/plugin/plot"); 
     plot.init(); 
     console.log('after plot init'); 
    plot.isEnabled(function(enabled) { 
    var plotEnabledState = enabled ? "enabled" : "disabled"; 
    console.log("Plot is " + plotEnabledState); 
}, function (err) { 
    console.log("Failed to determine whether Plot is enabled: " + err); 
}); 

回答

1

初始化Plot需要一些時間。劇情在後臺初始化。在撥打plot.init()後直接撥打plot.isEnabled(),則會返回false。如果您在致電plot.isEnabled()之前等待一秒鐘,那麼它將返回true