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.

Posts under PhotoKit tag

80 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

How to edit gain map image to preserve HDR in Live Photo
I have an app that allows you to edit your photos. To preserve HDR, I edit both the SDR image and gain map image, like so: let sdrImage = CIImage(data: data, options: [.applyOrientationProperty: true]) let gainMapImage = CIImage(data: data, options: [.applyOrientationProperty: true, .auxiliaryHDRGainMap: true]) // edit them... try CIContext().writeHEIFRepresentation(of: sdrImage, to: url, format: .RGBA8, colorSpace: colorSpace, options: [.hdrGainMapImage: gainMapImage]) I also support editing the still photo in Live Photos. To do this you create a PHLivePhotoEditingContext, set the frameProcessor block which gives you a CIImage that I edit when the frame.type is .photo, then you create a PHContentEditingOutput and call saveLivePhoto. I’m not seeing any way to preserve HDR here. Interestingly the frame processor is called twice with .photo frame.type, but I don’t see any difference between these images. How can I edit a gain map image to preserve HDR in the still photo of a Live Photo?
0
0
99
4d
LockedCameraCaptureExtension can not get access to photo library
I've requested the authentication in my main app. PHPhotoLibrary.requestAuthorization(for: .readWrite) { status in } Add the privacy description in both the main app and the extension. But No matter the device is locked or unlocked. When I call let fetchResult = PHAsset.fetchAssets(with: .image, options: nil) let count = fetchResult.count the count is always zero, even after a new photo is saved to the album in the same session.
1
0
111
3d
writeImageAtIndex:1012: ⭕️ ERROR: 'App' is trying to save an opaque image (5712x4284) with 'AlphaLast'.
I have an app that edits photos in your library. When I call try CIContext().writeHEIFRepresentation(of: editedImage, to: fileURL, format: .RGBA8, colorSpace: originalImage.colorSpace!) The following is logged to the console: writeImageAtIndex:1012: ⭕️ ERROR: 'App' is trying to save an opaque image (5712x4284) with 'AlphaLast'. This would unnecessarily increase the file size and will double (!!!) the required memory when decoding the image --> ignoring alpha. What does that mean and how can I resolve it? Xcode Version 16.0 (16A242d) iOS 18.1 (22B82)
0
2
184
6d
Inquiry Regarding File Size Differences When Migrating from ALAssetsLibrary to PHPhotoLibrary
We are currently in the process of migrating our application from using ALAssetsLibrary to PHPhotoLibrary to ensure compatibility with the latest versions of iOS. However, we have noticed a discrepancy in the file sizes of images obtained using PHPhotoLibrary compared to those obtained using ALAssetsLibrary. Specifically, we would like to understand the following points: 1.Reason for File Size Differences: What are the reasons for the difference in file sizes between images obtained using ALAssetsLibrary and those obtained using PHPhotoLibrary? Could you provide detailed information on the settings and options in PHPhotoLibrary that affect the size and quality of the images? 2.Optimal Settings: What are the optimal settings in PHPhotoLibrary to obtain images with the same quality and file size as those obtained using ALAssetsLibrary? If possible, could you provide code examples or recommended option settings?
3
0
152
3d
Potential bug with PHAsset Creation Request with photoProxy resource type.
I have noticed a problem when a PHAsset creation request is made with the resource type PHAssetResourceType.photoProxy. let creationRequest = PHAssetCreationRequest.forAsset() creationRequest.addResource(with: .photoProxy, data: photoData, options: nil) creationRequest.location = location creationRequest.isFavorite = true After successfully saving the resulting asset through PHPhotoLibrary.shared().performChanges, I could verify it in the Photos app. I noticed that the created photo was initially marked as Favorite and that the location was added to the info as expected. The title of the image changes from "Today" to "" too. Next, the photo was refreshed, and location data was purged. However, the title remains unchanged and displays the . This refresh was also observed in the code. PHPhotoLibraryChangeObserver protocols func photoLibraryDidChange(_ changeInstance: PHChange) receives a change notification. The same asset has been changed, and there is no location information anymore. isFavorite information persists correctly. After debugging for a few hours, I discovered that changing the resource type to .photo fixes this issue. Location data is not removed in the Photos app, and no refresh callback is seen in func photoLibraryDidChange(_ changeInstance: PHChange). I initially used .photoProxy because in the AVCapturePhotoCaptureDelegate implementation class, I always get the call in func photoOutput(_ output: AVCapturePhotoOutput, didFinishCapturingDeferredPhotoProxy deferredPhotoProxy: AVCaptureDeferredPhotoProxy?, error: Error?). So here is where I am capturing the photo data as photoData = deferredPhotoProxy?.fileDataRepresentation().
2
0
105
1w
Green Line Appears in Thumbnails in Photos but Not in Actual Photo
Hello, I’ve encountered an issue where a green line appears only in the thumbnail view of an image in the iPhone photo gallery. The green line is not present in the actual image itself. Here are some additional details: • The issue occurs only when saving the image as a JPEG. When saved as PNG, the green line does not appear. • The green line also shows up when using the PHAsset method requestImage(for:targetSize:). Depending on the targetSize, the resulting image may contain the green line. • Interestingly, this issue does not appear on iPhone Xs Max running iOS 15.2.1. However, the green line does appear on iPhone 15 Pro Max running iOS 18.0.1 when viewing the same image. I have attached the problematic image for your reference. Following images are the screen captures that shows the issue occurring on my iPhone. iPhone 15 pro max (iOS 18.0.1) iPhone Xs Max (iOS 15.2.1 ) Could this be related to a display or gallery app issue on iOS? Any advice or solutions would be greatly appreciated. Thank you!
1
0
181
3d
PHPickerResult slow loading, plus no thumbnails
A very common use case in our iOS app is that users take a large number of pictures (about 30) in low-light conditions using the camera app, and immediately after, they try to upload them to our servers. We measured the time to load photos from the PHPickerResult. For most photos, it takes less than 100 milliseconds, but for some of them, it takes several seconds—we even saw minutes in some extreme cases. We believe this started happening with iOS 17, when deferred photo processing was introduced. If users take the pictures using our in-app camera experience, the options to customize the camera are enough to avoid the long waiting times. However, the majority of our users still prefer to take the photos with the camera app, and there is little we can do about that. In the past few weeks, we tried many combinations: Without asking for permissions, we tried loadFileRepresentation, loadData, and loadObject. We explored the PHImageManager route, asking permissions and with different options for deliveryMode, resizeMode, version, isSynchronous, and allowSecondaryDegradedImage. We also tried fetching the photos in parallel, with very bad results. In summary, nothing helped the long waiting times—minutes in some cases. The first question is then, is there anything we can do to ignore the post-processing of the photos and get them fast? We could accept the unprocessed images. At a minimum, we would like to show our users what we are doing and why we are taking so much time. We tried to load thumbnails with loadPreviewImage and put a progress indicator on top. This method consistently gives us an error for all photos: (lldb) p error.localizedDescription (String) "Cannot load preview." We can load thumbnails with the PHImageManager option, but it seems excessive to need to get permissions only for that. Second question would be then, what can we do to load thumbnails without asking for permission? I created a feedback report with a video and sample code to reproduce -> FB15493683
2
0
159
2w
Add to Shared Photo Library with PhotoKit
I'm using PhotoKit in macOS to add photos to the user's library. Experimenting with Shared Photo Library, it seems that these new photos always end up in the Personal Library, not the Shared Library. I'd like to get them into the Shared Photo Library somehow. Is this possible? Things I've considered: A variation/option for PHAssetChangeRequest.creationRequestForAsset: doesn't seem to exist A property of PHAsset: can't find anything A special PHAssetCollection that I could add to: again, doesn't seem to exist
1
0
146
1w
Issues with ProRAW MAX(48) and stock camera app
Hello developer community. I purchase recently my new iPhone 16 Pro Max; it is a premium device with great quality overall. However, I am having a big trouble shotting in ProRaw MAX (48 mode) with native camera. Just to be clear, the problem that i will describe do not happen in 3rd apps, such as ProCam; only with native camera. When I use ProRaw Max, and take the photo, and watch the photo in the gallery the image can’t load and render properly. Even, when I maximize the image to the maximum I can see pixelated portions, defects and super low resolution and excessive denoise. For comparison, this not occur with my previous iPhone 15 PM and/or when I capture photos from ProCam (same settings and configurations) in the 16PM. I proceed to take the photo, open the gallery and I see full of details, when zoomed to 100%. I tried to format the phone, reinstall the software via my mac. Tried even to look at some forums to find if there’s someone with the same issue, the information available so far is very low. I’m in contact with apple assistant from my country (Portugal), and they escalated this problem to the engineers. (that’s what I’ve been told). They did all the tests remotely (via analysis and improvement’s) and they told me that my phone is perfect in the hardware department. I will wait for the next days to be contacted again. I’m on iOS 18.0.1. (The last software available at this time). I tried multiple 16PM, from friends, family and stores (more or less 10 units), and they all showed the exact same problematic. I’m a professional photographer, so I find this frustrating and unacceptable. I would appreciate any additional suggestion or information. Thank you! Cannot add photos or files because they are bigger than 5Mb.
1
0
258
2w
Wallpaper Api
Hey, I have an app that user selects wallpaper for iPhone. I want a feature that user can set wallpaper direct from app itself for lock screen and home screen not download the image and manually set the wallpaper. As my research there was a PhotoLibrary api that contains PLWallpaperImageViewController.h which allows you to set wallpaper directly. Thank You!
1
0
217
3w
Get View Full HDR state from Settings > Photos to properly set preferredImageDynamicRange in editing extension
I'm updating my Photo Editing Extension to support HDR. To do this I set imageView.preferredImageDynamicRange = .high. But you can turn off the option to view HDR photos in the complete dynamic range in Settings > Photos. When you do that, open a photo, and tap the edit button, it does not appear in the full range as expected, but when you select my app from More > Extensions, it does appear in the complete dynamic range unexpectedly. I need to set imageView.preferredImageDynamicRange = .standard when View Full HDR is off, but I don't see any way to get that in my PHContentEditingController.
1
0
272
3w
What format for writeHEIFRepresentation preserves HDR?
In the WWDC 24 session "Use HDR for dynamic image experiences in your app" it's noted this is how you save edits for Adaptive HDR: SDR + HDR: writeHEIFRepresentation(of: sdrImage, to: url, colorSpace: p3Space, options: [.hdrImage: hdrImage]) SDR + Gain: writeHEIFRepresentation(of: sdrImage, to: url, colorSpace: p3Space, options: [.hdrGainMapImage: gainImage]) This won't compile because the format argument is missing. What format should be used? In the WWDC 23 session "Support HDR images in your app" RGBAf, RGBAh, and RGBA16, and RGB10 were mentioned but I'm not sure which one to use. If relevant, I'm editing photos from the user's photo library, so the image was probably taken on iPhone but perhaps not. Thanks!
1
0
198
1w
'You don’t have permission. - The AVPlayerItem instance has failed with the error code 257 and domain "NSCocoaErrorDomain".'
[[PHImageManager defaultManager] requestAVAssetForVideo:asset options:videoOptions resultHandler:^(AVAsset *_Nullable avAsset, AVAudioMix *_Nullable audioMix, NSDictionary *_Nullable info) { if ([avAsset isKindOfClass:[AVURLAsset class]]) { AVURLAsset *urlAsset = (AVURLAsset *)avAsset; NSURL *videoURL = urlAsset.URL; mediaInfo[@"path"] = videoURL.absoluteString; } else { // Failed to get video asset completion(nil); } }];``` Before iOS 18, i could able access AVAsset video using the method mentioned above with the url, but starting from the iOS 18 version, the following error appears 'You don’t have permission. - The AVPlayerItem instance has failed with the error code 257 and domain "NSCocoaErrorDomain".'
2
0
302
3w
How to share PHAsset with UIActivityViewController like Photos App?
I am building an app about photos and I want to create a photo sharing feature like Apple's Photos App. Please see Steps to Reproduce and attached project. The current share method has the following issues The file name of the shared photo changes to “FullSizeRender”. The creation and update dates of shared photos will change to the date they were edited or shared. I want to ensure that the following conditions are definitely met Share the latest edited version. The creation date should be when the original photo was first created. How can I improve the code? STEPS TO REPRODUCE class PHAssetShareManager { static func shareAssets(_ assets: [PHAsset], from viewController: UIViewController, sourceView: UIView) { let manager = PHAssetResourceManager.default() var filesToShare: [URL] = [] let group = DispatchGroup() for asset in assets { group.enter() getAssetFile(asset, resourceManager: manager) { fileURL in if let fileURL = fileURL { filesToShare.append(fileURL) } group.leave() } } group.notify(queue: .main) { self.presentShareSheet(filesToShare, from: viewController, sourceView: sourceView) } } private static func getAssetFile(_ asset: PHAsset, resourceManager: PHAssetResourceManager, completion: @escaping (URL?) -> Void) { print("getAssetFile") let resources: [PHAssetResource] switch asset.mediaType { case .image: if asset.mediaSubtypes.contains(.photoLive) { // let editedResources = PHAssetResource.assetResources(for: asset).filter { $0.type == .fullSizePairedVideo } // let originalResources = PHAssetResource.assetResources(for: asset).filter { $0.type == .pairedVideo } let editedResources = PHAssetResource.assetResources(for: asset).filter { $0.type == .fullSizePhoto } let originalResources = PHAssetResource.assetResources(for: asset).filter { $0.type == .photo } resources = editedResources.isEmpty ? originalResources : editedResources } else { let editedResources = PHAssetResource.assetResources(for: asset).filter { $0.type == .fullSizePhoto } let originalResources = PHAssetResource.assetResources(for: asset).filter { $0.type == .photo } resources = editedResources.isEmpty ? originalResources : editedResources } case .video: let editedResources = PHAssetResource.assetResources(for: asset).filter { $0.type == .fullSizeVideo } let originalResources = PHAssetResource.assetResources(for: asset).filter { $0.type == .video } resources = editedResources.isEmpty ? originalResources : editedResources default: print("Unsupported media type") completion(nil) return } guard let resource = resources.first else { print("No resource found") completion(nil) return } let fileName = resource.originalFilename let tempDirectoryURL = FileManager.default.temporaryDirectory let localURL = tempDirectoryURL.appendingPathComponent(fileName) // Delete existing files and reset cache if FileManager.default.fileExists(atPath: localURL.path) { do { try FileManager.default.removeItem(at: localURL) } catch { print("Error removing existing file: \(error)") } } let options = PHAssetResourceRequestOptions() options.isNetworkAccessAllowed = true resourceManager.writeData(for: resource, toFile: localURL, options: options) { (error) in if let error = error { print("Error writing asset data: \(error)") completion(nil) } else { completion(localURL) } } } private static func presentShareSheet(_ items: [Any], from viewController: UIViewController, sourceView: UIView) { print("presentShareSheet") let activityViewController = UIActivityViewController(activityItems: items, applicationActivities: nil) if UIDevice.current.userInterfaceIdiom == .pad { activityViewController.popoverPresentationController?.sourceView = sourceView activityViewController.popoverPresentationController?.sourceRect = sourceView.bounds } viewController.present(activityViewController, animated: true, completion: nil) } }```
0
0
143
4w
IIOScanner and PHImageIODecoder crash
I have a user who keeps crashing on his iOS 18 device, I need some help~ Exception 1, Code 26, Subcode 8 > Attempted to dereference garbage pointer 0x1a. 0 ImageIO IIOScanner::getVal32() + 36 1 ImageIO PSDReadPlugin::initialize(IIODictionary*) + 620 2 ImageIO PSDReadPlugin::initialize(IIODictionary*) + 620 3 ImageIO IIOReadPlugin::callInitialize() + 400 4 ImageIO IIO_Reader::initImageAtOffset(CGImagePlugin*, unsigned long, unsigned long, unsigned long) + 164 5 ImageIO IIOImageSource::makeImagePlus(unsigned long, IIODictionary*) + 832 6 ImageIO IIOImageSource::getPropertiesAtIndexInternal(unsigned long, IIODictionary*) + 72 7 ImageIO IIOImageSource::createThumbnailAtIndex(unsigned long, IIODictionary*, int*) + 1352 8 ImageIO CGImageSourceCreateThumbnailAtIndex + 740 9 Photos _createDecodedImageUsingImageIOWithFileUrlOrData + 856 10 Photos __91-[PHImageIODecoder decodeImageFromData:orFileURL:options:existingRequestHandle:completion:]_block_invoke_2 + 176 11 libdispatch.dylib _dispatch_call_block_and_release + 32 12 libdispatch.dylib _dispatch_client_callout + 20 13 libdispatch.dylib _dispatch_continuation_pop + 596 14 libdispatch.dylib _dispatch_async_redirect_invoke + 580 15 libdispatch.dylib _dispatch_root_queue_drain + 392 16 libdispatch.dylib _dispatch_worker_thread2 + 156 17 libsystem_pthread.dylib _pthread_wqthread + 228
1
0
169
Sep ’24
PHAsset, PHImageManager requestAVAssetForVideo not downloading full size video from iCloud
Hello, I am using the below code to request for video to be downloaded from iCloud. But the downloaded video size does not match with the original size of video. PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init]; options.version = PHVideoRequestOptionsVersionOriginal; options.deliveryMode = PHVideoRequestOptionsDeliveryModeHighQualityFormat; [options setNetworkAccessAllowed:YES]; [[PHImageManager defaultManager] requestAVAssetForVideo:asset options:options resultHandler: ^(AVAsset *avAsset, AVAudioMix *audioMix, NSDictionary *info) { } Original size of video, getting it from below code NSArray *resources = [PHAssetResource assetResourcesForAsset:asset]; for (PHAssetResource *resource in resources) { if ((resource.type == PHAssetResourceTypeVideo) || (resource.type== PHAssetResourceTypePhoto)){ return resource; } } [resource valueForKey:@"fileSize"] The original Size and the downloaded size of video is not matching. Can anyone help me to debug what is the issue here
0
0
239
Sep ’24
Xcode16RC present PHPickerViewController layout error & cell non-Interactive.
After upgrading to Xcode16RC, in an old project based on ObjC, I directly used the following controller code in AppDelegate: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. UIButton *b = [[UIButton alloc]initWithFrame:CGRectMake(100, 100, 44, 44)]; [b setTitle:@"title" forState:UIControlStateNormal]; [self.view addSubview:b]; [b addTarget:self action:@selector(onB:) forControlEvents:UIControlEventTouchUpInside]; } - (IBAction)onB:(id)sender{ PHPickerConfiguration *config = [[PHPickerConfiguration alloc]initWithPhotoLibrary:PHPhotoLibrary.sharedPhotoLibrary]; config.preferredAssetRepresentationMode = PHPickerConfigurationAssetRepresentationModeCurrent; config.selectionLimit = 1; config.filter = nil; PHPickerViewController *picker = [[PHPickerViewController alloc]initWithConfiguration:config]; picker.modalPresentationStyle = UIModalPresentationFullScreen; picker.delegate = self; [self presentViewController:picker animated:true completion:nil]; } - (void)picker:(PHPickerViewController *)picker didFinishPicking:(NSArray<PHPickerResult *> *)results{ } Environment: Simulator iPhone 15 Pro (iOS18) Before this version (iOS17.4), clicking the button to pop up the system photo picker interface was normal (the top boundary was within the SafeAreaGuide area), but now the top boundary of the interface aligns directly to the top of the window, and clicking the photo cell is unresponsive. If I create a new Target, using the same codes, the photo picker page does not have the above problem. Therefore, I suspect it may be due to the old project’s .proj file’s info.plist, buildSetting, or buildPhase lacking some default configuration key value required by the new version, (My project was built years ago may be from iOS13 or earlier ) but I cannot confirm the final cause. iOS18.0 has the additional messages: objc[79039]: Class UIAccessibilityLoaderWebShared is implemented in both /Library/Developer/CoreSimulator/Volumes/iOS_22A3351/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.0.simruntime/Contents/Resources/RuntimeRoot/System/Library/AccessibilityBundles/WebCore.axbundle/WebCore (0x198028328) and /Library/Developer/CoreSimulator/Volumes/iOS_22A3351/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.0.simruntime/Contents/Resources/RuntimeRoot/System/Library/AccessibilityBundles/WebKit.axbundle/WebKit (0x1980fc398). One of the two will be used. Which one is undefined. AX Safe category class 'SLHighlightDisambiguationPillViewAccessibility' was not found! Has anyone encountered the same issue as me?
2
2
530
Sep ’24
Loading images from `PHPickerResult` with `loadFileRepresentation` taking very long time
We are seeing how most of the images loaded from the PHPickerViewController with: result.itemProvider.loadFileRepresentation(forTypeIdentifier: imageType.identifier) take a fraction of a second to load. However, since a few weeks ago, we are seeing more a more images that take minutes, 10 minutes in some cases. This images shouldn't be in iCloud, they are recently taken, the devices have enough free space and we are trying with good network conditions. Are others out there experiencing the same? Any tips to prevent these long times?
1
0
307
Sep ’24
Crashes in PHPickerViewController PFAssertionPolicyAbort
Hello! I'm getting crash reports in PHPickerViewController for iOS 17 users only. Can someone point me into the right direction what could be the root cause in my case since it's related to PHPickerViewController? Thread 0 name: Thread 0 Crashed: 0 libsystem_kernel.dylib 0x00000001e7e9342c __pthread_kill + 8 (:-1) 1 libsystem_pthread.dylib 0x00000001fbc32c0c pthread_kill + 268 (pthread.c:1721) 2 libsystem_c.dylib 0x00000001a6d36ba0 abort + 180 (abort.c:118) 3 PhotoFoundation 0x00000001d2420280 -[PFAssertionPolicyAbort notifyAssertion:] + 68 (PFAssert.m:432) 4 PhotoFoundation 0x00000001d2420068 -[PFAssertionPolicyComposite notifyAssertion:] + 160 (PFAssert.m:259) 5 PhotoFoundation 0x00000001d242061c -[PFAssertionPolicyUnique notifyAssertion:] + 176 (PFAssert.m:292) 6 PhotoFoundation 0x00000001d241f7f4 -[PFAssertionHandler handleFailureInFunction:file:lineNumber:description:arguments:] + 140 (PFAssert.m:169) 7 PhotoFoundation 0x00000001d2420c74 _PFAssertFailHandler + 148 (PFAssert.m:127) 8 PhotosUI 0x0000000216b59e30 -[PHPickerViewController _handleRemoteViewControllerConnection:extension:extensionRequestIdentifier:error:completionHandler:] + 1356 (PHPicker.m:1502) 9 PhotosUI 0x0000000216b5a954 __66-[PHPickerViewController _setupExtension:error:completionHandler:]_block_invoke_3 + 52 (PHPicker.m:1454) Crash report: 2024-09-05_18-27-56.7526_+0500-a953eaee085338a690ac1604a78de86e3e49d182.crash
2
0
281
2w