在离子完整示例中使用 GCM 进行 andorid 的推送通知
Push Notification using GCM for andorid in ionic full example
如何在IONIC中为Android开发推送通知?请给我工作示例代码。
这是我的代码。
文件名为应用程序.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>
检查这个ng-cordova推送通知插件
http://ngcordova.com/docs/plugins/pushNotifications/
检查我的堆栈答案如何获取设备令牌
使用离子框架从设备检索设备令牌
在此处查看完整的演示博客,并有明确的解释https://devdactic.com/ionic-push-notifications/
相关文章:
- 为什么不't Javascript对我的输入值进行了一些重新检查
- 使用agility.js进行页面布局和合成
- 如何使用skip参数使用angular ui引导进行服务器端分页
- JavaScript数组排序(函数)用于对表行进行排序,而不是排序
- 借助asp.net验证或java脚本对多个文本进行验证
- 使用promise和mongoose对文档进行排序
- Selectize.js:如何对整数值的选项进行排序
- 在Safari执行javascript之前对其进行修改
- React组件等待所需道具进行渲染
- 单击顶部导航时如何进行向下滚动效果(向下滑动).
- 使用html中的外部javascript进行数据验证
- 如何在javascript上使用flak-babel进行翻译
- 如何通过引用var Using DataTables来进行分页或排序
- $rootScope未使用forEach进行更新
- 有没有一个javascript图形绘制库可以进行气球树布局
- 在数据提取完成之前进行页面渲染
- JQuery对动态创建的对象进行选择
- javascript:如何在antlr生成的Lexer中进行错误处理
- 对id以某个字符串开头的元素进行计数
- 在离子完整示例中使用 GCM 进行 andorid 的推送通知