diff --git a/IceCubesApp.xcodeproj/project.pbxproj b/IceCubesApp.xcodeproj/project.pbxproj
index d92541c99..8d44e9753 100644
--- a/IceCubesApp.xcodeproj/project.pbxproj
+++ b/IceCubesApp.xcodeproj/project.pbxproj
@@ -1545,6 +1545,7 @@
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.social-networking";
INFOPLIST_KEY_NSCameraUsageDescription = "Upload photos & videos to attach to your Mastodon posts.";
INFOPLIST_KEY_NSHumanReadableCopyright = "© 2024 Thomas Ricouard";
+ INFOPLIST_KEY_NSPhotoLibraryAddUsageDescription = "Ice Cubes would like to save the selected photo in your photo library.";
INFOPLIST_KEY_NSPhotoLibraryUsageDescription = "Upload photos & videos to Mastodon";
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
@@ -1611,6 +1612,7 @@
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.social-networking";
INFOPLIST_KEY_NSCameraUsageDescription = "Upload photos & videos to attach to your Mastodon posts.";
INFOPLIST_KEY_NSHumanReadableCopyright = "© 2024 Thomas Ricouard";
+ INFOPLIST_KEY_NSPhotoLibraryAddUsageDescription = "Ice Cubes would like to save the selected photo in your photo library.";
INFOPLIST_KEY_NSPhotoLibraryUsageDescription = "Upload photos & videos to Mastodon";
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
diff --git a/IceCubesApp/App/IceCubesApp-release.entitlements b/IceCubesApp/App/IceCubesApp-release.entitlements
index 4ed805259..b0793e600 100644
--- a/IceCubesApp/App/IceCubesApp-release.entitlements
+++ b/IceCubesApp/App/IceCubesApp-release.entitlements
@@ -28,6 +28,8 @@
com.apple.security.network.client
+ com.apple.security.personal-information.photos-library
+
keychain-access-groups
$(AppIdentifierPrefix)$(BUNDLE_ID_PREFIX).IceCubesApp
diff --git a/IceCubesApp/App/IceCubesApp.entitlements b/IceCubesApp/App/IceCubesApp.entitlements
index 4ed805259..b0793e600 100644
--- a/IceCubesApp/App/IceCubesApp.entitlements
+++ b/IceCubesApp/App/IceCubesApp.entitlements
@@ -28,6 +28,8 @@
com.apple.security.network.client
+ com.apple.security.personal-information.photos-library
+
keychain-access-groups
$(AppIdentifierPrefix)$(BUNDLE_ID_PREFIX).IceCubesApp
diff --git a/Packages/MediaUI/Sources/MediaUI/MediaUIView.swift b/Packages/MediaUI/Sources/MediaUI/MediaUIView.swift
index a8c096d8b..0023d4a80 100644
--- a/Packages/MediaUI/Sources/MediaUI/MediaUIView.swift
+++ b/Packages/MediaUI/Sources/MediaUI/MediaUIView.swift
@@ -3,6 +3,7 @@ import Models
import Nuke
import QuickLook
import SwiftUI
+import Photos
public struct MediaUIView: View, @unchecked Sendable {
private let data: [DisplayData]
@@ -144,6 +145,8 @@ private struct SavePhotoToolbarItem: ToolbarContent, @unchecked Sendable {
state = .unsaved
}
}
+ } else {
+ state = .unsaved
}
}
} label: {
@@ -180,9 +183,17 @@ private struct SavePhotoToolbarItem: ToolbarContent, @unchecked Sendable {
}
return nil
}
-
+
private func saveImage(url: URL) async -> Bool {
- if let image = try? await uiimageFor(url: url) {
+ guard let image = try? await uiimageFor(url: url) else { return false }
+
+ var status = PHPhotoLibrary.authorizationStatus(for: .addOnly)
+
+ if status != .authorized {
+ await PHPhotoLibrary.requestAuthorization(for: .addOnly)
+ status = PHPhotoLibrary.authorizationStatus(for: .addOnly)
+ }
+ if status == .authorized {
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
return true
}