lisen87 / image_pickers

图片多选并压缩,保存图片到相册,视频多选,预览图片和视频
Apache License 2.0
90 stars 59 forks source link

NSInvalidArgumentException when calling ImagePickers.pickerPaths() #123

Open ppbrasil opened 1 year ago

ppbrasil commented 1 year ago

Device: iPhone Xs (16.6.1) image_pickers: ^2.0.4+3

I'm getting NSInvalidArgumentException when retrieving some media (not a clear pattern here) in iOS devices

I have this simple function on my repo

  Future<Either<Failure, List<dynamic>>>
      performGetObjectListFromDevice() async {
    try {
      log.fine(
          'MediaService called for retrieval of media objects from device');
      final List<dynamic> objectsList =
          await mediaServices.getObjectsListFromDevice();
      log.fine(
          'MediaService Successfully retrieved ${objectsList.length} media objects from device');
      return Right(objectsList);
    } on MediaServiceException catch (e) {
      log.warning('MediaServiceException encountered: ${e.message}');
      return const Left(ServerFailure(
          message: "Couldn't retrieve list of media from device"));
    }
  }

Which calls

@override
  Future<List<dynamic>> getObjectsListFromDevice() async {
    List<imagePickers.Media> listVideoPaths = [];
    try {
      listVideoPaths = await imagePickers.ImagePickers.pickerPaths(
        galleryMode: imagePickers.GalleryMode.all,
        videoSelectMaxSecond: 1200,
        videoRecordMaxSecond: 1200,
        selectCount: 10,
      );
    } on Exception catch (e) {
      log.severe(
          'imagePickers library failed to return pickersPath\n--imagePickers: $e');
      rethrow;
    }
    return listVideoPaths;
  }

As you can see in the log below, execution brakes when calling ImagePickers.pickerPaths()

== LOG ==

flutter: [MemoriesRepositoryImpl] FINE: 2023-10-14 13:54:57.349108: MediaService called for retrieval of media objects from device
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
*** First throw call stack:
(0x197380cb4 0x1904203d0 0x19165f8c0 0x19165f63c 0x1012add0c 0x1012ad2c8 0x1ac3f5f60 0x19e856fc4 0x19e847eac 0x19e84b330 0x19e84a998 0x19e859944 0x19e85a158 0x1f71b5da0 0x1f71b5b7c)
libc++abi: terminating due to uncaught exception of type NSException
* thread #43, queue = 'com.apple.photos.requestAVAsset', stop reason = signal SIGABRT
    frame #0: 0x00000001d633d578 libsystem_kernel.dylib`__pthread_kill + 8
