Search code examples
iosios8-today-widgettoday-extension

Can I read my app extension's info.plist in my host app?


I've built a today widget and I want to show what version is running in my host app's about screen. Is there a way to do that?

I've tried replacing [NSBundle mainBundle] with bundleWithIdentifier but that fails. So, is there a way to get the infoDictionary from he extension bundle, or am I wasting my time?


Solution

  • You can pull this off by specifying the direct path to the extension's bundle. It looks like app extensions live in the PlugIns/ folder in your app's main bundle. You can create an instance of NSBundle by using -initWithPath:. For example:

    - (NSBundle *)appExtensionBundle {
        NSString *plugInsPath = [NSBundle mainBundle].builtInPlugInsPath;
        NSString *appExtensionPath = [plugInsPath stringByAppendingPathComponent:@"MyTodayExtension.appex"];
        return [[NSBundle alloc] initWithPath:appExtensionPath];
    }
    

    NOTE: This code was tested only with a Today extension. You should test to make sure it works correctly if you have other types of extensions.