> ## Documentation Index
> Fetch the complete documentation index at: https://help.airbridge.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Data Fetching Guide for iOS

## Airbridge Device ID

Device identifier by Airbridge. (example: 82A16EC9-A273-48B6-9BB2-017EAB641109)

### iOS SDK

<CodeGroup>
  ```swift Swift lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  import Airbridge

  Airbridge.fetchDeviceUUID { deviceUUID in

  }
  ```

  ```objective-c Objective-C lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  #import <Airbridge/Airbridge.h>

  [Airbridge fetchDeviceUUID:^(NSString * _Nonnull deviceUUID) {

  }];
  ```
</CodeGroup>

### iOS SDK (Deprecated)

<CodeGroup>
  ```swift Swift lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  import AirBridge

  AirBridge.deviceUUID
  ```

  ```objective-c Objective-C lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  #import <AirBridge/AirBridge.h>

  AirBridge.deviceUUID;
  ```
</CodeGroup>

## Airbridge Generated ID

Random UUID assigned by Airbridge upon app install on each device. (example: 82A16EC9-A273-48B6-9BB2-017EAB641109)

### iOS SDK

<CodeGroup>
  ```swift Swift lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  import Airbridge

  Airbridge.fetchAirbridgeGeneratedUUID { airbridgeGeneratedUUID in

  }
  ```

  ```objective-c Objective-C lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
      #import <Airbridge/Airbridge.h>

      [Airbridge fetchAirbridgeGeneratedUUID:^(NSString * _Nonnull airbridgeGeneratedUUID) {
          
      }];
  ```
</CodeGroup>

### iOS SDK (Deprecated)

<CodeGroup>
  ```swift Swift lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  import AirBridge

  AirBridge.fetchAirbridgeGeneratedUUID { uuid in

  }
  ```

  ```objective-c Objective-C lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
      #import <AirBridge/AirBridge.h>

      [AirBridge fetchAirbridgeGeneratedUUID:^(NSString * _Nonnull uuid) {
          
      }];
  ```
</CodeGroup>

## ATT (App Tracking Transparency)

As of iOS 14.5, apps must obtain explicit user consent before tracking users. ATT (App Tracking Transparency) is Apple's privacy framework that enables users to control whether apps can track their activity.

<CodeGroup>
  ```swift Swift lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  import AppTrackingTransparency

  let status = ATTrackingManager.trackingAuthorizationStatus

  switch status {
  case .notDetermined:
      // User has not yet made a decision - popup can be shown
  case .authorized:
      // Tracking permission granted
  case .denied:
      // Tracking permission denied
  case .restricted:
      // Tracking is restricted (by device settings)
  @unknown default:
      break
  }
  ```

  ```objective-c Objective-C lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  #import <AppTrackingTransparency/AppTrackingTransparency.h>

  ATTrackingManagerAuthorizationStatus status = [ATTrackingManager trackingAuthorizationStatus];

  switch (status) {
      case ATTrackingManagerAuthorizationStatusNotDetermined:
          // User has not yet made a decision - popup can be shown
          break;
      case ATTrackingManagerAuthorizationStatusAuthorized:
          // Tracking permission granted
          break;
      case ATTrackingManagerAuthorizationStatusDenied:
          // Tracking permission denied
          break;
      case ATTrackingManagerAuthorizationStatusRestricted:
          // Tracking is restricted (by device settings)
          break;
  }
  ```
</CodeGroup>

## IDFA

Advertising ID issued by Apple. (example: 82A16EC9-A273-48B6-9BB2-017EAB641109)

<CodeGroup>
  ```swift Swift lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  import AdSupport

  ASIdentifierManager.shared().advertisingIdentifier.uuidString
  ```

  ```objective-c Objective-C lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  #import <AdSupport/AdSupport.h>

  ASIdentifierManager.sharedManager.advertisingIdentifier.UUIDString;
  ```
</CodeGroup>

## IDFV

Unique ID that publishers can use to identify which apps a specific user has installed. (example: 82A16EC9-A273-48B6-9BB2-017EAB641109)

<CodeGroup>
  ```swift Swift lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  UIDevice.current.identifierForVendor?.uuidString
  ```

  ```objective-c Objective-C lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  UIDevice.currentDevice.identifierForVendor.UUIDString;
  ```
</CodeGroup>

## Limit Ad Tracking

Device's Limit AD Tracking information. (example: true)

