I have a simple iOS app running on an iPhone 12 Pro simulator with the task of reading a pdf file saved in my Desktop folder on my iCloud Drive. I can see the file on my macBook Pro and on my iPhone 12 Pro (real and simulator devices). But when I run the app on the simulator I cannot fetch the contents of the pdf file into the app.
Here is my Swift code in View Controller.swift;
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
guard let fileURL = FileManager.default.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent("Desktop").appendingPathComponent("samplePIL1436").appendingPathExtension("pdf") else { print("Got here 1."); return }
print(fileURL)
guard let pdfFileData = try? Data(contentsOf: fileURL) else { print("Got here 2.");return }
print(pdfFileData[0])
}
}
I have added iCloud capabilities in the Signing & Capabilities tab of Xcode. And I have done all the necessary steps in my Apple Developer account regarding app ID, provisioning profile, certificate, etc.
I have also added the necessary dictionaries to the info.plist
file.
I used UIDocumentPickerViewController to pick a pdf file and load it into my app.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.