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