Skip to content

Commit

Permalink
Make platformUUID only available on macos
Browse files Browse the repository at this point in the history
  • Loading branch information
thecatalinstan committed Jun 17, 2021
1 parent 20d6931 commit 3d9127a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ FOUNDATION_EXPORT CSSystemInfoKey const CSSystemInfoKeyMachine;
/// @name UUID of the current device

/// Get the UUID of the current device
@property (nonatomic, readonly, strong) NSString * platformUUID;
@property (nonatomic, readonly, strong) NSString * platformUUID API_UNAVAILABLE(ios, tvos, watchos);

@end

Expand Down
22 changes: 5 additions & 17 deletions CSSystemInfoHelper/Sources/CSSystemInfoHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,11 @@

#import <CSSystemInfoHelper/CSSystemInfoHelper.h>

#import <stdio.h>
#import <ifaddrs.h>
#import <arpa/inet.h>
#import <sys/utsname.h>
#import <ifaddrs.h>
#import <mach/mach.h>

#if TARGET_OS_WATCH
#import <WatchKit/WatchKit.h>
#elif TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
#endif
//#import <stdio.h>
#import <sys/utsname.h>

NSString * const CSSystemInfoKeySysname = @"CSSystemInfoSysname";
NSString * const CSSystemInfoKeyNodename = @"CSSystemInfoNodename";
Expand Down Expand Up @@ -130,23 +124,17 @@ - (NSString *)memoryUsageString {
return [NSByteCountFormatter stringFromByteCount:self.memoryUsage countStyle:NSByteCountFormatterCountStyleMemory];
}

#if TARGET_OS_OSX
- (NSString *)platformUUID {
static NSString* platformUUID;
if (!platformUUID) {

#if TARGET_OS_WATCH
#warning platformUUID is generated on-the-fly for watchOS
platformUUID = [NSUUID UUID].UUIDString;
#elif TARGET_OS_IPHONE
platformUUID = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
#else
io_registry_entry_t ioRegistryRoot = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/");
CFStringRef uuidCf = (CFStringRef) IORegistryEntryCreateCFProperty(ioRegistryRoot, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0);
IOObjectRelease(ioRegistryRoot);
platformUUID = CFBridgingRelease(uuidCf);
#endif
}
return platformUUID;
}
#endif

@end
2 changes: 2 additions & 0 deletions CSSystemInfoHelperTests/CSSystemInfoHelperTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ - (void)test_MemoryUsageString_ShouldNotBeEmpty {
XCTAssertGreaterThan(helper.memoryUsageString.length, 0);
}

#if TARGET_OS_OSX
- (void)test_PlatformUUID_DoesNotThrow {
CSSystemInfoHelper *helper = [CSSystemInfoHelper new];
XCTAssertNoThrow(helper.platformUUID);
Expand All @@ -139,5 +140,6 @@ - (void)test_PlatformUUID_ShouldNotBeEmpty {
CSSystemInfoHelper *helper = [CSSystemInfoHelper new];
XCTAssertGreaterThan(helper.platformUUID.length, 0);
}
#endif

@end

0 comments on commit 3d9127a

Please sign in to comment.