expo: Unrecognized permission: mediaLibrary
đ Bug Report
Summary of Issue
I have upgraded my expo sdk to the last one, and I am refactoring the permissions manager of my app. When asking for the permissions of the camera roll, I get the error âUnrecognized permission: mediaLibraryâ
Environment - output of expo diagnostics & the platform(s) youâre targeting
Expo CLI 3.27.13 environment info: System: OS: Windows 10 10.0.19041 Binaries: Node: 12.18.1 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.4 - C:\Program Files (x86)\Yarn\bin\yarn.CMD npm: 6.14.5 - C:\Program Files\nodejs\npm.CMD IDEs: Android Studio: Version 3.6.0.0 AI-192.7142.36.36.6241897 npmPackages: expo: ^40.0.0 => 40.0.0 react: ^16.13.1 => 16.14.0 react-dom: 16.11.0 => 16.11.0 react-native: ^0.63.4 => 0.63.4 react-native-web: ~0.13.7 => 0.13.18 Expo Workflow: managed
Reproducible Demo
Steps to Reproduce
Test the following code on iOS 14:
import { Camera as ExpoCamera } from "expo-camera";
import * as MediaLibrary from "expo-media-library";
import * as Permissions from "expo-permissions"; <--------
...
const [hasPermission, setHasPermission] = useState(null);
useEffect(() => { <------
// TODO - Request CAMERA and CAMERA_ROLL permissions https://docs.expo.io/versions/latest/sdk/media-library/
(async () => {
const { status } = await Permissions.askAsync(
Permissions.CAMERA,
Permissions.MEDIA_LIBRARY
);
setHasPermission(status === "granted");
})();
}, []);
Expected Behavior vs Actual Behavior
How can I be able to ask media library permissions in the new sdk?
âexpo-cameraâ: â~9.1.0â, âexpo-media-libraryâ: â~10.0.0â, âexpo-permissionsâ: â~10.0.0â,
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 33 (9 by maintainers)
weâve moved away from using the
Permissionsmodule as the central way to request permissions and prefer calling the permissions requesters directly on the modules now.so, MediaLibrary.requestPermissionsAsync() would be the solution here.
example: https://snack.expo.io/@brents/shallow-blueberries
that said, we should keep these old methods working or deprecate them
The same problem as @diegomais, I noticed, that MediaLibrary.getPermissionsAsync / MediaLibrary.requestPermissionsAsync always return {âstatusâ: âundeterminedâ, âcanAskAgainâ: false, âexpiresâ: âneverâ, âgrantedâ: false} even if manually set up this permission READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE also added to Manifest
Expo eject to react native cli, all problem will be solved đ´, you can use all expo library there, just copy paste permission syntaxâŚ
Same issue, always get this:
{âstatusâ: âundeterminedâ, âcanAskAgainâ: false, âexpiresâ: âneverâ, âgrantedâ: false}
Seems like we need an extra permission to be able to do this and itâs missing from the docs:
This solves it for me
When using MediaLibrary.saveToLibraryAsync(), I received the error:
Missing MEDIA_LIBRARY write permission. Then I added MediaLibrary.requestPermissionsAsync() before saving the media, but I still got the error:Missing MEDIA_LIBRARY write permission.The workaround was using ImagePicker.requestMediaLibraryPermissionsAsync().
It would be nice to also have MediaLibrary.requestMediaLibraryPermissionsAsync() so you donât have to use a method from another package.
@CCB-cerivera FYI I heard
Permissionsmodule is deprecated. Try MediaLibrary.requestPermissionsAsync to get the permission.Could someone help me, Iâm on IOS 15.2 (simulator) and when requesting the MEDIA_LIBRARY permission it returns [granted] however when I use expo-media-library it returns the following error:
Error: MEDIA_LIBRARY permission is required to do this operation.
Permission routine:
const { status } = await Permissions.askAsync(Permissions.MEDIA_LIBRARY);
Using requestMediaLibraryPermissionsAsync seems to have fixed the issue for me on Android
any update on this?
Same here (Android 11 API 30), any updates on this? @brentvatne UPDATE Resolved on my side The issue was that I had another package which has
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="29" />When I built app, AndroinManifest.xml was merged together and at the end I havenât got permissions for using expo-media-library@diegolmello - is this on ios or android? which android version?
on ios the permissions requesters are identical between
MediaLibrary.requestPermissionsAsync()andImagePicker.requestMediaLibraryPermissionsAsync():https://github.com/expo/expo/blob/master/packages/expo-image-picker/ios/EXImagePicker/Permissions/EXImagePickerMediaLibraryPermissionRequester.m https://github.com/expo/expo/blob/master/packages/expo-media-library/ios/EXMediaLibrary/Permissions/EXMediaLibraryMediaLibraryPermissionRequester.m