MobileApplication.HandleURL not obvious

Greg, I noticed your file sharing switch was off, and it still worked.
I copied your plist additions over and modified it for my app, and now it works.
Interestingly though… previously I could tap on the file and it would open. This doesn’t happen now, rather I get a “preview” and have to tell it to open in my app. I think that’s because your plist didn’t have the OpenInPlace flags, where my previous one did.
I’m going to test that out again later today and see if it was the problem.

Thanks for all the effort you put into this. I really appreciate it.

Greg,

as soon as I add LSSupportsOpeningDocumentsInPlace = TRUE into the plist the behavior with file not being available returns.
Not sure if this is a bug or if there is more that needs to go into the apps capabilities or entitlements or …
I can live without it opening in place.

What’s interesting is that almost every tutorial I’ve found about how to do this tells you to set that key to False. Makes me wonder if there’s a bug there that Apple won’t or can’t fix.

The other possibility is that the URL you were getting was actually a security scoped bookmark. If that’s the case there are other things you have to do to get access to them.

Yeah that’s it:

LSSupportsOpeningDocumentsInPlace (Boolean - iOS) When set to a value of YES, enables your app to open the original document from a file provider, rather than a copy of the document. The app can access documents from the system’s local file provider, the iCloud file provider, and any third-party File Provider extensions that support opening documents in place.

The URL for a document opened in place is security-scoped. For information about working with security-scoped URLs and bookmarks, read the overview in NSURL Class Reference and read Document Provider in App Extension Programming Guide.

Ok this is good to know.

Thanks again, Greg.

This is killing me again. Pulling my last hair out!

It seems that I can open a document when I tap on it from mail.
I cannot from messages, but I can save it in my files, and from files I can tap on it to (try) to open it in my app. However I cannot access the file from the URL.

From the app.handleURL I’m doing the following:

Var file As FolderItem = New FolderItem( url, folderitem.PathModes.URL )

file.exists is always false when I open from files.

Any idea why?

Are you certain that the pathmode is of URL type?
Maybe try with Pathmodes.native

I understand the frustration, currently experiencing the same with a memory leak on iOS…

it comes up as file:///private/var/mobile/…
I assumed that a url from the format, but also from the function name HandleURL.

It also OpenInPlace = false

These issues are always tricky when you can only see the issues on the hardware, but we can’t debug on the hardware. It’s a time vampire. I wish there was a remote debugger for iOS, but I’m pretty sure that would be impossible from a security perspective.

If the url starts with file:/// then yes it is the PathModes.URL is correct.

Do you have iOSKit from Jason King in your App?

If you do, calling NSURL.StartAccessingSecurityScopedResource might help.
Then read the data and make a new file in your App sandbox
Finally call NSURL.StopAccessingSecurityScopedResource

I can try that.
But I just looked in the console and I see this error.

Sandbox: SpotOn Color(579) deny(1) file-read-metadata /private/var/mobile/Containers/Shared/AppGroup/A077269F-BD1A-4AD7-BDA8-BF040E9F12FF/File Provider Storage/chris test 2.soj

What I’m doing getting a reference to the file, then copying it to a temporary location to work with it. I figure this should work regardless of the OpenInPlace true/false flag.

I just trapped an unhandled exception:

The file “chris test2.soj” couldn’t be opened because you don’t have permissions to view it.

This occurs when I try to copy the file, not open it.
Will try iOSKit

iOSKit failed to compile with a lot of errors.

You need to disable Simple References in build settings to compile iOSKit

I never knew what that was for.
I’ll try.

Thanks, Jason.

OK, now I can compile iOSKit in, but I still cannot open that file using Jeremie’s recommendation.

The upshot of trying this and it failing is that now I do have iOSKit in my project and that has a ton of stuff that I’m happy to use.

Since you now have a error message when opening it might be time to search stack overflow or the Apple dev forums. There is probably someone else who had the same error and might have a solution. We can help convert whatever switch/obj-c to Xojo if you find a solution

Does anyone have a simple example of this working? I’d love to try to reverse engineer the difference between a working project and mine.

I’ve done everything I can imagine and it just won’t behave.
It’s funny, reading a file into my software is something I’ve taken for granted for so long, to now lose this much time trying to do it is really hard to stomach.

I’d be curious to see an example of how to use NSURL.StartAccessingSecurityScopedResource correctly. I tried:

Var theRef as CFStringRef = url
var vNSURL as new NSURL(theRef, False)
if vNSURL.StartAccessingSecurityScopedResource then

where url is the string returned by HandleURL but cause a crash with the console message:

*** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘*** +[NSString<0x20da2d170> init]: cannot init a class object.’

I’m afraid I’m out of my league here and would appreciate any help I can get!

1 Like

I don’t know how the security scoped book mark part works but you don’t need to create the CFStringRef like that. String and Text types are automatically converted for you if you pass them into a function expecting a CFStringRef. The crash you are getting is a little weird since normally that means something isn’t being allocated. Can you try to do

Var vNSURL as new NSURL(url)

And see if that resolves the crash?