UNPKG

onboardsync-react-native

Version:

Expo SDK for OnboardSync - Remote onboarding configuration platform with A/B testing

116 lines 5.18 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.PermissionsHandler = void 0; const react_native_1 = require("react-native"); const expo_camera_1 = require("expo-camera"); const MediaLibrary = __importStar(require("expo-media-library")); const Location = __importStar(require("expo-location")); const Contacts = __importStar(require("expo-contacts")); const Notifications = __importStar(require("expo-notifications")); class PermissionsHandler { static async requestPermission(permission) { console.log(`[OnboardSync] Requesting permission: ${permission}`); try { switch (permission) { case 'camera': { const { status } = await expo_camera_1.Camera.requestCameraPermissionsAsync(); const granted = status === 'granted'; console.log(`[OnboardSync] Camera permission ${granted ? 'granted' : 'denied'}`); if (!granted) { this.showSettingsAlert('Camera'); } return granted; } case 'photos': { const { status } = await MediaLibrary.requestPermissionsAsync(); const granted = status === 'granted'; console.log(`[OnboardSync] Photos permission ${granted ? 'granted' : 'denied'}`); if (!granted) { this.showSettingsAlert('Photos'); } return granted; } case 'location': { const { status } = await Location.requestForegroundPermissionsAsync(); const granted = status === 'granted'; console.log(`[OnboardSync] Location permission ${granted ? 'granted' : 'denied'}`); if (!granted) { this.showSettingsAlert('Location'); } return granted; } case 'contacts': { const { status } = await Contacts.requestPermissionsAsync(); const granted = status === 'granted'; console.log(`[OnboardSync] Contacts permission ${granted ? 'granted' : 'denied'}`); if (!granted) { this.showSettingsAlert('Contacts'); } return granted; } case 'notification': { const { status } = await Notifications.requestPermissionsAsync(); const granted = status === 'granted'; console.log(`[OnboardSync] Notifications permission ${granted ? 'granted' : 'denied'}`); if (!granted) { this.showSettingsAlert('Notifications'); } return granted; } default: console.warn(`[OnboardSync] Unknown permission type: ${permission}`); return false; } } catch (error) { console.error(`[OnboardSync] Error requesting permission ${permission}:`, error); return false; } } static showSettingsAlert(permission) { react_native_1.Alert.alert(`${permission} Permission Required`, `Please enable ${permission} access in your device settings to use this feature.`, [ { text: 'Cancel', style: 'cancel' }, { text: 'Open Settings', onPress: () => { react_native_1.Linking.openSettings(); } }, ]); } } exports.PermissionsHandler = PermissionsHandler; //# sourceMappingURL=permissionsHandler.js.map