按路径获取绑定包

  1. 使用其路径定位 Cocoa 包

要使用 Cocoa 在特定路径获取 bundle,请调用 NSBundlebundleWithPath: class 方法 ****

   NSBundle *myBundle;
   // obtain a reference to a loadable bundle 
   myBundle = [NSBundle bundleWithPath:@"/Library/MyBundle.bundle";
  1. 使用其路径查找 Cocoa Foundation 绑定包

要使用 Core Foundation 在特定路径获取绑定包,请调用 CFBundleCreate 函数并且必须使用 CFURLRef 类型。

   CFURLRef bundleURL;
   CFBundleRef myBundle;
   // Make a CFURLRef from the CFString representation of the bundle's path.
   bundleURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, CFSTR("/Library/MyBundle.bundle"), kCFURLPOSIXPathStyle, true);
   // Make a bundle instance using the URLRef.
   myBundle = CFBundleCreate(kCFAllocatorDefault, bundeURL);
   // You can release the URL now.
   CFRelease(bundleURL);
   // Use the bundle ...
   // Release the bundle when done.
   CFRelease(myBundle);