0

Using UIIMagePickerController to select a photo to display image with date, time and location from PHAsset. The problem is that it only works on one specific Simulator (iPhone XR). When I run it on a different simulator (eg. iPhone XS) the image displays fine, but not the location and date/time info. Not sure if the problem is in my code or if I'm not using Simulator incorrectly.

Image shows the same build running on 2 Simulators

Image shows the same build running on 2 Simulators

And here's my code

guard let selectedImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage else { return }
if let asset = info[UIImagePickerController.InfoKey.phAsset] as? PHAsset,
    let location = asset.location {
    CLGeocoder().reverseGeocodeLocation(location) { placemarks, error in
        guard let placemark = placemarks?.first else { return }
        self.name.text = placemark.name
        self.locality.text = placemark.locality
        self.stateUS.text = placemark.administrativeArea
        self.country.text = placemark.country
    }
    if let creationDate = asset.creationDate {
        let formatter = DateFormatter()
        formatter.dateStyle = .medium
        formatter.timeStyle = .none
        let readableDateTime = formatter.string(from: creationDate)
        self.dateTime.text = readableDateTime
    }
    if let creationDate = asset.creationDate {
        let formatter = DateFormatter()
        formatter.dateStyle = .none
        formatter.timeStyle = .short
        let readableTimeOnly = formatter.string(from: creationDate)
        self.timeOnly.text = readableTimeOnly
    }
    photoData = asset  // To pass PHAsset data to next VC
}

Andrew
  • 26,706
  • 9
  • 85
  • 101
yantronica
  • 353
  • 1
  • 3
  • 12

1 Answers1

0

Problem solved! The issue was the path to info.plist needed to be fixed. I followed this very helpful walkthrough: https://stackoverflow.com/a/52671583/4577719.

yantronica
  • 353
  • 1
  • 3
  • 12