| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- import { getLocalPush } from '@/features/trackTimeDuration/actions/TrackTimeActions';
- import { clientInfo } from '@/services/common';
- import Taro from '@tarojs/taro';
- import JPush from 'jpush-react-native';
- import { Alert, Linking } from 'react-native';
- import { check, PERMISSIONS, RESULTS, checkMultiple } from 'react-native-permissions';
- // import {OneSignal} from 'react-native-onesignal';
- export const checkLocation = () => {
- // JPush.isNotificationEnabled((result) => {
- // Taro.showModal({
- // title: '提示',
- // content: JSON.stringify(result)
- // })
- // });
- check(PERMISSIONS.IOS.LOCATION_ALWAYS)
- .then((result) => {
- switch (result) {
- case RESULTS.UNAVAILABLE:
- // Alert.alert('This feature is not available (on this device / in this context)');
- break;
- case RESULTS.DENIED:
- console.log('The permission has not been requested / is denied but requestable');
- break;
- case RESULTS.LIMITED:
- console.log('The permission is limited: some actions are possible');
- break;
- case RESULTS.GRANTED:
- console.log('The permission is granted');
- break;
- case RESULTS.BLOCKED:
- // console.log('The permission is denied and not requestable anymore');
- break;
- }
- })
- .catch((error) => {
- // …
- });
- }
- export const uploadPermissions = () => {
- if (Taro.getSystemInfoSync().platform == 'android') {
- checkMultiple([PERMISSIONS.ANDROID.CAMERA,
- PERMISSIONS.ANDROID.ACCESS_COARSE_LOCATION,
- PERMISSIONS.ANDROID.POST_NOTIFICATIONS]).then(statuses => {
- const OneSignal = require('react-native-onesignal').OneSignal
- OneSignal.initialize("2bbf5339-7ab8-4c5c-9a66-c3a8eaea188e");
- OneSignal.Notifications.getPermissionAsync().then((res) => {
- if (res) {
- global.notification = 'authorized'
- }
- else {
- global.notification = 'denied'
- }
- clientInfo({
- perm: {
- camera: statuses[PERMISSIONS.ANDROID.CAMERA],
- location: statuses[PERMISSIONS.ANDROID.ACCESS_COARSE_LOCATION],
- notification: global.notification
- }
- })
- })
- });
- return
- }
- checkMultiple([PERMISSIONS.IOS.CAMERA,
- PERMISSIONS.IOS.PHOTO_LIBRARY,
- PERMISSIONS.IOS.LOCATION_WHEN_IN_USE,
- PERMISSIONS.IOS.LOCATION_ALWAYS]).then(statuses => {
- if (global.notification == 'not_determined') {
- clientInfo({
- perm: {
- album: statuses[PERMISSIONS.IOS.PHOTO_LIBRARY],
- camera: statuses[PERMISSIONS.IOS.CAMERA],
- location_always: statuses[PERMISSIONS.IOS.LOCATION_ALWAYS],
- location_when_in_use: statuses[PERMISSIONS.IOS.LOCATION_WHEN_IN_USE],
- notification: 'not_determined'
- }
- })
- }
- else {
- JPush.isNotificationEnabled((res) => {
- console.log(res)
- if (res) {
- getLocalPush()
- clientInfo({
- perm: {
- album: statuses[PERMISSIONS.IOS.PHOTO_LIBRARY],
- camera: statuses[PERMISSIONS.IOS.CAMERA],
- location_always: statuses[PERMISSIONS.IOS.LOCATION_ALWAYS],
- location_when_in_use: statuses[PERMISSIONS.IOS.LOCATION_WHEN_IN_USE],
- notification: 'authorized'
- }
- })
- }
- else {
- clientInfo({
- perm: {
- album: statuses[PERMISSIONS.IOS.PHOTO_LIBRARY],
- camera: statuses[PERMISSIONS.IOS.CAMERA],
- location_always: statuses[PERMISSIONS.IOS.LOCATION_ALWAYS],
- location_when_in_use: statuses[PERMISSIONS.IOS.LOCATION_WHEN_IN_USE],
- notification: 'denied'
- }
- })
- }
- })
- }
- })
- }
- export const checkNotification = () => {
- if (Taro.getSystemInfoSync().platform == 'android') {
- const OneSignal = require('react-native-onesignal').OneSignal
- OneSignal.Notifications.canRequestPermission().then((res) => {
- if (res) {
- OneSignal.Notifications.requestPermission(true);
- }
- else {
- Linking.openSettings()
- }
- })
- return;
- }
- if (global.notification == 'not_determined') {
- if (Taro.getSystemInfoSync().platform == 'ios') {
- var Jto = require('react-native').NativeModules.NativeBridge;
- Jto.authNotification()
- }
- else {
- // Linking.openSettings()
- const OneSignal = require('react-native-onesignal').OneSignal
- OneSignal.Notifications.requestPermission(true).then((response) => {
- if (response) {
- global.notification = 'authorized'
- uploadPermissions()
- } else {
- global.notification = 'denied'
- uploadPermissions()
- }
- });
- }
- // const test = require('@/utils/push').default
- // test()
- }
- else {
- if (Taro.getSystemInfoSync().platform == 'ios') {
- Linking.openURL('app-settings:notifications')
- }
- else {
- Linking.openSettings()
- }
- }
- }
|