native_permission_check.tsx 4.2 KB

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