Home‎ > ‎

CFBundleのロード

サンプルソース:

-(BOOL)loadLaunchCheckerBundle:(NSString*)appName
{
     CFBundleRef cfBundle;
     CFURLRef bundleURL;

     NSString* plugInsPath = [[NSBundle mainBundle] builtInPlugInsPath];
     NSString* bundleFullPath = [plugInsPath stringByAppendingPathComponent:@"LaunchChecker.bundle"];
     CFStringRef cfBundlePath= (CFStringRef)bundleFullPath;
     bundleURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfBundlePath, kCFURLPOSIXPathStyle, true );

     cfBundle = CFBundleCreate(kCFAllocatorDefault, bundleURL);
     typedef bool (*LaunchCheck)(const CFStringRef,int,int,int*);

     LaunchCheck LaunchCheckPtr = NULL;

     LaunchCheckPtr = (void*)CFBundleGetFunctionPointerForName(cfBundle, CFSTR("LaunchCheck"));
     if(LaunchCheckPtr)
     {
          int mode = kMode_Normal;
          int isRestart = kResult_NoRestart;
          int result;
 
          CFStringRef cfAppNameStr = (CFStringRef)appName;
          LaunchCheckPtr(cfAppNameStr, mode, isRestart, &result);
          if (result == kResult_Terminate)
          {
               CFRelease(cfBundle);
               return NO;
          }

     }
 
     //更新チェックモジュールが動作していない場合や、
     //kResult_Proceedがかえってきた場合は何もしない
     CFRelease(cfBundle);
     return YES;
}