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

99 Posts
Sort by:
Post marked as solved
1 Replies
616 Views
I'm trying to wrap PHLivePhotoView with UIViewRepresentable. When I put the view in ScrollView, its height gets close to zero. I have to explicit the view size with frame(width:height:) modifier to make it visible. ( When I put it in VStack, it will displayed correctly. ) import SwiftUI import PhotosUI struct LivePhotoView: UIViewRepresentable {     let livePhoto: PHLivePhoto     func makeUIView(context: Context) -> PHLivePhotoView {         return PHLivePhotoView(frame: .zero)     }     func updateUIView(_ livePhotoView: PHLivePhotoView, context: Context) {         livePhotoView.livePhoto = livePhoto     } } import SwiftUI import PhotoKit struct ContentView: View { @Binding var photos:[PHLivePhoto] = [] var body: some View { ScrollView { //👈🏼 ForEach(photos, id: \.self) { photo in PHLivePhotoView(livePhoto: photo) } } } } How can I make LivePhotoView work without size specification, like SwiftUI.Image ?
Posted
by
Post not yet marked as solved
2 Replies
507 Views
When using PHPickerViewController to load images from my photo library, several photos fail with: Error Domain=NSItemProviderErrorDomain Code=-1200 "Could not coerce an item to class UIImage" UserInfo={NSLocalizedDescription=Could not coerce an item to class UIImage} It appears to happen consistently on specific photos, even after restarting the device. I've set the PHPickerFilter to .images on the config, so I wouldn't expect casting to UIImage to be a problem. In what scenario would casting to UIImage fail when the .image filter is set? There's nothing obviously different about the photos that receive this error. In fact, other photos taken as part of the same series work just fine. Also, it's worth noting that these photos are part of a shared album.
Posted
by
Post marked as solved
1 Replies
327 Views
Currently, if we perform multiple selection on PHPickerViewController, a tick icon is being used to indicate selection. https://i.imgur.com/KCaSF9p.png However, such information doesn't convey information for the selection ordering. Is it every possible, to display the ordering number? This is an example from 3rd party library - https://github.com/mikaoj/BSImagePicker As you can see, the 3rd party library is using 1,2,3... to convey selection ordering information https://i.imgur.com/YoQVS4v.png Can we achieve the same behavior in PHPickerViewController? We prefer to use PHPickerViewController, because it doesn't need to request permission to access photo library. Thanks.
Posted
by
Post marked as solved
1 Replies
530 Views
For PHPickerViewController, we know we can perform simple filtering by var config = PHPickerConfiguration() config.filter = PHPickerFilter.images But, how about we only want to show images with format JPG & PNG, but excluding GIF? This is because our app doesn't support GIF. Is it possible to do so?
Posted
by
Post marked as solved
2 Replies
1.7k Views
Using Xcode 13 beta 4, I seem to have lost the ability to access user-created photo albums with PhotoKit (via PHAssetCollection.fetchAssetCollections). When I request albums of the type .smartAlbum, I get all the Smart Albums. However when I request .album, I get 0 results. Has anyone else run into this? Here's some example code: import SwiftUI import Photos struct ContentView: View { @State var status: PHAuthorizationStatus = PHPhotoLibrary .authorizationStatus(for: .readWrite) private static var collectionOptions: PHFetchOptions { let reverseChron = PHFetchOptions() reverseChron.sortDescriptors = [NSSortDescriptor(keyPath: \PHAssetCollection.endDate, ascending: false)] return reverseChron }     var body: some View { VStack { Text("Welcome!") .padding() if status == .authorized { Button("Load photos") { let userAlbums = PHAssetCollection.fetchAssetCollections( with: .album, subtype: .any, options: ContentView.collectionOptions ) print("List of albums:") for i in 0..<userAlbums.count { let album = userAlbums[i] print(album.localizedTitle ?? "[No title]") } } } }.onAppear() { PHPhotoLibrary.requestAuthorization(for: .readWrite) { aStatus in   status = aStatus   }   }     } } struct ContentView_Previews: PreviewProvider {     static var previews: some View {         ContentView()     } } Edit: filed as FB9477907
Posted
by
Post not yet marked as solved
1 Replies
735 Views
Follow up from the answer provided in https://developer.apple.com/forums/thread/653414?login=true The Apple engineer provided the below: When running on iOS 11 or above, your app don't need to ask for Photos Library permission before presenting UIImagePickerController (and assuming the app doesn't use PhotoKit/doesn't access UIImagePickerControllerPHAsset from the result). I have a question here about user privacy. Let's take a look at the customer perspective and their privacy with regards to photo sharing with an app using UIImagePickerController. If an app uses UIImagePickerController, then my understanding is the app will no longer show up in the Settings --> Privacy --> Photos menu (with options of [None] / [Selected Photos] / [All Photos]) as you don't need to ask for Photo Library permissions. Is that correct? Now, if that user goes to this app and chooses to select a photo, then their whole library will show. Is the takeaway that the app has access to all of the photos in the library? Or is the takeaway that this is only just a view of the images only and only the photo selected from the menu will be accessible to the app?
Posted
by
Post not yet marked as solved
0 Replies
305 Views
Currently, we are using PHPickerViewController + CGImage for efficient memory usage consideration - https://christianselig.com/2020/09/phpickerviewcontroller-efficiently/ However, we are getting "unsupported file format 'org.webmproject.webp'" error, while trying to save CGImage in webp format. func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) { picker.dismiss(animated: true) guard !results.isEmpty else { return } for result in results { result.itemProvider.loadFileRepresentation(forTypeIdentifier: UTType.image.identifier) { (url, error) in guard let url = url else { return } let options: [CFString: Any] = [ kCGImageSourceCreateThumbnailFromImageAlways: true, kCGImageSourceCreateThumbnailWithTransform: true, kCGImageSourceShouldCacheImmediately: true, kCGImageSourceThumbnailMaxPixelSize: 512 ] guard let imageSource = CGImageSourceCreateWithURL(url as NSURL, nil) else { return } let image = CGImageSourceCreateThumbnailAtIndex(imageSource, 0, options as CFDictionary) // // No issue in dealing with UTType.jpeg.identifier and UTType.png.identifier. // destUrl is type URL. // guard let destination = CGImageDestinationCreateWithURL(destUrl as CFURL, UTType.webP.identifier, 1, nil) else { return } CGImageDestinationAddImage(destination, image!, nil) CGImageDestinationFinalize(destination) } } We face no issue in saving CGImage in UTType.jpeg.identifier format and UTType.png.identifier format. May I know how can we save CGImage in webp format without issue? Thank you.
Posted
by
Post not yet marked as solved
0 Replies
269 Views
I know how to search for Smart Albums (favorites, selfies, etc...) containing photos: // Get smart albums PHFetchResult *smartAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:nil]; I have the following questions: Is there a way to enumerate the People Smart Albums and access the photos in a specific People Smart Album? Is there a way to enumerate the Places Smart Albums and access the photos in a specific Place Smart Album? Is there a way to enumerate Shared Albums (shared to the current iCloud user) and access the photos in a specific Shared Album?
Posted
by
Post not yet marked as solved
0 Replies
278 Views
Hello our wonderful Apple community, I'm so glad to be able to get some assistent regarding my inquiry. I just wanted to say that, since the last few months, I’ve bean very tired, exhausted and wasting a lot of hours of my days searching and figure out where to find the right applicable images for building my iOS app. I’ve checked many varies websites that can enable you to download free/ paid images, but I’m having a very hard time to compare the images to my app idea: size, vertical form, the activity in the image. I do review all the apps that has the similar idea in the App Store and I always wonder, how the developers find and pick these images to create their apps! I wish to get your support relating to this topic and the rest is easy. Thank you guys Kindly,
Posted
by
Post marked as solved
1 Replies
341 Views
From the imagecapturecore-rs crate here: https://github.com/brandonhamilton/image-capture-core-rs/issues/7 Only didOpenSessionWithError fires when connecting a PTP (picture transfer protocol) device with a None for the error value and an NSArray with a count of 0. decl.add_method( sel!(device:didOpenSessionWithError:), device_did_open_session_with_error as extern "C" fn(&Object, Sel, id, id), ); println!(" 📸 add_method didCloseSessionWithError"); decl.add_method( sel!(device:didCloseSessionWithError:), device_did_close_session_with_error as extern "C" fn(&Object, Sel, id, id), ); println!(" 📸 add_method didRemoveDevice"); decl.add_method( sel!(didRemoveDevice:), device_did_remove_device as extern "C" fn(&Object, Sel, id), ); println!(" 📸 add_method withCompleteContentCatalog"); decl.add_method( sel!(withCompleteContentCatalog:), device_did_become_ready as extern "C" fn(&Object, Sel, id), ); Do I need to be using the fancier cameraDevice.requestOpenSession() with the callback function from here? https://developer.apple.com/documentation/imagecapturecore/icdevice/3142916-requestopensession As seen on StackOverflow: https://stackoverflow.com/questions/68978185/apple-ptp-withcompletecontentcatalog-not-firing-rust-obj-c
Posted
by
Post not yet marked as solved
0 Replies
371 Views
I customize the captured portrait mode photo's depthData by using fileDataRepresentationWithCustomizer method, and replace the depth data with my edited version. - (nullable AVDepthData *)replacementDepthDataForPhoto:(AVCapturePhoto *)photo{ return myEditedDepthData; } The weird thing is that the returned NSData value of fileDataRepresentationWithCustomizer losts portraitMatte. CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)nsData, NULL); CFDictionaryRef dicRef = CGImageSourceCopyAuxiliaryDataInfoAtIndex(imageSource, 0, kCGImageAuxiliaryDataTypePortraitEffectsMatte); the dicRef always return 0x0 after I use fileDataRepresentationWithCustomizer instead of fileDataRepresentation Does anyone know what am I doing wrong?
Posted
by
Post not yet marked as solved
1 Replies
530 Views
After backup my iPad (iOS 15 beta.8) through Finder (or iTunes on Windows), I could browse the backup folder using tools like 'iMazing'. And I found there are remaining asset files in this folder 「AppDomainGroup-group.com.apple.mobileslideshow.PhotosFileProvider\File Provider Storage\photospicker」which are picked by PHPickerViewController. I wondered why they were not cleaned by system and how long they will be kept? Thanks for your reading and looking forward the answers!
Posted
by
Post not yet marked as solved
4 Replies
565 Views
Dear: When I use iOS15 save video camera equipment to album, show PHPhotosErrorInvalidResource. Videos stored in the sandbox can play normally, lower than ios15 can be saved. And only one camera video fails to save, others succeeds. Confused and hoping for help. Here is the code [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{         PHAssetChangeRequest *photoRequest = [PHAssetChangeRequest creationRequestForAssetFromVideoAtFileURL:url];         PHAssetCollectionChangeRequest *albumChangeRequest = [PHAssetCollectionChangeRequest changeRequestForAssetCollection:collection];         PHObjectPlaceholder *assetPlaceholder = [photoRequest placeholderForCreatedAsset];         [albumChangeRequest addAssets:@[ assetPlaceholder ]];     } completionHandler:^(BOOL success, NSError * _Nullable error) {         [self performInMainThreadBlock:^{             if (success) {                 successBlock();             }else{                 failureBlock(error);             }         }];     }]
Posted
by
Post not yet marked as solved
1 Replies
477 Views
When using PHPicker and selecting multiple images, is there a way to have those images already preselected when you re-open the image picker? Say a user is able to add 5 images to a post. They open the PHPicker and add 3. Later they decide they want to add an additional 2 so they open the PHPicker again. But when the PHpicker is opened again, no images are selected so they are able to select the same images they've already chosen beforehand. Is it possible for the phpicker save it's previous state or is there a way to pass in what images should be selected upon opening the picker?
Posted
by
Post marked as Apple Recommended
744 Views
After a user complained that they could no longer load partially transparent PNG images in my photo compositing app, I eventually tracked this down to a bug in iOS 15.1 (tested on beta 2). When the user selects a PNG image in the PHPickerViewController, the returned NSItemProvider reports having a file for the "public.png" UTI (and only that one). However when requesting data for that UTI, the system actually returns JPEG image data instead. Just a heads up to other developers who might run into this. Hopefully it will get fixed before 15.1 ships. I reported it as FB9665280.
Posted
by
Post not yet marked as solved
1 Replies
453 Views
My recording was stopped due to low battery and phone shutdown. When I reopen my app, the recorded ".mov video"(around 8GB) file is not moving/copying to PHPhotoLibrary and it shows internalError which is hard to understand the exact reason for denying to add the video file to PHPhotoLibrary. Error Domain=PHPhotosErrorDomain Code=-1 \"(null)\") So How to resolve such kind of internalError while adding assets to PHPhotoLibrary? Thanks & Regards, Natarajan S
Posted
by
Post not yet marked as solved
1 Replies
224 Views
I am facing issue with capture images from my phone when I am preview it, its transition is not smooth some jumpiness is there while display it. that issue I have seen in iOS14, 15 version.
Posted
by
Post not yet marked as solved
0 Replies
261 Views
iOS 15 has new function to manually adjust capture location, time and date. The question is I used requestImageDataAndOrientation(for:options:resultHandler:) to request image,  but the EXIF data is still unadjusted. Is there anyway to request image with the adjusted EXIF data ?
Posted
by
Post not yet marked as solved
1 Replies
380 Views
The newish PHPicker is a great way to access the users’ photo library without requiring fill access permissions. However, this is currently no way for accessing the original or unadjusted version of an asset. The preferredAssetRepresentationMode of the PHPickerConfiguration only allows the options automatic, compatible, and current, where current still returns the asset with previous adjustments applied. The option only seems to impact potential asset transcoding. In contrast, when fetching PHAsset data, one can specify the PHImageRequestOptionsVersion unadjusted or original, which give access to the underlying untouched image. It would be great to have these options in the PHPicker interface as well. The alternative would be to load the image through PHAsset via the identifier returned by the picker, but that would require full library access, which I want to avoid. Or is there another way to access the original image without these permissions?
Posted
by