<CodeGroup>
  ```swift Swift lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  import AdSupport

  ASIdentifierManager.shared().isAdvertisingTrackingEnabled
  ```

  ```objective-c Objective-C lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  #import <AdSupport/AdSupport.h>

  ASIdentifierManager.sharedManager.advertisingTrackingEnabled;
  ```
</CodeGroup>

## Device Model

Device model name. (example: iPhone)

<CodeGroup>
  ```swift Swift lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  UIDevice.current.localizedModel
  ```

  ```objective-c Objective-C lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  UIDevice.currentDevice.localizedModel;
  ```
</CodeGroup>

## Device Identifier

Device identifier name. (example: iPhone9,3)

<CodeGroup>
  ```swift Swift lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  var systemInfo = utsname()
  uname(&systemInfo)
          
  return String(cString: &systemInfo.machine.0, encoding: .utf8)
  ```

  ```objective-c Objective-C lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  #import <sys/utsname.h>

  struct utsname systemInfo;
  uname(&systemInfo);
          
  return [NSString stringWithCString:systemInfo.machine
                            encoding:NSUTF8StringEncoding];
  ```
</CodeGroup>

## Device Manufacturer

Device manufacturer information. (example: Apple)

<CodeGroup>
  ```swift Swift lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  "Apple"
  ```

  ```objective-c Objective-C lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  @"Apple"
  ```
</CodeGroup>

## OS Name

Device OS name. (example: iOS)

<CodeGroup>
  ```swift Swift lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  UIDevice.current.systemName
  ```

  ```objective-c Objective-C lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  UIDevice.currentDevice.systemName;
  ```
</CodeGroup>

## OS Version

Device OS version. (example: 13.3)

<CodeGroup>
  ```swift Swift lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  UIDevice.current.systemVersion
  ```

  ```objective-c Objective-C lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  UIDevice.currentDevice.systemVersion;
  ```
</CodeGroup>

## Locale

Device locale settings. (example: ko-KR)

<CodeGroup>
  ```swift Swift lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  func getSystemLocale() -> String? {
      guard let language = getSystemLanguage() else { return nil }
      guard let country = getSystemCountry() else { return nil }
      
      return "\(language)-\(country)"
  }

  func getSystemLanguage() -> String? {
      let languages = Locale.preferredLanguages
      
      if languages.count < 1 {
          return nil
      }
      
      let languageSource = languages[0]
      
      guard let barIndex = languageSource.range(of: "-") else {
          return languageSource
      }
      
      return String(languageSource[..<barIndex.lowerBound])
  }

  func getSystemCountry() -> String? {
      return Locale.autoupdatingCurrent.regionCode
  }
  ```

  ```objective-c Objective-C lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  + (NSString *)getSystemLocale {
      NSString* language = [#ClassName# getSystemLanguage];
      NSString* country = [#ClassName# getSystemCountry];
      if(language == nil || country == nil) {
          return nil;
      }
      return [NSString stringWithFormat:@"%@-%@", language, country];
  }

  + (NSString*) getSystemLanguage {
      NSArray* preferredLanguages = NSLocale.preferredLanguages;
      if (preferredLanguages.count < 1) {
          return nil;
      }
      NSString* languageSource = preferredLanguages[0];
      if (languageSource == nil) {
          return nil;
      }
      NSRange barIndex = [languageSource rangeOfString:@"-"];
      if (barIndex.location != NSNotFound) {
          languageSource = [languageSource substringToIndex:barIndex.location];
      }
      return languageSource;
  }

  + (NSString*) getSystemCountry {
      NSLocale* locale = NSLocale.autoupdatingCurrentLocale;
      if (locale == nil) {
          return nil;
      }
      return [locale objectForKey:NSLocaleCountryCode];
  }
  ```
</CodeGroup>

## Timezone

Device timezone settings. (example: US/Pacific)

<CodeGroup>
  ```swift Swift lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  TimeZone.current.description
  ```

  ```objective-c Objective-C lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  NSTimeZone.systemTimeZone.name;
  ```
</CodeGroup>

## Orientation

Device display orientation. Values will be either "portrait" or "landscape". (example: portrait)

<CodeGroup>
  ```swift Swift lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  if UIDevice.current.orientation.isLandscape {
      return @"landscape"
  } else {
      return @"portrait"
  }
  ```

  ```objective-c Objective-C lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
  if (UIInterfaceOrientationIsLandscape(orientation))
      return @"landscape";
  else
      return @"portrait";
  ```
</CodeGroup>

## Screen Density

Device's screen density. (example: 3.000)

<CodeGroup>
  ```swift Swift lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  String(format: "%.3f", UIScreen.main.scale)
  ```

  ```objective-c Objective-C lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  [NSString stringWithFormat:@"%.3f", UIScreen.mainScreen.scale];
  ```
</CodeGroup>

## Screen Width

Device's actual width. (example: 375.0)

<CodeGroup>
  ```swift Swift lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  String(format: "%.f", UIScreen.main.bounds.size.width)
  ```

  ```objective-c Objective-C lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  [NSString stringWithFormat:@"%.f", UIScreen.mainScreen.bounds.size.width];
  ```
</CodeGroup>

## Screen Height

Device's actual height. (example: 667.0)

<CodeGroup>
  ```swift Swift lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  String(format: "%.f", UIScreen.main.bounds.size.height)
  ```

  ```objective-c Objective-C lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  [NSString stringWithFormat:@"%.f", UIScreen.mainScreen.bounds.size.height];
  ```
</CodeGroup>

## Network Carrier

Device network carrier information.

<CodeGroup>
  ```swift Swift lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  import CoreTelephony

  let info = CTTelephonyNetworkInfo()

  if #available(iOS 12.1, *) {
      let providers = info.serviceSubscriberCellularProviders
      return providers?.values.first?.carrierName
  } else {
      let provider = info.subscriberCellularProvider
      return provider?.carrierName
  }
  ```

  ```objective-c Objective-C lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  #import <CoreTelephony/CTCarrier.h>
  #import <CoreTelephony/CTTelephonyNetworkInfo.h>

  CTTelephonyNetworkInfo* networkInfo = [[CTTelephonyNetworkInfo alloc] init];

  if (@available(iOS 12.1, *)) {
      NSDictionary<NSString*, CTCarrier*>* providers = [networkInfo serviceSubscriberCellularProviders];
      return providers.allValues.firstObject.carrierName;
  } else {
      CTCarrier* provider = [networkInfo subscriberCellularProvider];
      return provider.carrierName;
  }
  ```
</CodeGroup>

## Cellular Status

Device mobile data status. (example: true)

<CodeGroup>
  ```swift Swift lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  import SystemConfiguration

  func isCellular() -> Bool {
      return network() == .cellular
  }

  enum Network {
      case wifi
      case cellular
      case none
  }

  func getNetworkInfo() -> Network {
      var zeroAddress = sockaddr()
      bzero(&zeroAddress, MemoryLayout.size(ofValue: zeroAddress))
      zeroAddress.sa_len = __uint8_t(MemoryLayout.size(ofValue: zeroAddress))
      zeroAddress.sa_family = sa_family_t(AF_INET)

      guard let reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, &zeroAddress) else {
          return .none
      }

      var flags = SCNetworkReachabilityFlags()
      if !SCNetworkReachabilityGetFlags(reachability, &flags) {
          return .none
      }

      if !flags.contains(.reachable) {
          return .none
      }

      if flags.contains(.connectionRequired)
          && !((flags.contains(.connectionOnDemand) || flags.contains(.connectionOnTraffic))
              && !flags.contains(.interventionRequired)) {
          return .none
      }
      
      if flags.contains(.isWWAN) {
          return .cellular
      } else {
          return .wifi
      }
  }
  ```

  ```objective-c Objective-C lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  #import <SystemConfiguration/SystemConfiguration.h>
  #import <netinet/in.h>

  + (BOOL) isCellular {
      return [#ClassName# getNetworkInfo] == CELLULAR;
  }

  typedef enum : NSInteger {
      WIFI,
      CELLULAR,
      NONE
  } ABNetwork;

  + (ABNetwork) getNetworkInfo {
      struct sockaddr_in zeroAddress;
      bzero(&zeroAddress, sizeof(zeroAddress));
      zeroAddress.sin_len = sizeof(zeroAddress);
      zeroAddress.sin_family = AF_INET;
      SCNetworkReachabilityRef reachability
          = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr *) &zeroAddress);
      if (reachability == nil) {
          return NONE;
      }
      SCNetworkReachabilityFlags flags;
      if (!SCNetworkReachabilityGetFlags(reachability, &flags)) {
          return NONE;
      }
      if ((flags & kSCNetworkReachabilityFlagsReachable) == 0) {
          return NONE;
      }
      if (((flags & kSCNetworkReachabilityFlagsConnectionRequired) != 0)
          && !(((flags & kSCNetworkReachabilityFlagsConnectionOnDemand ) != 0 || (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0)
               && (flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0))
      {
          return NONE;
      }
      if ((flags & kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN) {
          return CELLULAR;
      } else {
          return WIFI;
      }
  }
  ```
