-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from dxclancy/main
Allow the user to create an album in Photos from the currently filtered/sorted view of the FaceGrid @dxclancy Better error handling Toolbar refactor
- Loading branch information
Showing
12 changed files
with
237 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ DerivedData/ | |
*.ipa | ||
*.dSYM.zip | ||
*.dSYM | ||
.DS_Store | ||
|
||
## Playgrounds | ||
timeline.xctimeline | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>$(DEVELOPMENT_LANGUAGE)</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundlePackageType</key> | ||
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleVersion</key> | ||
<string>1</string> | ||
<key>UIApplicationSceneManifest</key> | ||
<dict> | ||
<key>UIApplicationSupportsMultipleScenes</key> | ||
<true/> | ||
</dict> | ||
<key>UIApplicationSupportsIndirectInputEvents</key> | ||
<true/> | ||
</dict> | ||
<dict/> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// PhotoLibraryAPI.swift | ||
// FaceExplorer | ||
// | ||
// Created on 11/27/23. | ||
|
||
import Foundation | ||
import Photos | ||
|
||
struct PhotosLibraryAPI { | ||
/// Create a new album in Photos.app with chosen photos | ||
/// using the native Photos API. | ||
/// This brings about some challenges, as the native API always operates on the system library, | ||
/// while FaceExplorer can use any .photoslibrary file. | ||
/// - Parameters: | ||
/// - name: the name of the new album | ||
/// - localIdentifiers: List of localIdentiers for photos to be added to the album | ||
func createAlbum(name: String, withLocalIdentifiers localIdentifiers: [String]) async throws { | ||
let allPhotosOptions = PHFetchOptions() | ||
allPhotosOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: true)] | ||
allPhotosOptions.predicate = NSPredicate(format: "localIdentifier in %@", localIdentifiers) | ||
let phAssetsToAdd = PHAsset.fetchAssets(with: allPhotosOptions) | ||
|
||
// Make an album with the assets | ||
var newAlbumRequest: PHAssetCollectionChangeRequest? | ||
var albumLocalIdentifier: String? | ||
try await PHPhotoLibrary.shared().performChanges { | ||
newAlbumRequest = PHAssetCollectionChangeRequest.creationRequestForAssetCollection(withTitle: name) | ||
albumLocalIdentifier = newAlbumRequest!.placeholderForCreatedAssetCollection.localIdentifier | ||
} | ||
if albumLocalIdentifier == nil { | ||
throw AlbumCreationError.runtimeError("Failed to create album: \(name)") | ||
} | ||
|
||
try await PHPhotoLibrary.shared().performChanges { | ||
let newlyCreatedAlbum = PHAssetCollection.fetchAssetCollections( | ||
withLocalIdentifiers: [albumLocalIdentifier!], options: nil | ||
).firstObject | ||
let addToAlbumChangeRequest = PHAssetCollectionChangeRequest(for: newlyCreatedAlbum!) | ||
addToAlbumChangeRequest!.addAssets(phAssetsToAdd) | ||
} | ||
} | ||
|
||
enum AlbumCreationError: Error { | ||
case runtimeError(String) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.