flutter-permission-handler icon indicating copy to clipboard operation
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)

Open nixonoftheyear opened this issue 3 years ago • 10 comments

🐛 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

nixonoftheyear avatar Jan 24 '21 13:01 nixonoftheyear

same :(

muhammadsaddamnur avatar Jan 27 '21 10:01 muhammadsaddamnur

I am facing same issue on iOS 14.4 with current version 5.1.0+2. Any suggestions so far? Thanks

bachras avatar Feb 18 '21 12:02 bachras

@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);

fartem avatar Feb 19 '21 06:02 fartem

@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);

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?

nixonoftheyear avatar Feb 19 '21 14:02 nixonoftheyear

@thenixoncompany You can use device_info plugin.

fartem avatar Feb 20 '21 04:02 fartem

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.

JDDV avatar Mar 24 '21 11:03 JDDV

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

lvhuy1102 avatar May 06 '21 10:05 lvhuy1102

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]);
    }];
    }
}

wenboLee avatar Jul 06 '21 03:07 wenboLee

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.

pzehle avatar Jan 11 '22 14:01 pzehle

the same to me,My device is iphone6 IOS 15.0

yaochangliang159 avatar Feb 08 '22 01:02 yaochangliang159

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.

JeroenWeener avatar Jul 12 '23 07:07 JeroenWeener

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.

github-actions[bot] avatar Jul 26 '23 08:07 github-actions[bot]