FlutterWay / gallery_picker

MIT License
6 stars 5 forks source link

App Crash in IOS #4

Closed Ashhad08 closed 4 months ago

Ashhad08 commented 4 months ago

After giving permission the app crashed in IOS and this error was logged

[GETX] Instance "PhoneGalleryController" has been created [GETX] Instance "PhoneGalleryController" has been initialized photo_gallery/SwiftPhotoGalleryPlugin.swift:295: Fatal error: Unexpectedly found nil while unwrapping an Optional value Lost connection to device. Exception: Unable to terminate com.connectummah.connectUmmah on A3641B21-842C-48EF-BB2D-6CC533970713: ProcessException: Process exited abnormally:

Command: xcrun simctl terminate A3641B21-842C-48EF-BB2D-6CC533970713 com.connectummah.connectUmmah the Dart compiler exited unexpectedly.

Ashhad08 commented 4 months ago

Replace this code let assets = albumId == "__ALL__" ? PHAsset.fetchAssets(with: fetchOptions) : PHAsset.fetchAssets(in: self.assetCollections.first(where: { (collection) -> Bool in collection.localIdentifier == albumId })!, options: fetchOptions)

by this code in SwiftPhotoGalleryPlugin.swift

var assets: PHFetchResult<PHAsset>

if albumId == "__ALL__" {
    assets = PHAsset.fetchAssets(with: fetchOptions)
} else if let collection = self.assetCollections.first(where: { $0.localIdentifier == albumId }) {
    assets = PHAsset.fetchAssets(in: collection, options: fetchOptions)
} else {
    // Handle the case where the collection is nil
    print("Error: Collection with ID \(albumId) not found")
    // You might want to provide a default value or handle this case according to your app's logic
    // For now, let's just assign an empty fetch result
    assets = PHAsset.fetchAssets(with: fetchOptions)
}