native_permission_check.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import { getLocalPush } from '@/features/trackTimeDuration/actions/TrackTimeActions';
  2. import { clientInfo } from '@/services/common';
  3. import Taro from '@tarojs/taro';
  4. // import JPush from 'jpush-react-native';
  5. import { PushNotification } from 'react-native-push-notification';
  6. import { Alert, Linking } from 'react-native';
  7. import { check, PERMISSIONS, RESULTS, checkMultiple } from 'react-native-permissions';
  8. import { kIsIOS } from './tools';
  9. // import {OneSignal} from 'react-native-onesignal';
  10. export const uploadPermissions = () => {
  11. if (Taro.getSystemInfoSync().platform == 'android') {
  12. checkMultiple([PERMISSIONS.ANDROID.CAMERA,
  13. PERMISSIONS.ANDROID.ACCESS_COARSE_LOCATION,
  14. PERMISSIONS.ANDROID.POST_NOTIFICATIONS]).then(statuses => {
  15. const OneSignal = require('react-native-onesignal').OneSignal
  16. OneSignal.initialize("2bbf5339-7ab8-4c5c-9a66-c3a8eaea188e");
  17. OneSignal.Notifications.getPermissionAsync().then((res) => {
  18. if (res) {
  19. global.notification = 'authorized'
  20. }
  21. else {
  22. global.notification = 'denied'
  23. }
  24. var Jto = require('react-native').NativeModules.NativeBridge;
  25. Jto.checkSystemLocationService().then(enableLocation => {
  26. clientInfo({
  27. perm: {
  28. android: {
  29. camera: statuses[PERMISSIONS.ANDROID.CAMERA],
  30. location: {
  31. location_services_enabled: enableLocation,
  32. authorization_status: statuses[PERMISSIONS.ANDROID.ACCESS_COARSE_LOCATION]
  33. },
  34. notification: {
  35. authorization_status: global.notification
  36. }
  37. }
  38. }
  39. })
  40. })
  41. })
  42. });
  43. return
  44. }
  45. checkMultiple([PERMISSIONS.IOS.CAMERA,
  46. PERMISSIONS.IOS.PHOTO_LIBRARY,
  47. PERMISSIONS.IOS.LOCATION_WHEN_IN_USE,
  48. PERMISSIONS.IOS.LOCATION_ALWAYS]).then(statuses => {
  49. // getLocalPush()
  50. var Jto = require('react-native').NativeModules.NativeBridge;
  51. Jto.getLocationAuthStatus((res) => {
  52. clientInfo({
  53. perm: {
  54. ios: {
  55. album: statuses[PERMISSIONS.IOS.PHOTO_LIBRARY],
  56. camera: statuses[PERMISSIONS.IOS.CAMERA],
  57. location: res,
  58. notification: {
  59. authorization_status: global.notification
  60. }
  61. }
  62. }
  63. })
  64. })
  65. })
  66. }
  67. export const checkNotification = () => {
  68. if (Taro.getSystemInfoSync().platform == 'android') {
  69. const OneSignal = require('react-native-onesignal').OneSignal
  70. OneSignal.Notifications.canRequestPermission().then((res) => {
  71. if (res) {
  72. OneSignal.Notifications.requestPermission(true);
  73. }
  74. else {
  75. Linking.openSettings()
  76. }
  77. })
  78. return;
  79. }
  80. if (global.notification == 'not_determined') {
  81. if (kIsIOS) {
  82. var Jto = require('react-native').NativeModules.NativeBridge;
  83. Jto.authNotification()
  84. }
  85. else {
  86. // Linking.openSettings()
  87. const OneSignal = require('react-native-onesignal').OneSignal
  88. OneSignal.Notifications.requestPermission(true).then((response) => {
  89. if (response) {
  90. global.notification = 'authorized'
  91. uploadPermissions()
  92. } else {
  93. global.notification = 'denied'
  94. uploadPermissions()
  95. }
  96. });
  97. }
  98. // const test = require('@/utils/push').default
  99. // test()
  100. }
  101. else {
  102. if (kIsIOS) {
  103. Linking.openURL('app-settings:notifications')
  104. }
  105. else {
  106. Linking.openSettings()
  107. }
  108. }
  109. }