Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. import { PermissionsAndroid } from 'react-native';
  2.  
  3. export const PERMISSIONS_TYPES = {
  4. WRITE_EXTERNAL_STORAGE: 'WRITE_EXTERNAL_STORAGE',
  5. READ_EXTERNAL_STORAGE: 'READ_EXTERNAL_STORAGE',
  6. };
  7.  
  8. const PERMISSIONS = {
  9. [PERMISSIONS_TYPES.WRITE_EXTERNAL_STORAGE]: {
  10. type: 'WRITE_EXTERNAL_STORAGE',
  11. config: {
  12. title: 'MindCast App Create File Permission',
  13. message:
  14. 'MindCast needs access to your storage '
  15. + 'so you can save your podcasts locally.',
  16. },
  17. },
  18.  
  19. [PERMISSIONS_TYPES.READ_EXTERNAL_STORAGE]: {
  20. type: 'READ_EXTERNAL_STORAGE',
  21. config: {
  22. title: 'MindCast App Read File Permission',
  23. message:
  24. 'MindCast needs access to your storage '
  25. + 'so you can listen your podcasts locally and offline.',
  26. },
  27. },
  28. };
  29.  
  30. export const requestPermission = async (type) => {
  31. try {
  32. const permissionConfig = PERMISSIONS[type];
  33.  
  34. const granted = await PermissionsAndroid.request(
  35. PermissionsAndroid.PERMISSIONS[type],
  36. {
  37. ...permissionConfig.config,
  38. buttonNeutral: 'Ask Me Later',
  39. buttonNegative: 'Cancel',
  40. buttonPositive: 'OK',
  41. },
  42. );
  43.  
  44. return granted === PermissionsAndroid.RESULTS.GRANTED;
  45. } catch (err) {
  46. console.tron.log(err);
  47. }
  48. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement