Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Files opened by "Copy to" on iOS are not re-openable #3

Merged
merged 7 commits into from
Jun 9, 2020

Conversation

amake
Copy link
Contributor

@amake amake commented Jun 5, 2020

On iOS, files can be opened from other apps in two ways:

  • "Open in MyApp"
    • Received in application(_:open:options:) as an "open in place" security-scoped resource
    • options map contains UIApplicationOpenURLOptionsOpenInPlaceKey: true
  • "Copy to MyApp"
    • Received in application(_:open:options:) as a regular (non-security-scoped) file URI
    • File is already copied to app container, so can always be persistently accessed
    • options map contains UIApplicationOpenURLOptionsOpenInPlaceKey: false in my observation (could hypothetically have nil or the key might be absent)

Previously, I thought that with correct setup (proper keys in Info.plist), all apps would be able to "Open In", but it turns out that some, in particular Google Drive, can never "Open In" but only offer "Copy To", regardless of the target application and its capabilities.

file_picker_writable currently handles receiving "Copy To" files OK: it ignores the failure to obtain a security scope in _prepareUrlForReading:

private func _prepareUrlForReading(url: URL) throws -> [String: String] {
let securityScope = url.startAccessingSecurityScopedResource()
defer {
if securityScope {
url.stopAccessingSecurityScopedResource()
}
}
let bookmark = try url.bookmarkData()
let tempFile = try _copyToTempDirectory(url: url)
return _fileInfoResult(tempFile: tempFile, originalURL: url, bookmark: bookmark)
}

But when trying to reopen a bookmark obtained from such a file, it fails due to strict checking in readFile:

if !url.startAccessingSecurityScopedResource() {
throw FilePickerError.readError(message: "Unable to start accessing security scope resource.")
}

@amake
Copy link
Contributor Author

amake commented Jun 6, 2020

Now this PR fixes #4 as well.

Copy link
Owner

@hpoul hpoul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, looks good, just two small things.. see my inline comments and let me know what you think

ios/Classes/SwiftFilePickerWritablePlugin.swift Outdated Show resolved Hide resolved
ios/Classes/SwiftFilePickerWritablePlugin.swift Outdated Show resolved Hide resolved
lib/src/file_picker_writable.dart Show resolved Hide resolved
Copy link
Owner

@hpoul hpoul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, lgtm 👍️

@hpoul hpoul merged commit 9622a46 into hpoul:master Jun 9, 2020
@amake
Copy link
Contributor Author

amake commented Jun 9, 2020

Thanks for merging. But somehow I don't see it in the master branch.

@hpoul
Copy link
Owner

hpoul commented Jun 9, 2020

oops sorry.. no idea how that happened.. i think i've did one force push too many..
thanks for catching that 🤦️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants