Xcode 10.3模拟器问题?照片仅在一个模拟器中起作用的PHAsset位置和日期信息

问题描述 投票:0回答:1

使用UIIMagePickerControllerPHAsset中选择照片以显示带有日期,时间和位置的图像。问题在于它只能在一个特定的模拟器(iPhone XR)上运行。当我在其他模拟器(例如iPhone XS)上运行它时,图像显示正常,但位置和日期/时间信息却不显示。不知道问题出在我的代码中还是我没有正确使用Simulator。

图像显示了在两个模拟器上运行的相同版本

Image shows the same build running on 2 Simulators

这是我的代码

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
}

swift xcode ios-simulator phasset clgeocoder
1个回答
0
投票

问题解决了!问题是info.plist的路径需要修复。我遵循了这个非常有用的演练:https://stackoverflow.com/a/52671583/4577719

© www.soinside.com 2019 - 2024. All rights reserved.