libsystem_kernel.dylib`:
->  0x1d633d578 <+8>:  b.lo   0x1d633d598               ; <+40>
    0x1d633d57c <+12>: pacibsp
    0x1d633d580 <+16>: stp    x29, x30, [sp, #-0x10]!
    0x1d633d584 <+20>: mov    x29, sp
Target 0: (Runner) stopped.
Lost connection to device.
ppbrasil commented 1 year ago

FYI: After calling ImagePickers.pickerPaths() but before selection is confirmed (done is clicked) I get the following message in the debug console

flutter: [GetObjectsListFromDeviceUseCase] FINE: 2023-10-14 14:33:38.422599: MemoriesRepository performGetObjectListFromDevice call with no Params
flutter: [MemoriesRepositoryImpl] FINE: 2023-10-14 14:33:38.423265: MediaService called for retrieval of media objects from device
[core] "Error returned from daemon: Error Domain=com.apple.accounts Code=7 "(null)""
[PAAccessLogger] Failed to log access with error: access=<PATCCAccess 0x2817728a0> accessor:<<PAApplication 0x28174cd20 identifierType:auditToken identifier:{pid:4872, version:13663}>> identifier:A64DED7B-B144-4D1E-9941-B3E021FBF668 kind:intervalEvent timestampAdjustment:0 visibilityState:0 assetIdentifierCount:0 tccService:kTCCServicePhotos, error=Error Domain=NSCocoaErrorDomain Code=4097 "connection to service with pid 3358 named com.apple.privacyaccountingd" UserInfo={NSDebugDescription=connection to service with pid 3358 named com.apple.privacyaccountingd}

As per the instructions, my plist is set as


<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>
<key>NSCameraUsageDescription</key>
<string>Needed for you to create videos and photo memories</string>
<key>NSMicrophoneUsageDescription</key>
<string>Needed for you to add sound to your videos memories</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Needed for you to upload your media</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>Needed for you to record new media</string>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
cuixiaocun commented 1 year ago

you can also add permissions

PHPhotoLibraryPreventAutomaticLimitedAccessAlert
<true/>

although this is not the solution to the problem [PAAccessLogger] Failed to log access with error: access=<PATCCAccess 0x2817728a0> or You can ignore this issue. This warning will not affect the normal operation of your program

FYI: After calling ImagePickers.pickerPaths() but before selection is confirmed (done is clicked) I get the following message in the debug console

flutter: [GetObjectsListFromDeviceUseCase] FINE: 2023-10-14 14:33:38.422599: MemoriesRepository performGetObjectListFromDevice call with no Params
flutter: [MemoriesRepositoryImpl] FINE: 2023-10-14 14:33:38.423265: MediaService called for retrieval of media objects from device
[core] "Error returned from daemon: Error Domain=com.apple.accounts Code=7 "(null)""
[PAAccessLogger] Failed to log access with error: access=<PATCCAccess 0x2817728a0> accessor:<<PAApplication 0x28174cd20 identifierType:auditToken identifier:{pid:4872, version:13663}>> identifier:A64DED7B-B144-4D1E-9941-B3E021FBF668 kind:intervalEvent timestampAdjustment:0 visibilityState:0 assetIdentifierCount:0 tccService:kTCCServicePhotos, error=Error Domain=NSCocoaErrorDomain Code=4097 "connection to service with pid 3358 named com.apple.privacyaccountingd" UserInfo={NSDebugDescription=connection to service with pid 3358 named com.apple.privacyaccountingd}

As per the instructions, my plist is set as


<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>
<key>NSCameraUsageDescription</key>
<string>Needed for you to create videos and photo memories</string>
<key>NSMicrophoneUsageDescription</key>
<string>Needed for you to add sound to your videos memories</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Needed for you to upload your media</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>Needed for you to record new media</string>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>

you can also add permissions

PHPhotoLibraryPreventAutomaticLimitedAccessAlert
<true/>

although this is not the solution to the problem [PAAccessLogger] Failed to log access with error: access=<PATCCAccess 0x2817728a0> or You can ignore this issue. This warning will not affect the normal operation of your program

cuixiaocun commented 1 year ago

Device: iPhone Xs (16.6.1) image_pickers: ^2.0.4+3

I'm getting NSInvalidArgumentException when retrieving some media (not a clear pattern here) in iOS devices

I have this simple function on my repo

  Future<Either<Failure, List<dynamic>>>
      performGetObjectListFromDevice() async {
    try {
      log.fine(
          'MediaService called for retrieval of media objects from device');
      final List<dynamic> objectsList =
          await mediaServices.getObjectsListFromDevice();
      log.fine(
          'MediaService Successfully retrieved ${objectsList.length} media objects from device');
      return Right(objectsList);
    } on MediaServiceException catch (e) {
      log.warning('MediaServiceException encountered: ${e.message}');
      return const Left(ServerFailure(
          message: "Couldn't retrieve list of media from device"));
    }
  }

Which calls

@override
Future<List<dynamic>> getObjectsListFromDevice() async {
  List<imagePickers.Media> listVideoPaths = [];
  try {
    listVideoPaths = await imagePickers.ImagePickers.pickerPaths(
      galleryMode: imagePickers.GalleryMode.all,
      videoSelectMaxSecond: 1200,
      videoRecordMaxSecond: 1200,
      selectCount: 10,
    );
  } on Exception catch (e) {
    log.severe(
        'imagePickers library failed to return pickersPath\n--imagePickers: $e');
    rethrow;
  }
  return listVideoPaths;
}

As you can see in the log below, execution brakes when calling ImagePickers.pickerPaths()

== LOG ==

flutter: [MemoriesRepositoryImpl] FINE: 2023-10-14 13:54:57.349108: MediaService called for retrieval of media objects from device
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
*** First throw call stack:
(0x197380cb4 0x1904203d0 0x19165f8c0 0x19165f63c 0x1012add0c 0x1012ad2c8 0x1ac3f5f60 0x19e856fc4 0x19e847eac 0x19e84b330 0x19e84a998 0x19e859944 0x19e85a158 0x1f71b5da0 0x1f71b5b7c)
libc++abi: terminating due to uncaught exception of type NSException
* thread #43, queue = 'com.apple.photos.requestAVAsset', stop reason = signal SIGABRT
    frame #0: 0x00000001d633d578 libsystem_kernel.dylib`__pthread_kill + 8
libsystem_kernel.dylib`:
->  0x1d633d578 <+8>:  b.lo   0x1d633d598               ; <+40>
    0x1d633d57c <+12>: pacibsp
    0x1d633d580 <+16>: stp    x29, x30, [sp, #-0x10]!
    0x1d633d584 <+20>: mov    x29, sp
Target 0: (Runner) stopped.
Lost connection to device.

此问题,新的版本已更新,请更新一下代码,具体请见2.0.4+5

ppbrasil commented 1 year ago

First of all, congrats on you guys fro the super fast response on those issues.

While release ^2.0.4+5 solved the crashing issue it generated a new one. Now I'm facing several timeouts when selecting images. Unfortunately, I couldn't find a clear pattern to share with you guys. I had time out alerts while selecting one single image in the same compass that I have succeeded selecting some videos (up to 30secs).

FYI (1): In case it help, the progress indicator changed. It used to a progress indicator per selected tile and now is a generic one for the whole screen. And it's triggered not by individual selections but by clicking "done".

FYI (2): I had to pod update ZLPhotoBrowser so the code could compile