Re: LSOpenCFURLRef() Not Working
Re: LSOpenCFURLRef() Not Working
- Subject: Re: LSOpenCFURLRef() Not Working
- From: Jean-Daniel Dupas <email@hidden>
- Date: Wed, 3 Sep 2008 12:22:31 +0200
Le 3 sept. 08 à 12:05, kalpana k a écrit :
On 9/3/08, Jean-Daniel Dupas <email@hidden> wrote:
Le 3 sept. 08 à 11:44, kalpana k a écrit :
Hi all,
I am developing an application on Mac OS X 10.4.11. I am using
LSOpenCFURLRef() for opening a pdf file.
This function is working fine on 10.4.x , but when I take this
application to Leopard (10.5.x) it doesn't work.
Also if the application is build using Xcode 3.0 on Mac OS X 10.5
this function is working fine.
My Code snippet :
void OpenHelpFile(){
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFStringRef path1 = CFURLGetString (CFBundleCopyBundleURL
( mainBundle));
if(mainBundle == NULL)
{
return;
}
char buffer[100] ;
Boolean r = CFStringGetCString ( path1, buffer, 100,
kCFStringEncodingUTF8);
strcat(buffer,"Contents/Resources/Java/MAC_Eng.pdf");
CFURLRef urlPath = CFURLCreateWithString ( kCFAllocatorDefault,
fullPath ,NULL);
CFStringRef path2 = CFURLGetString (urlPath);
CFShow(path2); // case 1
CFURLRef outurlPath;
OSStatus status = LSOpenCFURLRef (urlPath, &outurlPath);
path2 = CFURLGetString (outurlPath);
CFShow(path2); // case 2
}
You must not create the url manually, you should use
CFBundleCopyResourceURL instead.
CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("MAC_Eng"),
CFSTR("pdf"), CFSTR("Java"));
That said, the error does not come from you code, but from your Mac
OS X installation. What append if you launch preview by hand, or if
you double clic on the pdf icon ?
Hi Daniel,
I have tried using CFBundleCopyResourceURL(),
CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("MAC_Eng"),
CFSTR("pdf"), CFSTR("Java"));
but this function itself gives error and does not create proper URL
in return.
Check you Bundle contents, I did a test, and it works on my computer
(I know, there is a memory leak):
CFShow(CFBundleCopyResourceURL(CFBundleGetMainBundle(),
CFSTR("MAC_Eng"), CFSTR("pdf"), CFSTR("Java")));
=>
<CFURL 0x13b590 [0xa02911a0]>{type = 0, string = /Users/Projects/
Products/MyProject/Debug/MyProject.app/Contents/Resources/Java/
MAC_Eng.pdf, base = (null)}
>That said, the error does not come from you code, but from your Mac
OS X installation. What append if you launch preview by hand, or if
>you double clic on the pdf icon ?
If i launch the Preview.app before calling my code it opens the pdf
file correctly in Leopard also. But in case when Preview is not
launched
my code is not able to launch Preview in Leopard only.
Thanks for your reply,
Kalpana
Are you sure you have only one "Preview.app" on you computer. Maybe
there is an other preview application that confuse LaunchServices (on
another partition for example).
Once preview is launched, LaunchServices will use the running instance
to open your pdf, that why it works when you launch it before opening
your file.
You may try to find what append using LSGetApplicationForURL(). Ask
Launch services the full path of the application it is trying to use
to open your file.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden