kmorkos / flutter_photokit

Flutter plugin to interact with iOS PhotoKit
Other
8 stars 15 forks source link

FlutterPhotokit.saveToCameraRoll and saveToAlbum crash the app #3

Open rogiervandenberg opened 5 years ago

rogiervandenberg commented 5 years ago

When running your example on my iPhone simulator (iPhone XS Max • 6F9DE665-62D8-4DCC-A47B-CA97DAF9BD01 • ios • iOS 12.0 (simulator)) it crashes:

Reproduce with the code example

git clone git@github.com:kmorkos/flutter_photokit.git
cd flutter_photokit/example
flutter run -d 'iPhone XS Max'

When clicking the 'save to camera roll' button, it crashes. From within my own project I found out that it crashes on the line of FlutterPhotokit.saveToCameraRoll. But I cannot get any further feedback unfortunately, because of Lost connection to device. Exited (sigterm).

My setup

[✓] Flutter (Channel beta, v0.9.4, on Mac OS X 10.13.6 17G65, locale en-NL)
    • Flutter version 0.9.4 at /Users/rogier/DEV/flutter
    • Framework revision f37c235c32 (4 weeks ago), 2018-09-25 17:45:40 -0400
    • Engine revision 74625aed32
    • Dart version 2.1.0-dev.5.0.flutter-a2eb050044

[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
    • Android SDK at /Users/rogier/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 27.0.3
    • ANDROID_HOME = /Users/rogier/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 10.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.0, Build version 10A255
    • ios-deploy 1.9.2
    • CocoaPods version 1.5.3

[✓] Android Studio (version 3.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 29.1.1
    • Dart plugin version 181.5656
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

[✓] VS Code (version 1.28.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 2.19.0

[✓] Connected devices (2 available)
    • G8231         • QV700E8M0K                           • android-arm64 • Android 8.0.0 (API 26)
    • iPhone XS Max • 6F9DE665-62D8-4DCC-A47B-CA97DAF9BD01 • ios           • iOS 12.0 (simulator)

• No issues found!
rogiervandenberg commented 5 years ago

I just found out through XCode: "This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSPhotoLibraryUsageDescription key with a string value explaining to the user how the app uses this data."

Solution is to change the NSPhotoLibraryAddUsageDescription value in the Info.plist into NSPhotoLibraryUsageDescription.

4

kmorkos commented 5 years ago

That's strange, according to the docs:

NSPhotoLibraryAddUsageDescription (String - iOS) This key lets you describe the reason your app seeks write-only access to the user’s photo library. When the system prompts the user to allow access, this string is displayed as part of the alert.

NSPhotoLibraryUsageDescription (String - iOS) This key lets you describe the reason your app accesses the user’s photo library. When the system prompts the user to allow access, this string is displayed as part of the alert.

Although this keys governs read and write access to the user’s photo library, it’s best to use NSPhotoLibraryAddUsageDescription if your app needs only to add assets to the library and does not need to read any assets.

This plugin never accesses the photo library, just writes to it which is why I used NSPhotoLibraryAddUsageDescription (this worked when I tested with iOS 11). I unfortunately do not have access to a Mac to test with anymore, so I can't test behavior on iOS 12.

tyl0r commented 5 years ago

I can confirm that my app crashes when I only have NSPhotoLibraryAddUsageDescription in my Info.plist file. Changing to NSPhotoLibraryUsageDescription fixed the issue for me. I'm on iOS 12.2 and MacOS 10.14.4 using Android Studio.

In my case I need read access to the library as well, not just write access.

danieleformichelli commented 5 years ago

Same problem here. NSPhotoLibraryUsageDescription should not be required to add image to the gallery