2015-08-17 38 views
0

我想實現的pushbots代碼到我的離子的應用程序有推送通知通過 - Pushbots docsPushbots和離子應用

似乎我無法弄清楚就是下面的代碼有云:

if(PushbotsPlugin.isAndroid()){ 
    PushbotsPlugin.initializeAndroid("PUSHBOTS_APP_ID", "GCM_SENDER_ID"); 
} 

它在下面的代碼去,如果這樣,其中abouts:

.run(function($ionicPlatform, $ionicAnalytics, $window) { 

    $ionicPlatform.ready(function() { 


    /* $ionicAnalytics.register();*/ 
    // 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); 
    } 

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

或將它的配置去?

回答

0

Pushbots的初始化代碼應該放入一個在'deviceready'事件被觸發時調用的函數。在你的情況,鑑於你有一個Ionic項目,代碼應該進入一個代碼塊$ ionicPlatform.ready(function(){})

您可以使用現有的塊:

.run(function($ionicPlatform, $ionicAnalytics, $window) { 

    $ionicPlatform.ready(function() { 
    if(PushbotsPlugin.isAndroid()){ 
     PushbotsPlugin.initializeAndroid("PUSHBOTS_APP_ID", "GCM_SENDER_ID"); 
    } 

    /* $ionicAnalytics.register();*/ 
    // 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); 
    } 

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

或者你可以創建一個單獨的塊,以保持乾淨的東西,並解開:

.run(function($ionicPlatform, $ionicAnalytics, $window) { 

    $ionicPlatform.ready(function() { 
    if(PushbotsPlugin.isAndroid()){ 
     PushbotsPlugin.initializeAndroid("PUSHBOTS_APP_ID", "GCM_SENDER_ID"); 
    } 
    }); 

    $ionicPlatform.ready(function() { 
    /* $ionicAnalytics.register();*/ 
    // 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); 
    } 

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

阿林嗨,我在控制檯中一個錯誤,是:未捕獲ReferenceError:未定義PushbotsPlugin – Sole

+0

您需要安裝插件(* cordova plugin add com.pushbots.push *)並將腳本標記添加到您的index.html:* * –

+0

其實,劃傷:腳本標記不應該是必要的 –