vendor_identifier.m 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. vendor_identifier.m
  3. TrustKit
  4. Copyright 2016 The TrustKit Project Authors
  5. Licensed under the MIT license, see associated LICENSE file for terms.
  6. See AUTHORS file for the list of project authors.
  7. */
  8. #import "vendor_identifier.h"
  9. #if TARGET_OS_IPHONE && !TARGET_OS_WATCH
  10. #pragma mark Vendor identifier - iOS, tvOS
  11. // for accessing the IDFV
  12. #if __has_feature(modules)
  13. @import UIKit;
  14. #else
  15. #import <UIKit/UIKit.h>
  16. #endif
  17. NSString *identifier_for_vendor(void)
  18. {
  19. return UIDevice.currentDevice.identifierForVendor.UUIDString;
  20. }
  21. #else
  22. #pragma mark Vendor identifier - macOS, watchOS
  23. static NSString * const kTSKVendorIdentifierKey = @"TSKVendorIdentifier";
  24. NSString *identifier_for_vendor(void)
  25. {
  26. // Try to retrieve the vendor ID from the preferences
  27. NSUserDefaults *preferences = NSUserDefaults.standardUserDefaults;
  28. NSString *vendorId = [preferences stringForKey:kTSKVendorIdentifierKey];
  29. if (vendorId == nil)
  30. {
  31. // Generate and store a new UUID
  32. vendorId = NSUUID.UUID.UUIDString;
  33. [preferences setObject:vendorId forKey:kTSKVendorIdentifierKey];
  34. [preferences synchronize];
  35. }
  36. return vendorId;
  37. }
  38. #endif