Question

I'm currently trying to implement the opening file from another app. When I got to a third party app (like documents) and opening a file with my app, I can't seems to be able to open it with NSFileHandle.

After the AppDelegates method is called :

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation

I get an url like this :

file://localhost/private/var/mobile/Applications/E9F2998C-1ED2-4955-9681-30C518FBD1A5/Documents/Inbox/text%20source%20%C3%A0%20ID-7.docx

I have tried to remove manually file://localhost/private in order to look like a NSBunble path, but no luck...

Does anyone have a simple way to open with NSFileHandle an URL got from that delegate method ?

Was it helpful?

Solution

To convert the file NSURL value to an actual pathname that can be used by methods and functions that require a file path, call the path method.

if ([url isFileURL]) {
    NSString *filePath = [url path];
    // use filePath as needed
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top