jpushservice.js 3.1 KB

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