App.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <script>
  2. const jpushModule = uni.requireNativePlugin('JG-JPush')
  3. console.log(jpushModule.getRegistrationID,'jpushModule')
  4. export default {
  5. onLaunch: function() {
  6. console.log('App Launch')
  7. if (uni.getSystemInfoSync().platform == "ios") {
  8. // 请求定位权限
  9. let locationServicesEnabled = jpushModule.locationServicesEnabled()
  10. let locationAuthorizationStatus = jpushModule.getLocationAuthorizationStatus()
  11. console.log('locationAuthorizationStatus', locationAuthorizationStatus)
  12. if (locationServicesEnabled == true && locationAuthorizationStatus < 3) {
  13. jpushModule.requestLocationAuthorization((result) => {
  14. console.log('定位权限', result.status)
  15. })
  16. }
  17. jpushModule.requestNotificationAuthorization((result) => {
  18. let status = result.status
  19. if (status < 2) {
  20. uni.showToast({
  21. icon: 'none',
  22. title: '您还没有打开通知权限',
  23. duration: 3000
  24. })
  25. }
  26. })
  27. }
  28. jpushModule.getRegistrationID(result => {
  29. console.log(result,"注册ID.....")
  30. uni.showToast({
  31. title:result.registerID,
  32. icon:"success",
  33. duration:30000
  34. })
  35. })
  36. jpushModule.initJPushService();
  37. jpushModule.setLoggerEnable(true);
  38. jpushModule.addConnectEventListener(result => {
  39. console.log(result)
  40. let connectEnable = result.connectEnable
  41. uni.$emit('connectStatusChange', connectEnable)
  42. });
  43. jpushModule.addNotificationListener(result => {
  44. console.log(result)
  45. if (result.notificationEventType == "notificationOpened") {
  46. //点击窗口通知栏推送的消息 跳转指定页面
  47. uni.navigateTo({
  48. url: '/pages/home/warningCenter/warningCenter',
  49. complete(res) {
  50. console.log(res);
  51. }
  52. })
  53. }
  54. });
  55. jpushModule.addCustomMessageListener(result => {
  56. let type = result.type
  57. let messageType = result.messageType
  58. let content = result.content
  59. uni.showToast({
  60. icon: 'none',
  61. title: JSON.stringify(result),
  62. duration: 3000
  63. })
  64. })
  65. jpushModule.addLocalNotificationListener(result => {
  66. let messageID = result.messageID
  67. let title = result.title
  68. let content = result.content
  69. let extras = result.extras
  70. uni.showToast({
  71. icon: 'none',
  72. title: JSON.stringify(result),
  73. duration: 3000
  74. })
  75. })
  76. jpushModule.addGeofenceListener(result => {
  77. let code = result.code
  78. let type = result.type
  79. let geofenceId = result.geofenceId
  80. let userInfo = result.userInfo
  81. uni.showToast({
  82. icon: 'none',
  83. title: '触发地理围栏',
  84. duration: 3000
  85. })
  86. })
  87. jpushModule.setIsAllowedInMessagePop(true)
  88. jpushModule.pullInMessage(result => {
  89. let code = result.code
  90. console.log(code)
  91. })
  92. jpushModule.addInMessageListener(result => {
  93. let eventType = result.eventType
  94. let messageType = result.messageType
  95. let content = result.content
  96. console.log('inMessageListener', eventType, messageType, content)
  97. uni.showToast({
  98. icon: 'none',
  99. title: JSON.stringify(result),
  100. duration: 3000
  101. })
  102. })
  103. },
  104. onShow: function() {
  105. console.log('App Show')
  106. },
  107. onHide: function() {
  108. console.log('App Hide')
  109. }
  110. }
  111. </script>
  112. <style>
  113. /*每个页面公共css */
  114. </style>