locked
Unique Device ID / Mac Address/ Serial Number RRS feed

  • Question

  • User33830 posted

    I have seen some old posts and looked in the apple documentation for unique way to identify this Mac.

    Its seems IOKit is still not bound or am I wrong ?

    Has anyone any nice and easy way to do this ?

    Thursday, October 9, 2014 8:50 AM

Answers

  • User69303 posted

    Thanks, that's a much nicer way of doing things, and of course the serial number is really what I wanted anyway.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, October 10, 2014 8:14 PM

All replies

  • User69303 posted

    I'm using the code snippet from this page to get the UUID:
    http://blog.mrt-web.com/2013/01/get-mac-computers-unique-id-in.html

    Thursday, October 9, 2014 7:15 PM
  • User33830 posted

    woo.. that is quite a work around, thanks for responding Michael.

    @chamons had responded to a bug request asking them to bind IOKit, he was kind enough to put this together for me

    [DllImport ("/System/Library/Frameworks/IOKit.framework/IOKit")]
            static extern uint IOServiceGetMatchingService(uint masterPort, IntPtr matching );
    
            [DllImport ("/System/Library/Frameworks/IOKit.framework/IOKit")]
            static extern IntPtr IOServiceMatching (string s);
    
            [DllImport ("/System/Library/Frameworks/IOKit.framework/IOKit")]
            static extern IntPtr IORegistryEntryCreateCFProperty(uint entry, IntPtr key, IntPtr allocator, uint options);
    
            [DllImport ("/System/Library/Frameworks/IOKit.framework/IOKit")]
            static extern int IOObjectRelease(uint o);
    
            public static string GetSerialNumber ()
            {
                string serial = string.Empty;
                uint platformExpert = IOServiceGetMatchingService (0, IOServiceMatching ("IOPlatformExpertDevice"));
                if (platformExpert != 0) {
                    NSString key = (NSString)"IOPlatformSerialNumber";
                    IntPtr serialNumber = IORegistryEntryCreateCFProperty (platformExpert, key.Handle, IntPtr.Zero, 0);
                    if (serialNumber != IntPtr.Zero) {
                        serial = new NSString (serialNumber);
                    }
                    IOObjectRelease (platformExpert);
                }
    
                return serial;
            }
    
    Friday, October 10, 2014 7:04 AM
  • User69303 posted

    Thanks, that's a much nicer way of doing things, and of course the serial number is really what I wanted anyway.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, October 10, 2014 8:14 PM
  • User80906 posted

    @DavidLilley Isn't IOKit.framework a private Framework? Have you successfully submitted an app to the AppStore using these methods? My initial research shows any app using IOKit will not be approved by Apple.

    Thanks!

    Saturday, February 7, 2015 5:06 PM
  • User33830 posted

    @PeterDedene , I have not come across any thing that described it is a private api and yes My app has been submitted multiple times with out problem. Where did you see that IOKit was a private Api ?

    Wednesday, February 11, 2015 8:42 AM
  • User80906 posted

    @DavidLilley Amongst others:

    http://iphonedevwiki.net/index.php/IOKit.framework => "Apple discourages developers from using it, and any apps using it will be rejected from App Store."

    http://ios-blog.co.uk/tutorials/iokit-an-introduction/ => "WARNING: since this is a private framework, if you submit an app to the App Store that links to this framework, it will be rejected."

    Thanks for your response!

    Tuesday, February 17, 2015 2:39 PM
  • User32778 posted

    @PeterDedene -- IOKit is a private framework in the iOS world, however, it's not a private Framework in the OS X world...

    Wednesday, February 18, 2015 5:09 PM
  • User33830 posted

    @PeterDedene @DanSmith.7748 is right, I suspect IO kit is private in IOS is due to no peripherals can directly connect to it ( No USB or other sockets on an IOS device), so you don't really need it. But thats not the case for OS X.

    http://stackoverflow.com/questions/7015853/will-apple-reject-mac-os-app-which-uses-iokit-framework

    You also need IOKit apparently for validating InAppPurchase Receipts on the Mac

    (Apple Sample Code) https://developer.apple.com/library/mac/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateLocally.html#//apple_ref/doc/uid/TP40010573-CH1-SW2

    Thursday, February 19, 2015 1:31 PM
  • User366569 posted

    I'm using the method described above since the beginning of the year, and the app was successfully submitted. But today it has been rejected:

    Your app uses or references the following non-public APIs:

    _IORegistryEntryFromPath, _IOObjectRelease, _kIOMasterPortDefault, _IORegistryEntryCreateCFProperty

    The use of non-public APIs is not permitted on the App Store, because it can lead to a poor user experience should these APIs change.

    Any ideas?

    Wednesday, September 26, 2018 6:22 AM
  • User33830 posted

    I think apple reviewer has gotten it wrong. It is private for iOS but for MAC OS you need it validating Receipts locally and it is in the sample code for

    https://developer.apple.com/library/archive/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateLocally.html#//apple_ref/doc/uid/TP40010573-CH1-SW2

    See Listing 1-3 Get the computer’s GUID\

    Let me know how you get on as I am using the same method.

    Wednesday, September 26, 2018 7:44 AM