Skip to content

Open source CapCut alternative.

TypeScript

feat(ios): the camera roll import asks for photo access

David Le43c917006642
diff --git a/apps/ios/Donkey.xcodeproj/project.pbxproj b/apps/ios/Donkey.xcodeproj/project.pbxproj
index f176c705..2849517f 100644
--- a/apps/ios/Donkey.xcodeproj/project.pbxproj
+++ b/apps/ios/Donkey.xcodeproj/project.pbxproj
@@ -228,6 +228,7 @@
INFOPLIST_KEY_NSCameraUsageDescription = "Donkey Cut uses the camera to record your videos.";
INFOPLIST_KEY_NSMicrophoneUsageDescription = "Donkey Cut uses the microphone to record audio with your videos.";
INFOPLIST_KEY_NSPhotoLibraryAddUsageDescription = "Donkey saves videos you choose to your photo library.";
+ INFOPLIST_KEY_NSPhotoLibraryUsageDescription = "Donkey Cut imports photos and videos from your library into your projects.";
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
@@ -265,6 +266,7 @@
INFOPLIST_KEY_NSCameraUsageDescription = "Donkey Cut uses the camera to record your videos.";
INFOPLIST_KEY_NSMicrophoneUsageDescription = "Donkey Cut uses the microphone to record audio with your videos.";
INFOPLIST_KEY_NSPhotoLibraryAddUsageDescription = "Donkey saves videos you choose to your photo library.";
+ INFOPLIST_KEY_NSPhotoLibraryUsageDescription = "Donkey Cut imports photos and videos from your library into your projects.";
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
diff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/IdeasScreen.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/IdeasScreen.swift
index da8742e8..975b31d1 100644
--- a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/IdeasScreen.swift
+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/IdeasScreen.swift
@@ -1,5 +1,6 @@
#if os(iOS)
import AVKit
+import Photos
import PhotosUI
import SwiftUI
import DonkeyKitModels
@@ -64,7 +65,8 @@ struct IdeasScreen: View {
.photosPicker(
isPresented: $showsPhotoPicker,
selection: $pickerItems,
- matching: .any(of: [.images, .videos])
+ matching: .any(of: [.images, .videos]),
+ photoLibrary: .shared()
)
.onChange(of: pickerItems) { _, items in
guard !items.isEmpty else { return }
@@ -88,7 +90,7 @@ struct IdeasScreen: View {
private var addMenu: some View {
Menu {
Button("Paste link", systemImage: "link") { showsLinkSheet = true }
- Button("Camera roll", systemImage: "photo") { showsPhotoPicker = true }
+ Button("Camera roll", systemImage: "photo") { openCameraRoll() }
Button("New note", systemImage: "note.text") { ideas.openEditor() }
Button("New folder", systemImage: "folder.badge.plus") { folderPrompt = .create }
} label: {
@@ -102,6 +104,21 @@ struct IdeasScreen: View {
.accessibilityLabel("Add")
}
+ /// The camera roll reads the library, so the import asks for access
+ /// before it opens. Full access shows everything; a limited grant shows
+ /// the items the user hands over, with Manage inside the picker to add
+ /// more. Either choice is changeable later in Settings.
+ private func openCameraRoll() {
+ Task {
+ switch await PHPhotoLibrary.requestAuthorization(for: .readWrite) {
+ case .authorized, .limited:
+ showsPhotoPicker = true
+ default:
+ app.show(toast: "Allow photo access in Settings to import from your camera roll.")
+ }
+ }
+ }
+
private var filterChips: some View {
Picker("Filter", selection: $ideas.filter) {
ForEach(IdeasFilter.allCases, id: \.self) { filter in