summaryrefslogtreecommitdiff
path: root/SmartDeviceLink/SDLAppInfo.m
blob: 1b7ec0150fa1023946675f24552740c8c623f461 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//  SDLAppInfo.m
//

#import "SDLAppInfo.h"

#import "NSMutableDictionary+Store.h"
#import "SDLRPCParameterNames.h"

static NSString *const SDLBundleShortVersionStringKey = @"CFBundleShortVersionString";
static NSString *const SDLBundleAppNameKey = @"CFBundleName";

NS_ASSUME_NONNULL_BEGIN

@implementation SDLAppInfo

+ (instancetype)currentAppInfo {
    static SDLAppInfo *appInfo = nil;
    if (appInfo == nil) {
        appInfo = [[SDLAppInfo alloc] init];
        NSBundle *mainBundle = [NSBundle mainBundle];
        NSDictionary *bundleDictionary = mainBundle.infoDictionary;
        appInfo.appDisplayName = bundleDictionary[SDLBundleAppNameKey];
        appInfo.appVersion = bundleDictionary[SDLBundleShortVersionStringKey];
        appInfo.appBundleID = mainBundle.bundleIdentifier;
    }
    return appInfo;
}

- (void)setAppDisplayName:(NSString *)appDisplayName {
    [self.store sdl_setObject:appDisplayName forName:SDLRPCParameterNameAppDisplayName];
}

- (NSString *)appDisplayName {
    NSError *error = nil;
    return [self.store sdl_objectForName:SDLRPCParameterNameAppDisplayName ofClass:NSString.class error:&error];
}

- (void)setAppBundleID:(NSString *)appBundleID {
    [self.store sdl_setObject:appBundleID forName:SDLRPCParameterNameAppBundleId];
}

- (NSString *)appBundleID {
    NSError *error = nil;
    return [self.store sdl_objectForName:SDLRPCParameterNameAppBundleId ofClass:NSString.class error:&error];
}

- (void)setAppVersion:(NSString *)appVersion {
    [self.store sdl_setObject:appVersion forName:SDLRPCParameterNameAppVersion];
}

- (NSString *)appVersion {
    NSError *error = nil;
    return [self.store sdl_objectForName:SDLRPCParameterNameAppVersion ofClass:NSString.class error:&error];
}

@end

NS_ASSUME_NONNULL_END