2016-07-14 3 views
-1

IONICでアンドロイドのプッシュ通知を開発するにはどうすればよいですか? 実例コードを教えてください。GCMを使用したプッシュ通知とionicの完全な例でのandorid

ここに私のコードです。

ファイル名はapp.js

.config(['$ionicAppProvider', function($ionicAppProvider) 
{ 
    $ionicAppProvider.identify({ 
         app_id: 'APP_ID, 
         api_key: 'PUBLIC_KEY' 
         }); 
    }]) 

.controller('PushCtrl', function($scope, $rootScope, $ionicUser, $ionicPush) 
{ 
$rootScope.$on('$cordovaPush:tokenReceived', function(event, data) 
{ 
    alert("Successfully registered token " + data.token); 
    console.log('Ionic Push: Got token ', data.token, data.platform); 
    $scope.token = data.token;}); 

    $scope.identifyUser = function() 
    { 
     var user = $ionicUser.get(); 
     if(!user.user_id) 
     { 
     // Set your user_id here, or generate a random one. 
     user.user_id = $ionicUser.generateGUID(); 
     }; 

// Metadata 
angular.extend(user, { 
    name: 'Simon', 
    bio: 'Author of Devdactic' 
}); 

    // Identify your user with the Ionic User Service 
    $ionicUser.identify(user).then(function() 
    { 
     $scope.identified = true; 
     console.log('Identified user'+user.name+'\n ID'+user.user_id); 
    }); 
}; 

//あなたは私が間違っているところ教えてくださいできますプッシュ通知

$scope.pushRegister = function() 
{ 
    console.log('Ionic Push: Registering user'); 
// Register with the Ionic Push service. All parameters are optional. 
$ionicPush.register({ 
    canShowAlert: true, //Can pushes show an alert on your screen? 
    canSetBadge: true, //Can pushes update app icon badges? 
    canPlaySound: true, //Can notifications play a sound? 
    canRunActionsOnWake: true, //Can run actions outside the app, 
    onNotification: function(notification) 
{ 
    return true; 
} 
}); 
}; 
}); 

するためのデバイスを登録しています。私はこのライン

<script src="lib/angular-websocket/angular-websocket.js"></script> 
+1

あなたは[この文書](http://docs.ionic.io/docs/push-sending-push)を参照していますか? –

+0

[こちら](https://thinkster.io/ionic-push-notifications-tutorial)も参照してください... –

答えて

0

チェック

http://ngcordova.com/docs/plugins/pushNotifications/

がどのようにトークンデバイスを得るために、私のスタックの答えをチェックし、このNG-コルドバプッシュ通知プラグインでエラーが発生しました

Retrieve device token from device, using ionic framework

完全なデモブログはここをクリックしてください。 https://devdactic.com/ionic-push-notifications/

+0

私はすでにこのソリューションを試していますが、それは私のためには機能しませんでした。他の解決策がある場合は、私に知らせてください。あなたの答えをありがとう –

+0

私は上記のチュートリアルに従っていると私はあなたが何をしようとしたことを知っているかもしれない私のプロジェクトでまだ助けてくれるかもしれないあなたのコードの一部を与えるかもしれない –

+0

私の更新コード –

関連する問題