summaryrefslogtreecommitdiff
path: root/SmartDeviceLink/NSBundle+SDLBundle.m
blob: 5880a5927fd7ad8851d6bbdf21135c3a6ea6630e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
//  NSBundle+SDLBundle.m
//  SmartDeviceLink-iOS
//
//  Created by Joel Fischer on 8/31/16.
//  Copyright © 2016 smartdevicelink. All rights reserved.
//

#import "NSBundle+SDLBundle.h"

#import "SDLManager.h"

NS_ASSUME_NONNULL_BEGIN

@implementation NSBundle (SDLBundle)

+ (nullable NSBundle *)sdlBundle {
    NSURL *sdlBundleURL = [[NSBundle mainBundle] URLForResource:@"SmartDeviceLink" withExtension:@"bundle"];
    NSBundle *sdlBundle = nil;

    if (sdlBundleURL != nil) {
        sdlBundle = [NSBundle bundleWithURL:sdlBundleURL];
    }
    if (sdlBundle == nil) {
        NSBundle *frameworkBundle = [NSBundle bundleForClass:[SDLManager class]];

        // HAX: Cocoapods will have the bundle as an inner bundle that we need to unpack...because reasons. Otherwise it's just the bundle we need
        NSURL *innerBundleURL = [frameworkBundle URLForResource:@"SmartDeviceLink" withExtension:@"bundle"];
        if (innerBundleURL) {
            sdlBundle = [NSBundle bundleWithURL:innerBundleURL];
        } else {
            sdlBundle = frameworkBundle;
        }
    }
    if (sdlBundle == nil) {
        @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:@"SDL WARNING: The 'SmartDeviceLink.bundle' resources bundle was not found. If you are using cocoapods, try dragging the bundle from the SmartDeviceLink-iOS pod 'products' directory into your resources build phase. If this does not work, please go to the SDL slack at slack.smartdevicelink.com and explain your issue. You may disable the lockscreen in configuration to prevent this failure, for now." userInfo:nil];
    }

    return sdlBundle;
}

@end

NS_ASSUME_NONNULL_END