I'm trying to update an old iOS app to use the UIScene architecture, and I've run into a problem I'm hoping somebody can help me fix.
When I try to share a file with my app by AirDrop from another device, the URL that I'm getting from the urlContexts
argument does not exist on the device.
Here's the code I'm using in my SceneDelegate class to get things going:
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
guard let url = URLContexts.first?.url else {
os_log("URL in %@ is nil", #function)
return
}
// check that it's the proper file type
guard url.pathExtension == fileExtension.replacingOccurrences(of: ".", with: "") else {
return
}
...
}
When I set a breakpoint after populating the url
property, checking its existence in the Xcode Console reveals the enclosing folder does not exist:
(lldb) po url.path
/private/var/mobile/Library/Mobile Documents/com~apple~CloudDocs/Downloads/Seattle Times 2025-04-30 10.dbsud
(lldb) po FileManager.default.fileExists(atPath: URL(filePath: "/private/var/mobile/Library/Mobile Documents").path)
true
(lldb) po FileManager.default.fileExists(atPath: URL(filePath: "/private/var/mobile/Library/Mobile Documents/com-apple-CloudDocs/Downloads").path)
false
(lldb) po FileManager.default.fileExists(atPath: URL(filePath: "/private/var/mobile/Library/Mobile Documents/com-apple-CloudDocs/").path)
false
So when I try to process the file at the provided URL, it fails of course. Any ideas on how I can fix this?
This is happening while running the code on an iPad with iOS 18.5 from Xcode 16.4. If it makes a difference, the AirDrop is originated from an iPhone 16 Pro also running iOS 18.5.