operating system - How to Convert NSURL to CFURLRef -
apple gives sample code creating pdf document. uses cfurlref
nspanel savepanel gives nsurl.
i can't convert nsurl cfurlref
path = cfstringcreatewithcstring (null, filename, kcfstringencodingutf8); url = cfurlcreatewithfilesystempath (null, path, kcfurlposixpathstyle, 0); nslog(@"cfurlref %@",url);
output is
2016-04-22 00:34:26.648 xxx analysis[12242:813106] cfurlref analysisreport.pdf -- file:///users/xxxxxx/library/containers/com.xxxxxx.xxxnalysis/data/
convert code find
url = (__bridge cfurlref)thefile; nslog(@"nsurl %@",url);
output
2016-04-22 00:37:20.494 xxx analysis[12325:816505] nsurl file:///users/xxxxxx/documents/xxxnalysis.pdf
at end pdf file saved program crash when nspanel closed.
cfurlref
, nsurl
toll-free bridged. typically, this:
nsurl *url = ...; cfurlref cfurl = cfbridgingretain(url);
and when no longer need cfurl object:
cfrelease(cfurl);
or if you're reasonably nsurl stick around long enough, can do
cfurlref cfurl = (__bridge cfurlref)url;
if you're getting crash, means you're over-releasing — specifically, you're releasing object don't own. suggest reading apple's docs on object ownership:
Comments
Post a Comment