Photos and Imaging

RSS for tag

Integrate still images and other forms of photography into your apps.

Posts under Photos and Imaging tag

84 Posts
Sort by:
Post not yet marked as solved
6 Replies
1.2k Views
We implemented the new PHPicker and have run into an issue we haven't been able to replicate on our own devices but see a lot of users running into it. The problem is an error after getting the PHPickerResults and trying to get the UIImages. Because the user can select several images at once, what we do is get the results and iterate over each itemProvider object. I'm following apple's guidance and checking if itemProvider canLoadObjectOfClass:UIImage.class, before executing itemProvider loadObjectOfClass:UIImage.class. However we are getting hundreds of reports of users where this last method returns an error. Firstly, this is how we configure our PHPickerViewController: PHPickerConfiguration *configuration = [[PHPickerConfiguration alloc] init]; configuration.selectionLimit = self.pictureSelectionLimit; configuration.filter = PHPickerFilter.imagesFilter; configuration.preferredAssetRepresentationMode = PHPickerConfigurationAssetRepresentationModeCurrent; PHPickerViewController *pickerViewController = [[PHPickerViewController alloc] initWithConfiguration:configuration]; pickerViewController.delegate = self; pickerViewController.modalPresentationStyle = UIModalPresentationFullScreen; [viewController presentViewController:pickerViewController               animated:YES              completion:nil]; And this is what we do with the PHPickerResult. This is a method that returns a block with an array of an object NewPicture instantiated with the UIImage I should be getting. NSMutableArray *picArray = [[NSMutableArray alloc] init]; NSArray *itemProviders = [self.results custom_map: ^id _Nullable (PHPickerResult *_Nonnull current) {   return current.itemProvider; }]; dispatch_group_t dispatchGroup = dispatch_group_create(); for (NSItemProvider *itemProvider in itemProviders) { dispatch_group_enter(dispatchGroup); /**  We cannot properly retrieve raw type images with the current authorization status.  If the image is of type raw, we ignore it. */ if ([itemProvider hasItemConformingToTypeIdentifier:@"public.camera-raw-image"]) { NSException *exception = [NSException exceptionWithName:@"ImageIsTypeRaw"                         reason:[NSString stringWithFormat:@"Object is type raw. ItemProvider: %@", itemProvider.description]                        userInfo:nil]; // Log exception... dispatch_group_leave(dispatchGroup); continue; } if ([itemProvider canLoadObjectOfClass:UIImage.class]) { [itemProvider loadObjectOfClass:UIImage.class completionHandler: ^(__kindof id NSItemProviderReading _Nullable object, NSError *_Nullable error) {   if ([object isKindOfClass:UIImage.class]) { NewPicture *picture = [[NewPicture alloc]initWithImage:object]; [picArray addObject:picture]; }   if (error) { NSException *exception = [NSException exceptionWithName:@"CouldNotLoadImage"                         reason:[NSString stringWithFormat:@"Object is nil. UserInfo: %@", error.userInfo]                        userInfo:error.userInfo]; // Log exception... }   dispatch_group_leave(dispatchGroup); }]; } } dispatch_group_notify(dispatchGroup, dispatch_get_main_queue(), ^{ picturesBlock(picArray); }); The most common error we see our users are getting is: Object is nil. UserInfo: { NSLocalizedDescription = "Cannot load representation of type public.jpeg"; NSUnderlyingError = "Error Domain=NSCocoaErrorDomain Code=260 \"The file \U201cversion=1&uuid=*&mode=current.jpeg\U201d couldn\U2019t be opened because there is no such file.\" UserInfo={NSURL=file:///private/var/mobile/Containers/Shared/AppGroup/*/File%20Provider%20Storage/photospicker/version=1&uuid=*&mode=current.jpeg, NSFilePath=/private/var/mobile/Containers/Shared/AppGroup/*/File Provider Storage/photospicker/version=1&uuid=***&mode=current.jpeg, NSUnderlyingError=0x283822970 {Error Domain=NSPOSIXErrorDomain Code=2 \"No such file or directory\"}}"; } I'm having a really hard time understanding why this sometimes fails. I'd really appreciate it if someone could give me a hand with this. I'm attaching the stack trace: stack_trace - https://developer.apple.com/forums/content/attachment/051f7018-05ff-4ad1-a626-29f248d0b497
Posted Last updated
.
Post not yet marked as solved
0 Replies
111 Views
So I sent someone a live photo (that would soon to be a wallpaper) that looks crisp on my phone but when sent to her phone she gets a blurry live wallpaper instead. My phone is the iphone 12 while hers is the iphone 13 pro max
Posted
by Fyrezz.
Last updated
.
Post not yet marked as solved
0 Replies
107 Views
PHPhotoLibarary.requestAuthorization(for accessLevel: PHAccessLevel, handler: @escaping (PHAuthorizationStatus) -> Void) does not invoke the completion handler. If the user selects limited photos, the handler is not called. Furthermore the limited library picker is presented for about a second then it disappears. I already have the following in the info plist <string>Photo Library access is needed to import saved photos</string> <true/>        let stat = PHPhotoLibrary.authorizationStatus(for: .readWrite)       print("Photolibrary settign: current status: \(stat)")               PHPhotoLibrary.requestAuthorization(for: .readWrite) { status in         switch status {         case .restricted:           print("Photolibrary settign: restricted")         case .denied:           print("Photolibrary settign: denied")         case .limited:           print("Photolibrary settign: limited")         case .authorized:           print("Photolibrary settign: authorized")         case .notDetermined:           print("Photolibrary settign: not determined")         default:           break         }       }
Posted Last updated
.
Post marked as solved
1 Replies
187 Views
Hello, how can I add a detail view to this code? I want to show the image in a detail view and that for every image single. import SwiftUI struct ContentView: View {     var images: [String] = ["noaa1", "noaa2", "noaa3", "noaa4", "noaa5", "noaa6", "noaa7", "noaa8", "noaa9", "noaa10", "noaa11", "noaa12", "noaa13", "noaa14", "noaa15", "noaa16", "noaa17", "noaa18"]          var columnGrid: [GridItem] = [GridItem(.flexible()), GridItem(.flexible())]          var body: some View {             ScrollView {                 LazyVGrid(columns: columnGrid) {                     ForEach(images, id: \.self) { image in                         Image(image)                             .resizable()                             .scaledToFit()                             .cornerRadius(10)                                      }             }         }     }          struct ContentView_Previews: PreviewProvider {         static var previews: some View {             ContentView()         }     } }
Posted
by iRIG.
Last updated
.
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 CloverSly.
Last updated
.
Post not yet marked as solved
0 Replies
150 Views
We are a picture design company. When we use the Photos library to store pictures to albums, we encountered a large number of user album storage failure cases. The most error code is 41002, but I don't know how to fix it, or avoid it. Error Example: Error Domain=com.apple.photos.error Code=41002 "Unable to obtain assetsd XPC proxy for getPhotoKitAddServiceWithReply:. assetsd could have crashed" UserInfo={NSLocalizedDescription=Unable to obtain assetsd XPC proxy for getPhotoKitAddServiceWithReply:. assetsd could have crashed, NSUnderlyingError =0x2818a8b70 {Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.photos.service" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.photos.service}}}
Posted Last updated
.
Post not yet marked as solved
1 Replies
192 Views
tl;dr; Is there a way to ensure that only "Never" and "Read and Write" appear under Settings -&gt; App Name -&gt; Photos on devices running iOS 14 or higher? The Issue: The enhanced image library access permissions incorporated as part of iOS 14 are creating problems with a custom image selection flow created for an app and I'm just curious if there is a way to eliminate the "Selected Photos" option from the app settings until the app can be fully updated to offer users the enhanced security. I've removed the "Select Photos..." option from the iOS permission alert viewcontroller for the Images Library by setting the value for the PHPhotoLibraryPreventAutomaticLimitedAccessAlert key to 'true' as recommended in the Apple documentation: https://developer.apple.com/documentation/photokit/phauthorizationstatus/limited However, if the device is running iOS 14 or higher, the option for "Selected Photos" is still available when I go to the App's settings in the device's Settings menu. If a user interacts with permissions at this level the app does not function properly. I was wondering if anyone has experienced this as well and possibly come up with an interim solution.
Posted
by bcwoodard.
Last updated
.
Post not yet marked as solved
0 Replies
201 Views
Am using a Supervised Device with 15.4 OS Scenario: I have tried to push the Restriction payload to Device , with value true for "allowOpenFromUnmanagedToManaged" key . case 1: When i try to open a photo from Photo Library and try to open in with any Managed App ,the suggestions for managed app is not listed there. (Working as Expected) My Problem is: case 2: But when i open the Managed App and Try to add a photo , It allows me to open the Photo Library ,from where i can add it. If Sharing data from unmanaged to managed app is restricted, then it shouldn't be added in case2 ,Right? FYI: The managed App i have used in Outlook App Can Anyone Help me this strange Behaviour? Thanks In Advance
Posted Last updated
.
Post marked as solved
2 Replies
208 Views
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "PhoneDetailsCC", for: indexPath) as? PhoneDetailsCC     let imageUrl = phoneModel?.imageUrl[indexPath.row]     cell?.phoneDetailsImage.sd_setImage(with: URL(string: imageUrl!))     return cell!   } i am casting here cell image phoneDetailsImage and i use here sd_setimage to download inside array to come it other tableview each row also every cell to use model let imageUrl = phoneModel?.imageUrl[indexPath.row] this is and string array [string] and sdwebimage show inside url to convert image but i have another problem to it i am create an pdf in this every cell to use pdfkit beforo i used just 1 image and i prepared and send it other vc but i dont know how i send array of image to other vc i will share other code below import FirebaseStorage import FirebaseFirestore import SDWebImage import ProgressHUD import PDFKit class PhoneListViewController: UITableViewController {   @IBOutlet weak var phoneModelText: UITextView!   @IBOutlet weak var imeiAdressText: UITextView!   @IBOutlet weak var userNameText: UITextView!   @IBOutlet weak var idText: UITextView!   @IBOutlet weak var phoneNumberText: UITextView!   @IBOutlet weak var detailsText: UITextView!   @IBOutlet weak var dateText: UITextView!   @IBOutlet weak var priceText: UITextView!   @IBOutlet weak var adressText: UITextView!   @IBOutlet weak var imageView: UIImageView!   @IBOutlet weak var imageCollectionView: UICollectionView!       public var documentData: Data?   var phoneModel : PhoneModel?           override func viewDidLoad() {     super.viewDidLoad()     imageCollectionView.delegate = self     imageCollectionView.dataSource = self     view.backgroundColor? = UIColor.systemGray3     tableView.backgroundView = UIImageView(image: UIImage(named: "SplashScreen.jpeg"))     tableView.backgroundView?.alpha = 0.2     phoneModelText.text = phoneModel?.phoneModelText     imeiAdressText.text = phoneModel?.imeiAdressText     userNameText.text = phoneModel?.userNameText     idText.text = phoneModel?.idText     phoneNumberText.text = phoneModel?.phoneNumberText     detailsText.text = phoneModel?.detailsText     dateText.text = phoneModel?.dateText     priceText.text = phoneModel?.priceText     adressText.text = phoneModel?.adressText     imageCollectionView.register(UINib(nibName:"PhoneDetailsCC", bundle: Bundle.main), forCellWithReuseIdentifier: "PhoneDetailsCC")         }       @IBAction func printAction(_ sender: Any) {     let pdfPreview = PDFView()     if let data = documentData {       pdfPreview.document = PDFDocument(data: data)       pdfPreview.autoScales = true     }     view.addSubview(pdfPreview)   }   override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -&gt; Bool {     if       let _ = phoneModelText.text,       let _ = userNameText.text,       let _ = imageView.image, // this is i used before only 1 image and this is worked for me       let _ = adressText.text {       return true     }           let alert = UIAlertController(title: "Please Wait, Try again", message: "You Need to be wait downloading all image", preferredStyle: .alert)     alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))     present(alert, animated: true, completion: nil)           return false   }       override func prepare(for segue: UIStoryboardSegue, sender: Any?) {     if segue.identifier == K.pdfSegue {       guard let vc = segue.destination as? PDFViewController else { return }               if let phoneM = phoneModelText.text,         let imeiA = imeiAdressText.text,         let nameS = userNameText.text,         let idN = idText.text,         let phoneN = phoneNumberText.text,         let adressT = adressText.text,         let detailS = detailsText.text,         let priceC = priceText.text,         let dateT = dateText.text,         let imageV = imageView.image               {         let pdfCreate = PDFCreate(phoneModel: phoneM, imeiAdress: imeiA, nameSurname: nameS, id: idN, phoneNumber: phoneN, adress: adressT, details: detailS, price: priceC, date: dateT, image: imageV)         vc.documentData = pdfCreate.createPdf()       } //this model use to create of the inside of pdf other text is passing well     }   } } extension PhoneListViewController: UICollectionViewDelegate,UICollectionViewDataSource {       func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {     return phoneModel?.imageUrl.count ?? 0   }       func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {     collectionView.deselectItem(at: indexPath, animated: true)              }       func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {     collectionView.deselectItem(at: indexPath, animated: true)             }       func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {     let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "PhoneDetailsCC", for: indexPath) as? PhoneDetailsCC     let imageUrl = phoneModel?.imageUrl[indexPath.row]     cell?.phoneDetailsImage.sd_setImage(with: URL(string: imageUrl!))     return cell!   }         } how i send it array of images to use sdwebimage inside of collection view data to other vc Thank you for answers...
Posted Last updated
.
Post not yet marked as solved
0 Replies
264 Views
Hi. I'd like to be able to do a flood fill on images, either UIImage or CGImage, and was wondering if there was a built in way to do this provided by Apple's standard frameworks? i.e. Take a bitmap image and specify a point and color and then make it fill the area with that color, no matter what shape it is. I've seen a few examples of algorithm code to do this, but they're quite large and complicated so am trying to avoid them.
Posted
by moontiger.
Last updated
.
Post not yet marked as solved
4 Replies
1.1k Views
I use the following code to parse Photo metadata and this works well. However, I am unable to pull the new iOS 14 "caption" from this metadata (it worked in early iOS 14 betas, but has since stopped working in the GM.) Does anyone know how I can get the caption data from a PHAsset? Thanks! Stephen         let options = PHContentEditingInputRequestOptions()         options.isNetworkAccessAllowed = true         asset.requestContentEditingInput(with: options, completionHandler: {(contentEditingInput, _) -> Void in             if let url = contentEditingInput?.fullSizeImageURL {                 let fullImage = CIImage(contentsOf: url)                                  // get all the metadata                 self.allPhotoMetadata = fullImage?.properties ?? [:]                                  // {TIFF}                 if let tiffDict = self.allPhotoMetadata["{TIFF}"] as? [String:Any] {                     if tiffDict["Make"] != nil {                         self.cameraData[cameraKeys.make] = tiffDict["Make"]                     }                     if tiffDict["Model"] != nil {                         self.cameraData[cameraKeys.model] = tiffDict["Model"]                     }                     if tiffDict["ImageDescription"] != nil {                         self.imageData[imageKeys.caption] = tiffDict["ImageDescription"]                     }                 }                                  // {IPTC}                 if let iptcDict = self.allPhotoMetadata["{IPTC}"] as? [String:Any] {                     // if we didn't find a caption in the TIFF dict, try to get it from IPTC data                     // first try, Caption/Abtract, then ArtworkContentDescription                     if self.imageData[imageKeys.caption] == nil {                         if iptcDict["Caption/Abstract"] != nil {                             self.imageData[imageKeys.caption] = iptcDict["ArtworkContentDescription"]                         } else if iptcDict["ArtworkContentDescription"] != nil {                             self.imageData[imageKeys.caption] = iptcDict["ArtworkContentDescription"]                         }                     }                 }             }         })     }
Posted
by sorth.
Last updated
.
Post not yet marked as solved
0 Replies
256 Views
Hi, If I generate an image from a symbol the resulting image is surrounded by some margins. For example this code: let image = UIImage(systemName: "suit.heart") will generate this image: As you can see there are some margins around the content. There is a way to build an image cropped to the actual content, like showed in the below example? Thank you
Posted
by DaleOne.
Last updated
.
Post not yet marked as solved
0 Replies
305 Views
I have been unable to capture Live Photos using UIImagePickerController. I can capture still photos and even video (which is not my scenario but I checked just to make sure), but the camera does not capture live photos. The documentation suggests it should (source): To obtain the motion and sound content of a live photo for display (using the PHLivePhotoView class), include the kUTTypeImage and kUTTypeLivePhoto identifiers in the allowed media types when configuring an image picker controller. When the user picks or captures a Live Photo, the editingInfo dictionary contains the livePhoto key, with a PHLivePhoto representation of the photo as the corresponding value. I've set up my controller: let camera = UIImagePickerController() camera.sourceType = .camera camera.mediaTypes = [UTType.image.identifier, UTType.livePhoto.identifier] camera.delegate = context.coordinator In the delegate I check for the Live Photo: func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { if let live = info[.livePhoto] as? PHLivePhoto { // handle live photo } else if let takenImage = info[.originalImage] as? UIImage, let metadata = info[.mediaMetadata] as? [AnyHashable:Any] { // handle still photo } } But I never get the Live Photo. I've tried adding NSMicrophoneUsageDescription to the info.plist thinking it needs permissions for the microphone, but that did not help. Of course, I've added the NSCameraUsageDescription to give camera permissions. Has anyone successfully captured Live Photos using UIImagePickerController?
Posted Last updated
.
Post marked as solved
1 Replies
247 Views
Is it possible for apps to pull all photos from your gallery and upload them to their server if you grant the app full access to your gallery? I find it bizarre that this would be possible, even if Apple request permission to access their photos. I looked through ImagePickerController and it seem that users must select a photo/video to receive access through its delegate. However, on most forums like Quorum users say apps can upload your entire library if you give them full access. If this is true can someone outline how it's possible?
Posted
by eak65.
Last updated
.
Post not yet marked as solved
0 Replies
251 Views
Does Photospicker change the hash value of the photo after giving permission to third-party apps?
Posted Last updated
.
Post marked as solved
2 Replies
368 Views
For example, when Apple Engineers design something new like PHPickerViewController, I imagine that they test all the functionalities and to test all these functions, they create applications. Where can I download the code of those applications? I mean, code that is already tested and works from Apple Engineers. I'm sure they have tons of tested code, which would be very useful for us. Thanks!
Posted
by RayOV.
Last updated
.
Post not yet marked as solved
3 Replies
1.4k Views
Hi, I have a little issue with this new API PHPPickerViewController:  var configuration = PHPickerConfiguration()  configuration.filter = .any(of: [.images])  configuration.selectionLimit = 10  configuration.preferredAssetRepresentationMode = .compatible let picker = PHPickerViewController(configuration: configuration)  picker.delegate = self  present(picker, animated: true, completion: nil) func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {   var selectedPhotosData : [Data] = []   for (index,result) in results.enumerated() { &#9;&#9;&#9;&#9; result.itemProvider.loadFileRepresentation(forTypeIdentifier: "public.jpeg") { (url, error) in     guard let fileUrl = url else {return } print(fileUrl)      } } This code above doesn't work, I don't get the URL at all. I tried on Simulator and real device but the same problem. I tried loadObject function but I can't the UIImages... I saw some workarounds here but they don't work in my case it seems...
Posted
by maxh97.
Last updated
.
Post not yet marked as solved
0 Replies
431 Views
G'day, I'm working on a share extension for our iOS app where the users are able to select multiple photos or videos and choose to share it conversations inside the app. Similar to other chat apps are doing. I ran into a problem where the file URL extracted through the inputItem's attachment are non existent for some of the files. For example share extension gives file URL such as this, file:///var/folders/4r/qlw_jjvj3w7gh5mssgzhx15w0000gp/T/com.apple.Photos/ShareKit-Exports/2918015E-B07C-4F35-9D98-86B58464DE88/B699E8DE-4965-4C0F-9D9B-4956E5E02730/IMG_1234.jpg But there is no such file in that location. Instead there is a file named IMG_1234.png (or different file extension), for certain items in user's photo library. How does this happen? Am I supposed to query the files inside the parent directory and locate truely existing file from it by ignoring the returned file name or some other way. When the same file is shared from other apps such as airdrop, mail, notes, they seem to have no problem opening up this file and the saved file (e.g. from airdrop) has identical file name and properties (IMG_1234.png) at final destination. Below is code snippet on how I process the extension context in my share extension. // I'm getting first input item here, I've checked and there are no more than 1 input item for the affected assets that are causing problem guard let itemProviders = (extensionContext?.inputItems.first as? NSExtensionItem)?.attachments else { return } var items: [Attachment] = [] // Attachment is a custom type that contains file url or image data itemProviders.forEach { itemProvider in if itemProvider.hasItemConformingToTypeIdentifier(kUTTypeImage as String) { let desiredTypeIdentifier: String = kUTTypeImage as String itemProvider.loadItem(forTypeIdentifier: desiredTypeIdentifier, options: nil) { data, _ in if let url = data as? URL { items.append(.init(data: .file(url))) // the URL returned above is incorrect for the affected items. It's reproducible every time. } else if let image = data as? UIImage { items.append(.init(data: .memory(image))) } } } } Regards,
Posted Last updated
.