Created
August 11, 2013 16:41
-
-
Save TomLiu/6205610 to your computer and use it in GitHub Desktop.
Get Mac Disk Info
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// AppDelegate.m | |
// demo | |
// | |
// Created by 61 on 13-8-11. | |
// Copyright (c) 2013年 61. All rights reserved. | |
// | |
#import "AppDelegate.h" | |
#import <IOKit/IOKitLib.h> | |
@implementation AppDelegate | |
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification | |
{ | |
NSLog(@"%@", [self getDiskSerialNumber]); | |
} | |
- (NSString *)getDiskSerialNumber | |
{ | |
kern_return_t kr; | |
io_iterator_t io_objects; | |
io_service_t io_service; | |
NSString *serialNumber = nil; | |
CFMutableDictionaryRef service_properties = CFDictionaryCreateMutable(NULL, 0, NULL,NULL); | |
kr = IOServiceGetMatchingServices(kIOMasterPortDefault, IOServiceNameMatching("AppleAHCIDiskDriver"), &io_objects); | |
if(kr != KERN_SUCCESS) | |
return nil; | |
while((io_service = IOIteratorNext(io_objects))) { | |
kr = IORegistryEntryCreateCFProperties(io_service, &service_properties, kCFAllocatorDefault, kNilOptions); | |
if(kr == KERN_SUCCESS) { | |
NSDictionary * serviceInfo = (__bridge NSDictionary *)service_properties; | |
NSLog(@"%@", serviceInfo); | |
serialNumber = [serviceInfo objectForKey:@"Serial Number"]; | |
CFRelease(service_properties); | |
} | |
IOObjectRelease(io_service); | |
} | |
IOObjectRelease(io_objects); | |
return serialNumber; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment