1212#import " BNCLog.h"
1313#import " BNCConfig.h"
1414#import " BNCNetworkInterface.h"
15- #import " BNCUserAgentCollector.h"
16- #import " BNCTelephony.h"
1715#import " BNCReachability.h"
1816#import " BNCLocale.h"
1917#import " NSMutableDictionary+Branch.h"
2018#import " BNCDeviceSystem.h"
2119
20+ #if !TARGET_OS_TV
21+ // tvOS does not support webkit or telephony
22+ #import " BNCTelephony.h"
23+ #import " BNCUserAgentCollector.h"
24+ #endif
25+
2226#if __has_feature(modules)
2327@import UIKit;
2428#else
@@ -60,31 +64,34 @@ - (void)registerPluginName:(NSString *)name version:(NSString *)version {
6064}
6165
6266- (void )loadDeviceInfo {
63-
67+
6468 BNCLocale *locale = [BNCLocale new ];
65- BNCTelephony *telephony = [BNCTelephony new ];
6669 BNCDeviceSystem *deviceSystem = [BNCDeviceSystem new ];
67-
70+
6871 // The random id is regenerated per app launch. This maintains existing behavior.
6972 self.randomId = [[NSUUID UUID ] UUIDString ];
7073 self.vendorId = [BNCSystemObserver getVendorId ];
7174 [self checkAdvertisingIdentifier ];
72-
75+
7376 self.brandName = [BNCSystemObserver getBrand ];
7477 self.modelName = [BNCSystemObserver getModel ];
7578 self.osName = [BNCSystemObserver getOS ];
7679 self.osVersion = [BNCSystemObserver getOSVersion ];
7780 self.osBuildVersion = deviceSystem.systemBuildVersion ;
78-
81+
7982 if (deviceSystem.cpuType ) {
8083 self.cpuType = [deviceSystem.cpuType stringValue ];
8184 }
82-
85+
8386 self.screenWidth = [BNCSystemObserver getScreenWidth ];
8487 self.screenHeight = [BNCSystemObserver getScreenHeight ];
8588 self.screenScale = @([UIScreen mainScreen ].scale );
89+
90+ #if !TARGET_OS_TV
91+ BNCTelephony *telephony = [BNCTelephony new ];
8692 self.carrierName = telephony.carrierName ;
87-
93+ #endif
94+
8895 self.locale = [NSLocale currentLocale ].localeIdentifier ;
8996 self.country = [locale country ];
9097 self.language = [locale language ];
@@ -114,25 +121,30 @@ - (NSString *)connectionType {
114121}
115122
116123- (NSString *)userAgentString {
124+ #if !TARGET_OS_TV
117125 return [BNCUserAgentCollector instance ].userAgent ;
126+ #else
127+ // tvOS has no web browser or webview
128+ return @" " ;
129+ #endif
118130}
119131
120132// IDFA should never be cached
121133- (void )checkAdvertisingIdentifier {
122134 self.isAdTrackingEnabled = [BNCSystemObserver adTrackingSafe ];
123135 self.advertiserId = [BNCSystemObserver getAdId ];
124136 BOOL ignoreIdfa = [BNCPreferenceHelper preferenceHelper ].isDebug ;
125-
137+
126138 if (self.advertiserId && !ignoreIdfa) {
127139 self.hardwareId = self.advertiserId ;
128140 self.hardwareIdType = @" idfa" ;
129141 self.isRealHardwareId = YES ;
130-
142+
131143 } else if (self.vendorId ) {
132144 self.hardwareId = self.vendorId ;
133145 self.hardwareIdType = @" vendor_id" ;
134146 self.isRealHardwareId = YES ;
135-
147+
136148 } else {
137149 self.hardwareId = self.randomId ;
138150 self.hardwareIdType = @" random" ;
@@ -144,24 +156,24 @@ - (NSDictionary *)v2dictionary {
144156 NSMutableDictionary *dictionary = [NSMutableDictionary new ];
145157 @synchronized (self) {
146158 [self checkAdvertisingIdentifier ];
147-
159+
148160 BOOL disableAdNetworkCallouts = [BNCPreferenceHelper preferenceHelper ].disableAdNetworkCallouts ;
149161 if (disableAdNetworkCallouts) {
150162 dictionary[@" disable_ad_network_callouts" ] = [NSNumber numberWithBool: disableAdNetworkCallouts];
151163 }
152-
164+
153165 if ([BNCPreferenceHelper preferenceHelper ].isDebug ) {
154166 dictionary[@" unidentified_device" ] = @(YES );
155167 } else {
156168 [dictionary bnc_safeSetObject: self .vendorId forKey: @" idfv" ];
157169 [dictionary bnc_safeSetObject: self .advertiserId forKey: @" idfa" ];
158170 }
159171 [dictionary bnc_safeSetObject: [self localIPAddress ] forKey: @" local_ip" ];
160-
172+
161173 if (!self.isAdTrackingEnabled ) {
162174 dictionary[@" limit_ad_tracking" ] = @(YES );
163175 }
164-
176+
165177 if ([BNCPreferenceHelper preferenceHelper ].limitFacebookTracking ) {
166178 dictionary[@" limit_facebook_tracking" ] = @(YES );
167179 }
@@ -184,9 +196,9 @@ - (NSDictionary *)v2dictionary {
184196
185197 [dictionary bnc_safeSetObject: [BNCPreferenceHelper preferenceHelper ].userIdentity forKey: @" developer_identity" ];
186198 [dictionary bnc_safeSetObject: [BNCPreferenceHelper preferenceHelper ].deviceFingerprintID forKey: @" device_fingerprint_id" ];
187-
199+
188200 [dictionary bnc_safeSetObject: self .applicationVersion forKey: @" app_version" ];
189-
201+
190202 [dictionary bnc_safeSetObject: self .pluginName forKey: @" plugin_name" ];
191203 [dictionary bnc_safeSetObject: self .pluginVersion forKey: @" plugin_version" ];
192204 dictionary[@" sdk_version" ] = BNC_SDK_VERSION;
0 commit comments