jpushservice.js 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. (function (app) {
  2. //工具类服务
  3. app.factory("jpushService", ['$http', '$window', '$document', function ($http, $window, $document) {
  4. var jpushServiceFactory = {};
  5. //var jpushapi=$window.plugins.jPushPlugin;
  6. //启动极光推送
  7. var _init = function (config) {
  8. $window.plugins.jPushPlugin.init();
  9. // //设置tag和Alias触发事件处理
  10. // document.addEventListener('jpush.setTagsWithAlias',config.stac,false);
  11. //打开推送消息事件处理
  12. $window.plugins.jPushPlugin.openNotificationInAndroidCallback = config.oniac;
  13. //IOS打开通知栏消息
  14. // $window.plugins.jPushPlugin.receiveMessageIniOSCallback=config.notify;
  15. $window.plugins.jPushPlugin.setDebugMode(true);
  16. $window.plugins.jPushPlugin.setDebugModeFromIos();
  17. $window.plugins.jPushPlugin.setCrashLogON();
  18. $window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
  19. //点击推送通知
  20. document.addEventListener("jpush.openNotification", config.notify, false);
  21. //前台收到推送
  22. document.addEventListener("jpush.receiveNotification", config.notify, false);
  23. //后台收到推送
  24. document.addEventListener("jpush.backgroundNotification", config.notify, false);
  25. // document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false);
  26. // document.addEventListener("deviceready", onDeviceReady, false);
  27. // document.addEventListener("jpush.openNotification", onOpenNotification, false);
  28. // document.addEventListener("jpush.receiveNotification", onReceiveNotification, false);
  29. document.addEventListener("jpush.receiveMessage", config.notify, false);
  30. }
  31. //获取状态
  32. var _isPushStopped = function (fun) {
  33. $window.plugins.jPushPlugin.isPushStopped(fun)
  34. }
  35. //停止极光推送
  36. var _stopPush = function () {
  37. $window.plugins.jPushPlugin.stopPush();
  38. }
  39. //重启极光推送
  40. var _resumePush = function () {
  41. $window.plugins.jPushPlugin.resumePush();
  42. }
  43. //设置标签和别名
  44. var _setTagsWithAlias = function (tags, alias) {
  45. $window.plugins.jPushPlugin.setTagsWithAlias(tags, alias);
  46. }
  47. //设置标签
  48. var _setTags = function (tags) {
  49. $window.plugins.jPushPlugin.setTags(tags);
  50. }
  51. //设置别名
  52. var _setAlias = function (alias) {
  53. $window.plugins.jPushPlugin.setAlias(alias);
  54. }
  55. jpushServiceFactory.init = _init;
  56. jpushServiceFactory.isPushStopped = _isPushStopped;
  57. jpushServiceFactory.stopPush = _stopPush;
  58. jpushServiceFactory.resumePush = _resumePush;
  59. jpushServiceFactory.setTagsWithAlias = _setTagsWithAlias;
  60. jpushServiceFactory.setTags = _setTags;
  61. jpushServiceFactory.setAlias = _setAlias;
  62. return jpushServiceFactory;
  63. }]);
  64. })(angular.module('app.services'));