flutter-permission-handler
flutter-permission-handler copied to clipboard
In iOS 14.3 the storage permission status is granted with $ await Permission.storage.status but is actually denied. (only iOS, not for Android)
🐛 Bug Report
await Permission.storage.request ().isGranted brings up the pop-up asking you to add files to the storage (in my case I'm going to add photos and videos). If permissions are denied, in subsequent calls the permissions with await Permission.storage.status are actually granted and not denied or permanentlyDenied. This results in later error when you think you have permission to save photos and videos and don't actually have them.
Expected behavior
Expected PermissionStatus.denied or PermissionStatus.permanentlyDenied
Reproduction steps
Like description. For testing you can simple request and deny. After not granting permissions, use the storage for example to save an image or video.
Configuration
[✓] Flutter (Channel stable, 1.22.5, on macOS 11.1 20C69 darwin-x64, locale en-GB)
Version: flutter-permission-handler: 5.0.1+1
Platform:
- :iphone: iOS 14.3
same :(
I am facing same issue on iOS 14.4 with current version 5.1.0+2. Any suggestions so far? Thanks
@thenixoncompany @muhammadsaddamnur @bachras For iOS 14 you need to request Photos
permission, not Storage
. Plugin supports to request this permission, for example:
final photosPermissionStatus = await Permission.photos.request();
And in sources:
/// Android: Nothing
/// iOS: Photos
/// iOS 14+ read & write access level
static const photos = Permission._(9);
@thenixoncompany @muhammadsaddamnur @bachras For iOS 14 you need to request
Photos
permission, notStorage
. Plugin supports to request this permission, for example:final photosPermissionStatus = await Permission.photos.request();
And in sources:
/// Android: Nothing /// iOS: Photos /// iOS 14+ read & write access level static const photos = Permission._(9);
So the Permission.photos is only for iOS 14+? Is there therefore to check the iOS version and use different permissions based on the version?
@thenixoncompany You can use device_info plugin.
Hi @thenixoncompany, would you please be so kind to tell us if the solution offered by @fartem solved your problem so the issue can be closed.
Hi @thenixoncompany, would you please be so kind to tell us if the solution offered by @fartem solved your problem so the issue can be closed.
still not work on ios 14.5
i write a swift method which is can return real permission status.
/// dart
/// notDetermined 0
/// restricted 1
/// denied 2
/// authorized 3
/// limited 4
static Future<int> photoPermissionStatus() async {
return await _channel.invokeMethod('photoPermissionStatus');
}
// swift
public func photoPermissionStatus(result: @escaping FlutterResult) {
if #available(iOS 14.0, *){
let status = PHPhotoLibrary.authorizationStatus(for: .readWrite);
result(status.rawValue)
}else{
let status = PHPhotoLibrary.authorizationStatus();
result(status.rawValue)
}
}
// return 3 , correct.
so, i think the order is wrong.
// source code <https://github.com/Baseflow/flutter-permission-handler/blob/master/permission_handler/ios/Classes/strategies/PhotoPermissionStrategy.m>
- (void)requestPermission:(PermissionGroup)permission completionHandler:(PermissionStatusHandler)completionHandler {
PermissionStatus status = [self checkPermissionStatus:permission];
// ----- should depredate
if (status != PermissionStatusDenied) {
completionHandler(status);
return;
}
// ----- front handle
if(@available(iOS 14, *)) {
[PHPhotoLibrary requestAuthorizationForAccessLevel:(addOnlyAccessLevel)?PHAccessLevelAddOnly:PHAccessLevelReadWrite handler:^(PHAuthorizationStatus authorizationStatus) {
completionHandler([PhotoPermissionStrategy determinePermissionStatus:authorizationStatus]);
}];
}else {
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus authorizationStatus) {
completionHandler([PhotoPermissionStrategy determinePermissionStatus:authorizationStatus]);
}];
}
}
This is still happening even on iOS 15.2. I don't seem to find any workaround for this but to use another library.
Some people above commented that photos
permission should be given in order to save photos to device starting on iOS 14. This is actually wrong, as if I request permissions to storage, and I grant them the first time, it allows me to download and everything works normal.
The problem is when permission is denied and you want to request them again, the status comes as .isGranted
, when it is not.
the same to me,My device is iphone6 IOS 15.0
Hi @nixonoftheyear, thanks for filing a bug report!
On the latest version of the plugin (10.4.2), Permission.storage
is always granted on iOS.
From the source code documentation:
/// iOS: Access to folders like `Documents` or `Downloads`. Implicitly
/// granted.
static const storage = Permission._(15);
For the implementation, see https://github.com/Baseflow/flutter-permission-handler/blob/main/permission_handler_apple/ios/Classes/strategies/StoragePermissionStrategy.m and https://github.com/Baseflow/flutter-permission-handler/blob/main/permission_handler_platform_interface/lib/src/permissions.dart.
It is expected behavior that Permission.storage.request() returns immediately with PermissionStatus.granted. Also, no permission dialog should show up. I see some comments (@pzehle) that mention that a permission dialog is popping up. Can you confirm that this is also happening on 10.4.2?
There are some other permissions that can be relevant for your use case, namely mediaLibrary
, photos
and photosAddOnly
.
Please let me know if everything works as expected on 10.4.2. If it does not, a minimal reproducible code sample and the iOS version could help us track down the issue.
Without additional information, we are unfortunately not able to resolve this issue. Therefore, we reluctantly closed this issue for now. If you run into this issue later, feel free to file a new issue with a reference to this issue. Add a description of detailed steps to reproduce, expected and current behaviour, logs and the output of 'flutter doctor -v'. Thanks for your contribution.