按路徑獲取繫結包

  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);