获取应用程序的路径
我正在使用以下代码来获取应用程序的路径。它适用于所有情况,但不适用于前排。
CFStringRef cfStrAppShortName = NULL;
FSRef appRef;
CFURLRef cfAppUrlRef = NULL;
CFBundleRef cfAppBundleRef = NULL;
CFDictionaryRef cfAppDictRef = NULL;
CFStringRef cfStrAppBundleName = NULL;
OSErr osErr;
cfStrAppShortName = CFSTR(Front Row);
if(cfStrAppShortName != NULL)
{
osErr = LSFindApplicationForInfo(kLSUnknownCreator,NULL,cfStrAppShortName,&appRef,NULL);
if(osErr == noErr)
{
cfAppUrlRef = CFURLCreateFromFSRef ( kCFAllocatorDefault, &appRef);
cfAppBundleRef = CFBundleCreate (kCFAllocatorDefault,cfAppUrlRef);
cfAppDictRef = CFBundleGetInfoDictionary (cfAppBundleRef);
cfStrAppBundleName = (CFStringRef)CFDictionaryGetValue (cfAppDictRef,kCFBundleNameKey);
}
我期望来自应用程序文件夹的应用程序路径,但它来自 /system/coreservices/..
对于 /system/library/coreservices/.. 中存在的所有项目都会发生这种情况。
是否有任何不应该在 /system/library/coreservices.. 中查找的问题或任何更好的解决方案? 有人可以帮助我吗?
提前致谢。
I am using following code to fetch the path of the application. It works for all cases but fails for front row.
CFStringRef cfStrAppShortName = NULL;
FSRef appRef;
CFURLRef cfAppUrlRef = NULL;
CFBundleRef cfAppBundleRef = NULL;
CFDictionaryRef cfAppDictRef = NULL;
CFStringRef cfStrAppBundleName = NULL;
OSErr osErr;
cfStrAppShortName = CFSTR(Front Row);
if(cfStrAppShortName != NULL)
{
osErr = LSFindApplicationForInfo(kLSUnknownCreator,NULL,cfStrAppShortName,&appRef,NULL);
if(osErr == noErr)
{
cfAppUrlRef = CFURLCreateFromFSRef ( kCFAllocatorDefault, &appRef);
cfAppBundleRef = CFBundleCreate (kCFAllocatorDefault,cfAppUrlRef);
cfAppDictRef = CFBundleGetInfoDictionary (cfAppBundleRef);
cfStrAppBundleName = (CFStringRef)CFDictionaryGetValue (cfAppDictRef,kCFBundleNameKey);
}
I was expecting application path from Applications folder, but it comes from /system/coreservices/..
This happens for all items present in /system/library/coreservices/.. .
Is there any was that it should not look in /system/library/coreservices.. or any better solution?
Can anyone help me?
Thanks in Advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
识别应用程序的更可靠方法是通过捆绑包标识符。以 Front Row 为例,有两个同名的独立应用程序:
查看包标识符,看起来这个函数毕竟返回了正确的 Front Row 的路径,因为 /Applications 中的路径只是一个启动器。
但您不应该依赖于此——该函数可以随时返回启动器的路径。此外,任何人都可以创建一个应用程序包并将其命名为“Front Row”。
使用捆绑包标识符,以便您始终要求正确的应用程序。
A more reliable way to identify an application is by bundle identifier. In the case of Front Row, for example, there are two separate applications with the same name:
Looking at the bundle identifiers, it looks like this function is returning the path to the correct Front Row after all, since the one in /Applications is just a launcher.
But you shouldn't rely on that—the function could return the launcher's path at any time. Moreover, anybody could create an application bundle and name it “Front Row”.
Use the bundle identifier, so that you are always asking for the correct application.