开发者

how to use CFURLCreateFromFileSystemRepresentation

I'm learning core audio on the iPhone. I have been using the higher level api's so alot of the stuff involved wi开发者_开发问答th core audio is new to me. To get a referance to a file I usually use [[NSBundle mainBunle]pathForResource:]; then creating an NSURL from the string thats retuned.

but with core audio, I need to use-

CFURLRef CFURLCreateFromFileSystemRepresentation (
   CFAllocatorRef allocator,
   const UInt8 *buffer,
   CFIndex bufLen,
   Boolean isDirectory
);

Parameters allocator The allocator to use to allocate memory for the new CFURL object. Pass NULL or kCFAllocatorDefault to use the current default allocator.

buffer The character bytes to convert into a CFURL object. This should be the path as you would use in POSIX function calls.

bufLen The number of bytes in the buffer.

isDirectory A Boolean value that specifies whether the string is treated as a directory path when resolving against relative path components—true if the pathname indicates a directory, false otherwise.

What would I pass in as the second argument to this function. Thanks in advance.


NSURL is toll-free bridged with CFURLRef. That means you can just cast a NSURL to a CFURLRef, like this:

CFURLRef url = (CFURLRef)[[NSBundle mainBunle] URLForResource:...];

If you really want to use CFURLCreateFromFileSystemRepresentation, the second parameter is an array of characters, much like a C-style "char *" string.


Try this magic:

NSString* path = @"/var/mobile/Applications/B1C8276B-D5ED-4D1E-BB2C-07D2AB7381B3/TCCTest.app";
CFURLRef url = CFURLCreateFromFileSystemRepresentation(0,
                               (char*)path.cString, path.length, false);

CFBundleRef bun =  CFBundleCreate(kCFAllocatorDefault, url);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