Reputation: 6087
I'm developing a download and share file method to other apps using UIDocumentInteractionController
. But strangely, all I can get is "copy to" apps features, instead of "open in" apps. If I click on the "copy to", nothing happened, even though I know that what happens behind the screen is that the file is copied to the other app. But I don't want that the file is just copied. I want the other app to actually switch over and open the file.
This is the code I use to download and share the file:
Alamofire.download(url, to:destination)
.downloadProgress { (progress) in
print((String)(progress.fractionCompleted))
}
.responseData { (data) in
print("DOWNLOAD COMPLETED")
print("DESTINATION URL: \((data.destinationURL)!)")
print("DESTINATION PATH: \((data.destinationURL?.path)!)")
let documentController = UIDocumentInteractionController.init(url: (data.destinationURL)!)
documentController.delegate = self
documentController.presentOpenInMenu(from: CGRect.zero, in: self.view, animated: true)
}
The file that's particularly downloaded and shared in the screenshot above is a .PDF file.
Upvotes: 2
Views: 2788
Reputation: 2573
There is nothing you can do here. Files get copied to the app or opened in the app depending on what the receiving app itself implements: if the app supports open-in-place (and your document is in an accessible location such as your Documents directory), you should get open ; if the app does not support open in place, it will copy.
So what you need to do is lobby the developers of apps you want to share documents with to adopt open-in-place.
Upvotes: 0
Reputation: 3040
Attempting to open files in other apps can be achieved using Apple's Universal Links. They permit you to launch another application from your current application. If implemented properly, they enable you to open the document/file in another app on the grounds that the other app has a method of handling incoming Universal Links and is registered to accept the document/file type.
An excellent way to start working with Universal Links is to attempt to integrate document sharing from your file to, say, Microsoft Word. The specific URL scheme to use for this example can be found here. There are many YouTube videos that explain the concept of linking as well as demonstrate how to implement it.
Upvotes: 2
Reputation: 197
This could be due to the file's accessibility issues to other apps. We faced same issue, and we could resolve it only after writing the file to tmp / documents directory. Try enabling permissions like 'File sharing' and 'Open in Place' options too. Refer this blog: https://medium.com/if-let-swift-programming/managing-files-in-ios-dfcdfdc1f426
Upvotes: 1