Skip to content

Instantly share code, notes, and snippets.

@samdmarshall
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samdmarshall/9050864 to your computer and use it in GitHub Desktop.
Save samdmarshall/9050864 to your computer and use it in GitHub Desktop.
//
// bundle.c
// Daodan
//
// Created by Sam Marshall on 2/16/14.
// Copyright (c) 2014 Sam Marshall. All rights reserved.
//
#ifndef Daodan_bundle_c
#define Daodan_bundle_c
#include "bundle.h"
#define kCFDaodanPreferenceBundle CFSTR("com.samdmarshall.Daodan")
bool Daodan_DetectBundle() {
bool foundBundle = false;
CFStringRef currentApp = CFBundleGetIdentifier(CFBundleGetMainBundle());
CFArrayRef knownApps = (CFArrayRef)CFPreferencesCopyAppValue(CFSTR("RegisteredPlugins"), kCFDaodanPreferenceBundle);
CFShow(knownApps); // SDM: this line here will cause bad things
// By removing line 20, the rest of the code executes fine
CFIndex knownAppsCount = CFArrayGetCount(knownApps);
for (CFIndex index = 0; index < knownAppsCount; index++) {
CFDictionaryRef app = (CFDictionaryRef)CFArrayGetValueAtIndex(knownApps, index);
CFShow(app);
CFStringRef appIdentifier = CFDictionaryGetValue(app, CFSTR("CFBundleIdentifier"));
if (CFStringCompare(appIdentifier, currentApp, kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
printf("found a registered plugin for current app!\n");
CFShow(app);
// However when i get to here, the dictionary that should have two values only ever displays the one value (CFBundleIdentifier)
}
}
return foundBundle;
}
#endif
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>RegisteredPlugins</key>
<array>
<dict>
<key>CFBundleIdentifier</key>
<string>com.somedomain.someapp</string>
<key>LoadPlugin</key>
<string>~/Library/Application Support/Daodan/Test.dylib</string>
</dict>
</array>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment