Reading data (embedded plist) linked to executable through -sectcreate __TEXT

后端 未结 4 1826
礼貌的吻别
礼貌的吻别 2021-01-31 09:55

I am linking a executable with a plist using -sectcreate __TEXT linker flags. Reason for this is mainly to use the SMJobBless() method. But I need to read plist lin

4条回答
  •  别跟我提以往
    2021-01-31 10:54

    There's a CoreFoundation function for that: CFBundleCopyInfoDictionaryForURL(). From the documentation:

    For a directory URL, this is equivalent to CFBundleCopyInfoDictionaryInDirectory. For a plain file URL representing an unbundled application, this function will attempt to read an information dictionary either from the (__TEXT, __info_plist) section of the file (for a Mach-O file) or from a plst resource.

    It's available on Mac OS X v10.2 and later. If you use in Cocoa you can do this (provided you have an (NSURL*)url for the bundle):

    NSDictionary* infoPlist = [ (NSDictionary*) CFBundleCopyInfoDictionaryForURL( (CFURLRef) url ) autorelease];
    

提交回复
热议问题