I'm having an issue with sharing an image to Instagram via the iOS share sheet. I need to share the image through a URL to a local file, since I want the image to be named a certain way when shared, and that's the only way I found I could do that. The code is:
//This saves the image into the local temp directory and returns the file url
saveImageForSharing(image: image!) {(tempUrl) in
if tempUrl != nil {
let objectsToShare = [tempUrl!]
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
self.present(activityVC, animated: true, completion: nil)
}
}
When the UIActivityViewController comes up you can share the image successfully to ALL the services available (including Facebook, email, Twitter etc), EXCEPT Instagram. When sharing to Instagram, the following error pops up:

Setting a completion handler for the UIActivityViewController's completionWithItemsHandler, the 'success' parameter is returned as false, but the error object is nil, so there's no information to be had about what went wrong.
When sharing a UIImage directly, there's no problem. Also when saving to a different URL or when changing the file name.
Any ideas what could be happening here, or how I can share an image successfully while also setting the item's name?
Edit: I've also encountered this problem when trying to share a video through its url. The video is stored simply in the Photos library, and I can't get Instagram to accept it, even though it shared perfectly well when sharing from the Photos app! Also, I'm getting a message in the output console that says "Failed to ssue sandbox token for URL:". Any advice?
Thanks!