Created
February 18, 2019 22:43
-
-
Save steniowagner/5b9d59461cf78f43f2f6680a2cad33c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { PermissionsAndroid } from 'react-native'; | |
export const PERMISSIONS_TYPES = { | |
WRITE_EXTERNAL_STORAGE: 'WRITE_EXTERNAL_STORAGE', | |
READ_EXTERNAL_STORAGE: 'READ_EXTERNAL_STORAGE', | |
}; | |
const PERMISSIONS = { | |
[PERMISSIONS_TYPES.WRITE_EXTERNAL_STORAGE]: { | |
type: 'WRITE_EXTERNAL_STORAGE', | |
config: { | |
title: 'MindCast App Create File Permission', | |
message: | |
'MindCast needs access to your storage ' | |
+ 'so you can save your podcasts locally.', | |
}, | |
}, | |
[PERMISSIONS_TYPES.READ_EXTERNAL_STORAGE]: { | |
type: 'READ_EXTERNAL_STORAGE', | |
config: { | |
title: 'MindCast App Read File Permission', | |
message: | |
'MindCast needs access to your storage ' | |
+ 'so you can listen your podcasts locally and offline.', | |
}, | |
}, | |
}; | |
export const requestPermission = async (type) => { | |
try { | |
const permissionConfig = PERMISSIONS[type]; | |
const granted = await PermissionsAndroid.request( | |
PermissionsAndroid.PERMISSIONS[type], | |
{ | |
...permissionConfig.config, | |
buttonNeutral: 'Ask Me Later', | |
buttonNegative: 'Cancel', | |
buttonPositive: 'OK', | |
}, | |
); | |
return granted === PermissionsAndroid.RESULTS.GRANTED; | |
} catch (err) { | |
console.tron.log(err); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment