Re: URI de/encoding
Re: URI de/encoding
- Subject: Re: URI de/encoding
- From: Chris Parker <email@hidden>
- Date: Thu, 18 May 2006 10:18:43 -0700
On May 18, 2006, at 10:04 AM, gnat wrote:
On May 18, 2006, at 10:41, Jim Correia wrote:
The documentation for -[NSURL path] says:
<http://devworld.apple.com/documentation/Cocoa/Reference/Foundation/ObjC_classic/Classes/NSURL.html#//apple_ref/occ/instm/NSURL/path
>
"If isFileURL returnsYES, the return value is suitable for input
into NSFileManager or NSPathUtilities."
It sounds like you are passing something else to the file manager.
I saw that, so i'm not sure what is going on. The XML file I am
loading is "~/Music/iTunes/iTunes Music Library.xml" which gets
loaded into an NSDictionary object. When I get to that point, I pull
the Location object out of a Track and store it in a NSString. This
path looks something like "file://localhost/Users/gnat/Music/iTunes/iTunes Music/Compilations/Vespertine/01 Hidden Place.mp3
" and my target NSString would look like "file://localhost/Volumes/test/Music/01 Hidden Place.mp3
". If I pass this to copyPath:, it returns false (and I can't find
an error message anywhere). If I strip the "file://localhost" and
replace the s with spaces, the copy works fine.
Now that i've figured out how to use the handler: option, the error
it is reporting is "Couldn't open" and the Path is the source (there
isn't a ToPath being populated). One thing I do notice is that the
Path is missing the second / after file: (i.e. file:/localhost
instead of file://localhost), but when I use NSLog to log my source
NSString after copyPath: returns FALSE they are both there.
The problem here is that you're passing the URL as a string to
copyPath:toPath:handler:.
NSURL * mp3URL = [NSURL URLWithString:@"file://localhost/Users/gnat/Music/iTunes/iTunes Music/Compilations/Vespertine/01 Hidden Place.mp3
"];
if ([mp3URL isFileURL]) {
NSString * mp3Path = [mp3URL path];
// do the copying here with mp3Path
}
-[NSURL path] will take care of stripping the "file://localhost/" and
percent-escapes for you.
I've wondered why I get occasional bugs indicating URLs were coming in
on the copyPath:toPath:handler: argument. I think some sample code at
that point in the URL documentation, or a slightly clearer explanation
might be in order.
.chris
--
Chris Parker
Cocoa Frameworks
Apple Computer, Inc.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden