1// Copyright 2015-present 650 Industries. All rights reserved.
2
3#import "EXConstantsBinding.h"
4#import "EXUnversioned.h"
5
6@interface EXConstantsBinding ()
7
8@property (nonatomic, strong) NSDictionary *unversionedConstants;
9
10@end
11
12@implementation EXConstantsBinding : EXConstantsService
13
14@synthesize appOwnership = _appOwnership;
15
16- (instancetype)initWithExperienceId:(NSString *)experienceId andParams:(NSDictionary *)params
17{
18  if (self = [super initWithExperienceId:experienceId]) {
19    _unversionedConstants = params[@"constants"];
20    if (_unversionedConstants && _unversionedConstants[@"appOwnership"]) {
21      _appOwnership = _unversionedConstants[@"appOwnership"];
22    }
23  }
24  return self;
25}
26
27- (NSDictionary *)constants
28{
29  NSMutableDictionary *constants = [[super constants] mutableCopy];
30
31  [constants setValue:[self expoClientVersion] forKey:@"expoVersion"];
32
33  BOOL isDetached = NO;
34#ifdef EX_DETACHED
35  isDetached = YES;
36#endif
37
38  constants[@"isDetached"] = @(isDetached);
39
40  if (_unversionedConstants) {
41    [constants addEntriesFromDictionary:_unversionedConstants];
42  }
43  return constants;
44}
45
46- (NSString *)expoClientVersion
47{
48  NSString *expoClientVersion = _unversionedConstants[EX_UNVERSIONED(@"expoRuntimeVersion")];
49  if (expoClientVersion) {
50    return expoClientVersion;
51  } else {
52    // not correct in standalone apps
53    return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
54  }
55}
56
57@end
58