</CodeGroup>

## WiFi Status

Device wifi status. (example: true)

<CodeGroup>
  ```swift Swift lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  import SystemConfiguration

  func isWifi() -> Bool {
      return network() == .wifi
  }

  enum Network {
      case wifi
      case cellular
      case none
  }

  func getNetworkInfo() -> Network {
      var zeroAddress = sockaddr()
      bzero(&zeroAddress, MemoryLayout.size(ofValue: zeroAddress))
      zeroAddress.sa_len = __uint8_t(MemoryLayout.size(ofValue: zeroAddress))
      zeroAddress.sa_family = sa_family_t(AF_INET)

      guard let reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, &zeroAddress) else {
          return .none
      }

      var flags = SCNetworkReachabilityFlags()
      if !SCNetworkReachabilityGetFlags(reachability, &flags) {
          return .none
      }

      if !flags.contains(.reachable) {
          return .none
      }

      if flags.contains(.connectionRequired)
          && !((flags.contains(.connectionOnDemand) || flags.contains(.connectionOnTraffic))
              && !flags.contains(.interventionRequired)) {
          return .none
      }
      
      if flags.contains(.isWWAN) {
          return .cellular
      } else {
          return .wifi
      }
  }
  ```

  ```objective-c Objective-C lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  #import <SystemConfiguration/SystemConfiguration.h>
  #import <netinet/in.h>

  + (BOOL) isWifi {
      return [#ClassName# getNetworkInfo] == WIFI;
  }

  typedef enum : NSInteger {
      WIFI,
      CELLULAR,
      NONE
  } ABNetwork;

  + (ABNetwork) getNetworkInfo {
      struct sockaddr_in zeroAddress;
      bzero(&zeroAddress, sizeof(zeroAddress));
      zeroAddress.sin_len = sizeof(zeroAddress);
      zeroAddress.sin_family = AF_INET;
      SCNetworkReachabilityRef reachability
          = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr *) &zeroAddress);
      if (reachability == nil) {
          return NONE;
      }
      SCNetworkReachabilityFlags flags;
      if (!SCNetworkReachabilityGetFlags(reachability, &flags)) {
          return NONE;
      }
      if ((flags & kSCNetworkReachabilityFlagsReachable) == 0) {
          return NONE;
      }
      if (((flags & kSCNetworkReachabilityFlagsConnectionRequired) != 0)
          && !(((flags & kSCNetworkReachabilityFlagsConnectionOnDemand ) != 0 || (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0)
               && (flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0))
      {
          return NONE;
      }
      if ((flags & kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN) {
          return CELLULAR;
      } else {
          return WIFI;
      }
  }
  ```
</CodeGroup>

## Package Name

Application package name. (example: co.ab180.ablog)

<CodeGroup>
  ```swift Swift lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  Bundle.main.bundleIdentifier
  ```

  ```objective-c Objective-C lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  NSBundle.mainBundle.bundleIdentifier;
  ```
</CodeGroup>

## Version

Application version name. (example: 1.0.0)

<CodeGroup>
  ```swift Swift lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  Bundle.main.infoDictionary?["CFBundleShortVersionString"]
  ```

  ```objective-c Objective-C lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  [NSBundle.mainBundle.infoDictionary objectForKey:@"CFBundleShortVersionString"];
  ```
</CodeGroup>

## Event Timestamp

Timestamp(milliseconds) of when the event was sent. (example: 1581043739682)

<CodeGroup>
  ```swift Swift lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  UInt64(Date().timeIntervalSince1970 * 1000)
  ```

  ```objective-c Objective-C lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  [NSNumber numberWithUnsignedLongLong:NSDate.date.timeIntervalSince1970 * 1000];
  ```
</CodeGroup>

<link rel="alternate" hrefLang="en" href="https://help.airbridge.io/en/developers/fetching-guide-for-ios-sdk" />

<link rel="alternate" hrefLang="ko" href="https://help.airbridge.io/ko/developers/fetching-guide-for-ios-sdk" />
