使用UIIMagePickerController
从PHAsset
中选择照片以显示带有日期,时间和位置的图像。问题在于它只能在一个特定的模拟器(iPhone XR)上运行。当我在其他模拟器(例如iPhone XS)上运行它时,图像显示正常,但位置和日期/时间信息却不显示。不知道问题出在我的代码中还是我没有正确使用Simulator。
该图显示了在2个模拟器上运行的相同构建
这是我的代码
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
}
最佳答案
问题解决了!问题是info.plist
的路径需要修复。我遵循了这个非常有用的演练:https://stackoverflow.com/a/52671583/4577719。
关于swift - Xcode 10.3模拟器问题?照片的PHAsset位置和日期信息仅在一个模拟器中起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59260969/