Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 307
Moshe Avatar asked Sep 19 '25 16:09

Moshe


1 Answers

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.

like image 178
Grant Butler Avatar answered Sep 22 '25 11:09

Grant Butler