PhotoKit

RSS for tag

Work with image and video assets managed by the Photos app, including those from iCloud Photos and Live Photos, using PhotoKit.

PhotoKit Documentation

Posts under PhotoKit tag

98 Posts
Sort by:
Post not yet marked as solved
0 Replies
81 Views
Environment: iOS 16 beta 2, beta 3. iPhone 11 Pro, 12 mini Steps to reproduce: Subscribe to Photo Library changes via PHPhotoLibraryChangeObserver, put some logs to track inserted/deleted objects: func photoLibraryDidChange(_ changeInstance: PHChange) { if let changeDetails = changes.changeDetails(for: allPhotosFetchResult) { for insertion in changeDetails.insertedObjects { print("🥶 INSERTED: ", insertion.localIdentifier) } for deletion in changeDetails.removedObjects { print("🥶 DELETED: ", deletion.localIdentifier) } } } Save a photo to camera roll with PHAssetCreationRequest Go to the Photo Library, delete the newly saved photo Come back to the app and watch the logs: 🥶 INSERTED:  903933C3-7B83-4212-8DF1-37C2AD3A923D/L0/001 🥶 DELETED:  39F673E7-C5AC-422C-8BAA-1BF865120BBF/L0/001 Expected result: localIdentifier of the saved and deleted asset is the same string in both logs. In fact: It's different. So it appears that either the localIdentifier of an asset gets changed after successful saving, or it's a bug in the Photos framework in iOS 16. I've checked - in iOS 15 it works fine (IDs in logs match).
Posted
by
Post not yet marked as solved
2 Replies
64 Views
iOS 16 Beta 3 introduces the "Shared Photo Library". PhotoKit however currently lacks any functionality to import photos/videos into the "Shared Photo Library" It would be welcome, if PHAssetCreationRequest could be extended with e.g. a property "destination" that defaults to the personal library, but can also be set to the shared library. Scenarios: 3rd party camera apps that should be able to import into the "Shared Library" Any type of family orientated apps that should be able to import into the "Shared Library" Filled this also as FB10577456
Posted
by
Post not yet marked as solved
3 Replies
91 Views
The smart albums PHAssetCollectionSubtypeSmartAlbumAllHidden now requires authorisation in iOS 16. How can we access PHAssetCollectionSubtypeSmartAlbumAllHidden from PhotoKit now and provide the necessary authorisation inside a 3rd party app? Cheers, Hendrik
Posted
by
Post not yet marked as solved
0 Replies
103 Views
Hello, Recently we added a change in our app that changed the resource addition to Photos - Until now we called addResourceWithType:fileURL:options: with PHAssetResourceCreationOptions.shouldMoveFile set to YES, and when we changed it to NO (the default value) we observed much more asset creation failures. Specifically we see a new error code in the procedure - PHPhotosErrorNotEnoughSpace. One can clearly see a connection between adding more storage to the file system and an asset creation failure that is related to storage, but we are struggling to understand a few things: The storage of the device is always higher than the video size, usually by a great amount - We observed failures for devices with 120GB free storage, while the video size was 200MB. Generally we save quite a lot of resources to the file system, so it is quite surprising to see supposedly storage issues when adding a relatively low amount of extra storage. The asset creation is part of a bigger procedure of encoding a video to a file system, and then moving/copying it to Photos. Is it that big of a difference to copy a video of 100MB-200MB instead of moving it, such that the overall procedure failure will increase drastically? Appreciate any help.
Posted
by
Post not yet marked as solved
0 Replies
89 Views
Pick 2 Photo with PhotosPicker Deselect 2 Photo in PhotosPicker And Done selection(PhotosPickerItem) doesn't change PhotosPicker(selection: $photoPickerItems, maxSelectionCount: 0, selectionBehavior: .ordered, matching: nil, preferredItemEncoding: .current, photoLibrary: .shared()) { Image(systemName: "photo") }
Posted
by
Post not yet marked as solved
0 Replies
110 Views
Our team has implemented PHPickerViewController to allow multiple photos to be selected. It works fine in the simulator but when tested on actual iPad we have this strange behaviour. The first time the gallery is displayed it works fine. If we try and display the gallery again it displays a window with this message “Unable to Load Items - [Try Again]”. If I tap [Try Again] or if I use our Gallery button it does display the gallery. And it keeps cycling through this behaviour. ie. every second attempt to display the gallery leads to the “Unable to Load Items” window.   Every time we display the gallery we dismiss the old instance and create/initialize a new instance of the controller. Our code is written in objective-c… -(void)initPHPickerController     {       [self dismiss];       mPHPickerController = nullref;           PHPickerConfiguration *config = [[PHPickerConfiguration alloc] init];       config.selectionLimit = 0; // 0 represents no selection limit.       config.filter = [PHPickerFilter imagesFilter];           config.preferredAssetRepresentationMode = PHPickerConfigurationAssetRepresentationModeCurrent;           PHPickerViewController *pickerViewController = [[PHPickerViewController alloc] initWithConfiguration:config];       pickerViewController.delegate = self;           mPHPickerController = pickerViewController;     }     - (void)dismiss     {       if (mPHPickerController)       {         [+mPHPickerController dismissViewControllerAnimated:YES completion:nil];       }       ...     } Any suggestions on how to fix this ? I have seen a post on stackoverflow that this may be a bug in iOS.
Posted
by
Post not yet marked as solved
1 Replies
189 Views
While trying to save a photo to a custom album on some devices we get the following error: The operation couldn’t be completed. (PHPhotosErrorDomain error 3300). code: 3300 This is the part of the code where the issue happens PHPhotoLibrary.shared().performChanges({ let assetChangeRequest = PHAssetChangeRequest.creationRequestForAsset(from: image) guard let placeholder = assetChangeRequest.placeholderForCreatedAsset else { return } let albumChangeRequest = PHAssetCollectionChangeRequest(for: album) albumChangeRequest?.addAssets([placeholder] as NSArray) }, completionHandler: { success, error in completion(success, error) }) I would be thankful for any tips since I am out of ideas.
Posted
by
Post not yet marked as solved
1 Replies
170 Views
I use PHPhotoLibrary in iOS to save JPG files to the camera roll. There is a difference in the date and time displayed in the "Photos" app depending on whether the 24-hour display setting in iOS is set to On or Off when saving. When saving with "24-hour display: Off", the date and time in the Exif of the JGP file is displayed. When saved with "24 Hour Display: On", the date and time when the file was saved is displayed. JPG files are saved with the following code. HPhotoLibrary.shared().performChanges({ PHAssetChangeRequest.creationRequestForAssetFromImage(atFileURL: jpgFileUrl) }, completionHandler: { (success: Bool, error: Error?) in print("success=\(success), error=\(String(describing: error))") }) Is this an iOS specification or a bug? Or is there a problem with the code? I would appreciate it if you could provide me with some information. Thank you in advance.
Posted
by
Post not yet marked as solved
2 Replies
241 Views
I use loadFileRepresentation(forTypeIdentifier:completionHandler:) to load video with PHPickerViewController What can I use load video with? // my sample code func loadPhoto(pickerItem: PhotosPickerItem) async throws -> Photo {     if let livePhoto = try await pickerItem.loadTransferable(type: PHLivePhoto.self) {       let photo: Photo = .init(id: pickerItem.itemIdentifier, item: livePhoto)       return photo     } else if let url = try await pickerItem.loadTransferable(type: URL.self) {       let photo: Photo = .init(id: pickerItem.itemIdentifier, item: url)       return photo     } else if let data = try await pickerItem.loadTransferable(type: Data.self) {       let photo: Photo = .init(id: pickerItem.itemIdentifier, item: data)       return photo     }     throw PhotoError.load   }
Posted
by
Post not yet marked as solved
1 Replies
191 Views
Incident Identifier: 3400A577-E4A0-483B-AF20-53F105BCB104 CrashReporter Key: 8d970b914f1fd529bba76fcaa1d0ba1588c88c47 Hardware Model: iPhone14,5 Process: Animalsocial [1096] Path: /private/var/containers/Bundle/Application/A645D0E7-C811-4A46-977C-0D46A755C68A/Animalsocial.app/Animalsocial Identifier: org.reactjs.developer.Animalsocial Version: 1.0 (1) Code Type: ARM-64 (Native) Role: Foreground Parent Process: launchd [1] Coalition: org.reactjs.developer.Animalsocial [550] Date/Time: 2022-06-10 20:11:40.0525 +0530 Launch Time: 2022-06-10 20:11:30.5303 +0530 OS Version: iPhone OS 15.5 (19F77) Release Type: User Baseband Version: 1.61.00 Report Version: 104 Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000014000 Exception Codes: 0x0000000000000001, 0x0000000000014000 VM Region Info: 0x14000 is not in any region. Bytes before following region: 4307402752 REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL UNUSED SPACE AT START ---> __TEXT 100bf0000-1022e8000 [ 23.0M] r-x/r-x SM=COW .../Animalsocial Exception Note: EXC_CORPSE_NOTIFY Termination Reason: SIGNAL 11 Segmentation fault: 11 Terminating Process: exc handler [1096] Triggered by Thread: 0 Thread 0 name: Dispatch queue: com.apple.main-thread Thread 0 Crashed: 0 libobjc.A.dylib 0x1c6e04c54 weak_entry_insert(weak_table_t*, weak_entry_t*) + 72 1 libobjc.A.dylib 0x1c6e0dffc weak_resize(weak_table_t*, unsigned long) + 112 2 libobjc.A.dylib 0x1c6dfea44 weak_register_no_lock + 256 3 libobjc.A.dylib 0x1c6e03924 objc_storeWeak + 448 4 Foundation 0x1af890ba4 -[NSConcreteHashTable addObject:] + 100 5 Animalsocial 0x1013ca198 -[SDImagePhotosLoader requestImageWithURL:options:context:progress:completed:] + 1216 6 Animalsocial 0x10139fc18 -[SDImageLoadersManager requestImageWithURL:options:context:progress:completed:] + 444 7 Animalsocial 0x1013b5240 -[SDWebImageManager callDownloadProcessForOperation:url:options:context:cachedImage:cachedData:cacheType:progress:completed:] + 1632 8 Animalsocial 0x1013b4164 __89-[SDWebImageManager callCacheProcessForOperation:url:options:context:progress:completed:]_block_invoke + 644 9 Animalsocial 0x10138c048 __73-[SDImageCache queryCacheOperationForKey:options:context:cacheType:done:]_block_invoke_2 + 56 10 libdispatch.dylib 0x1add7ae6c _dispatch_call_block_and_release + 32 11 libdispatch.dylib 0x1add7ca30 _dispatch_client_callout + 20 12 libdispatch.dylib 0x1add8af48 _dispatch_main_queue_drain + 928 13 libdispatch.dylib 0x1add8ab98 _dispatch_main_queue_callback_4CF + 44 14 CoreFoundation 0x1ae0cd800 CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 16 15 CoreFoundation 0x1ae087704 __CFRunLoopRun + 2532 16 CoreFoundation 0x1ae09abc8 CFRunLoopRunSpecific + 600 17 GraphicsServices 0x1ca1ce374 GSEventRunModal + 164 18 UIKitCore 0x1b0a0a648 -[UIApplication _run] + 1100 19 UIKitCore 0x1b078bd90 UIApplicationMain + 364 20 Animalsocial 0x100bf6258 main + 104 21 dyld 0x104e7dce4 start + 520 Thread 1 name: Dispatch queue: com.apple.avplayeritem.figplaybackitem.accessor Thread 1: 0 libsystem_kernel.dylib 0x1e5b4bf24 __psynch_cvwait + 8 1 libsystem_pthread.dylib 0x21f25f298 _pthread_cond_wait + 1236 2 CoreMedia 0x1b8c348c4 WaitOnCondition + 20 3 CoreMedia 0x1b8c91bd0 FigConditionVariableWaitRelative + 16 4 MediaToolbox 0x1b8430574 itemasync_CopyProperty + 500 5 AVFCore 0x1b76da950 +[AVPlayerItem _copyTimebaseFromFigPlaybackItem:] + 180 6 AVFCore 0x1b7707620 __31-[AVPlayerItem _updateTimebase]_block_invoke + 80 7 libdispatch.dylib 0x1add7ae6c _dispatch_call_block_and_release + 32 8 libdispatch.dylib 0x1add7ca30 _dispatch_client_callout + 20 9 libdispatch.dylib 0x1add84124 _dispatch_lane_serial_drain + 668 10 libdispatch.dylib 0x1add84c80 _dispatch_lane_invoke + 392 11 libdispatch.dylib 0x1add8f500 _dispatch_workloop_worker_thread + 648 12 libsystem_pthread.dylib 0x21f2580bc _pthread_wqthread + 288 13 libsystem_pthread.dylib 0x21f257e5c start_wqthread + 8 Thread 2 name: Dispatch queue: com.apple.avplayeritem.figplaybackitem.accessor Thread 2: 0 libsystem_kernel.dylib 0x1e5b4bf24 __psynch_cvwait + 8 1 libsystem_pthread.dylib 0x21f25f298 _pthread_cond_wait + 1236 2 CoreMedia 0x1b8c348c4 WaitOnCondition + 20 3 CoreMedia 0x1b8c91bd0 FigConditionVariableWaitRelative + 16 4 MediaToolbox 0x1b8430574 itemasync_CopyProperty + 500 5 AVFCore 0x1b76da950 +[AVPlayerItem _copyTimebaseFromFigPlaybackItem:] + 180 6 AVFCore 0x1b7707620 __31-[AVPlayerItem _updateTimebase]_block_invoke + 80 7 libdispatch.dylib 0x1add7ae6c _dispatch_call_block_and_release + 32 8 libdispatch.dylib 0x1add7ca30 _dispatch_client_callout + 20 9 libdispatch.dylib 0x1add84124 _dispatch_lane_serial_drain + 668 10 libdispatch.dylib 0x1add84c80 _dispatch_lane_invoke + 392 11 libdispatch.dylib 0x1add8f500 _dispatch_workloop_worker_thread + 648 12 libsystem_pthread.dylib 0x21f2580bc _pthread_wqthread + 288 13 libsystem_pthread.dylib 0x21f257e5c start_wqthread + 8 Thread 3 name: com.apple.uikit.eventfetch-thread Thread 3: 0 libobjc.A.dylib 0x1c6e1c3c4 class_rw_t::methods() const + 112 1 libobjc.A.dylib 0x1c6dfc2b4 class_copyMethodList + 144 2 BaseBoard 0x1b368a084 BSProtobufClassImplmementsProtobufSchema + 40 3 BaseBoard 0x1b36b45ac _BSProtobufValidateClassForEncoding + 44 4 BaseBoard 0x1b367d174 +[BSProtobufSerialization
Posted
by
Post not yet marked as solved
2 Replies
298 Views
Used to be able to assign a Live Photo as a new Wallpaper showing the static and video image prior to iOS 16. The beta version of iOS 16.0 accepts the Live Photo as a static image only. Not sure if this is a bug in the current prerelease or a permanently dropped feature. Anyone else observed this issue?
Posted
by
Post marked as solved
2 Replies
199 Views
PHPickerViewController crashes with the error 'Picker's configuration is not a valid configuration.' when I try to use PHPickerViewController with a configuration that has preselectedAssetIdentifiers specified, and I can't figure out why. The identifier looks like "12345678-1234-1234-123456789012/L0/001", and I'm getting it from PHPickerResult.assetIdentifier. The exact same code works if I specify preselectedAssetIdentifiers as an empty array. I was worried that it was just undocumented that this feature required full photo library permissions, but after giving .readWrite permissions I still experience the issue. My iPhone 13 Pro is running 15.4.1. The only lead on this I've found is https://stackoverflow.com/questions/71765492/pickers-configuration-is-not-a-valid-configuration-swift, but I'm uncomfortable with the solution of recreating my project without identifying a cause that I can avoid in the future.
Posted
by
Post not yet marked as solved
0 Replies
134 Views
Is there a way to update the metadata of a AVAsset/PHAsset to show a different still photo when the asset is not being played? If so what class should I look at to update the AVAsset or PHAsset? I am looking to edit the asset itself, not show a layer over the video. I would prefer to do this without trimming the video.
Posted
by
Post not yet marked as solved
1 Replies
167 Views
There's only a single function under PHPickerViewControllerDelegate which is didFinishPicking according to the documentation. How do I implement dismiss for the Cancel button that comes along when tapping out with PHPickerViewController? Have no problem if continue using UIImagePickerControllerDelegate, as it comes with imagePickerControllerDidCancel . However, if I were to implement with the new PHPickerViewController that currently only have a single function, how to enable proper dismiss right on the click of Cancel button instead of just relying the swipe down to dismiss the screen. Kindly advise. Thanks.
Posted
by