Here is my code:
-(BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
if (url != nil && [url isFileURL]) {
NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
if ( [[NSFileManager defaultManager] isReadableFileAtPath:[url absoluteString]] ) {
NSLog(@"READABLE!");
[[NSFileManager defaultManager] copyItemAtPath:[url absoluteString] toPath:[documentsPath stringByAppendingString:@"/timecode.xml"] error:nil];
} else {
NSLog(@"NOT READABLE!");
}
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:[documentsPath stringByAppendingString:@"/timecode.xml"]];
if (fileExists) {
NSLog(@"THERE!");
} else {
NSLog(@"NOT THERE!");
}
}
}
For some reason when I open a file from the mail app (or any other app, including good reader) into my app, it says it isn’t readable. And obviously, the file doesn’t exist.
Any ideas why this is happening?
Because an URL is not a path.
looks like
You need to use
instead.
Also, two comments:
is highly superfluous.
will return
NOanyway if the URL isnil(since messagingnilalways returns zero).Two:
Don’t reinvent the wheel/try to guess the path separator. This line should be