Skip to content

Commit

Permalink
Merge pull request intentkit#57 from ransomweaver/master
Browse files Browse the repository at this point in the history
Use NSBundle bundleForClass in place of mainBundle
  • Loading branch information
lazerwalker committed May 24, 2015
2 parents f38da53 + 0463fd3 commit 658a03d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
8 changes: 4 additions & 4 deletions IntentKit/Core/INKApplicationList.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ - (NSString *)fallbackUrlForCommand:(NSString *)command {
}

- (NSDictionary *)handlerDefaults {
NSURL *bundleURL = [[NSBundle mainBundle] URLForResource:@"IntentKit-Defaults" withExtension:@"bundle"];
NSURL *bundleURL = [[NSBundle bundleForClass:[INKApplicationList class]] URLForResource:@"IntentKit-Defaults" withExtension:@"bundle"];
NSBundle *bundle;
if (bundleURL) {
bundle = [NSBundle bundleWithURL:bundleURL];
Expand All @@ -140,21 +140,21 @@ - (NSDictionary *)handlerDefaults {

- (NSBundle *)bundleForCurrentHandler {
NSString *resourceName = [NSString stringWithFormat:@"IntentKit-%@", NSStringFromClass(self.handlerClass)];
NSURL *bundleURL = [[NSBundle mainBundle] URLForResource:resourceName withExtension:@"bundle"];
NSURL *bundleURL = [[NSBundle bundleForClass:[INKApplicationList class]] URLForResource:resourceName withExtension:@"bundle"];
NSBundle *bundle;
if (bundleURL) {
bundle = [NSBundle bundleWithURL:bundleURL];
}

if (!bundle) {
NSURL *bundleURL = [[NSBundle mainBundle] URLForResource:@"IntentKit" withExtension:@"bundle"];
NSURL *bundleURL = [[NSBundle bundleForClass:[INKApplicationList class]] URLForResource:@"IntentKit" withExtension:@"bundle"];
if (bundleURL) {
bundle = [NSBundle bundleWithURL:bundleURL];
}
}

if (!bundle) {
bundle = [NSBundle mainBundle];
bundle = [NSBundle bundleForClass:[INKApplicationList class]];
}

return bundle;
Expand Down
2 changes: 1 addition & 1 deletion IntentKit/Core/INKDefaultsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ - (NSString *)defaultApplicationForHandler:(Class)handlerClass
if (name) {
return name;
} else if (allowSystemDefault) {
NSURL *bundleURL = [[NSBundle mainBundle] URLForResource:@"IntentKit-Defaults" withExtension:@"bundle"];
NSURL *bundleURL = [[NSBundle bundleForClass:[INKDefaultsManager class]] URLForResource:@"IntentKit-Defaults" withExtension:@"bundle"];
NSBundle *bundle;
if (bundleURL) {
bundle = [NSBundle bundleWithURL:bundleURL];
Expand Down
5 changes: 3 additions & 2 deletions IntentKit/Core/INKLocalizedString.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
//

#import "INKLocalizedString.h"
#import "IntentKit.h"

NSString *INKLocalizedString(NSString *key, NSString *comment) {
NSString *result = @"";

static NSBundle *bundle = nil;
if (bundle == nil)
{
NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"IntentKit-Localizations" ofType:@"bundle"];
NSString *bundlePath = [[NSBundle bundleForClass:[IntentKit class]] pathForResource:@"IntentKit-Localizations" ofType:@"bundle"];
bundle = [NSBundle bundleWithPath:bundlePath];

NSString *language = [[NSLocale preferredLanguages] count]? [NSLocale preferredLanguages][0]: @"en";
Expand All @@ -30,6 +31,6 @@
bundle = [NSBundle bundleWithPath:bundlePath] ?: [NSBundle mainBundle];
}
result = [bundle localizedStringForKey:key value:result table:nil];
return [[NSBundle mainBundle] localizedStringForKey:key value:result table:nil];
return [[NSBundle bundleForClass:[IntentKit class]] localizedStringForKey:key value:result table:nil];

};
2 changes: 1 addition & 1 deletion IntentKit/Core/IntentKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ - (UIViewController *)topViewController:(UIViewController *)parent {
}

- (UIImage *)imageNamed:(NSString *)name {
NSURL *bundleURL = [[NSBundle mainBundle] URLForResource:@"IntentKit" withExtension:@"bundle"];
NSURL *bundleURL = [[NSBundle bundleForClass:[IntentKit class]] URLForResource:@"IntentKit" withExtension:@"bundle"];
NSBundle *bundle;
if (bundleURL) {
bundle = [NSBundle bundleWithURL:bundleURL];
Expand Down

0 comments on commit 658a03d

Please sign in to comment.