Solution to Get the MAC Address of iPhone or Macintosh OS X
This article is all about how can we get mac address of Macintosh via coding. So, before I proceed I would like to inform you that I can only be (as far as I know) by C code. This code works for both iPhone or Mac. This article will provide you step by step guidance from the beginning to the end. Also, you will get the github project as a bounce
I am writing this article because I had wasted so much time in order to find a solution and I do not want my fellow developers to do so.
Note: Mac address is basically use for identifying the device. Mac address ought to unique to the desvice.
Starting the mission:
Open Xcode and select Cocoa Application>>Next
Name your project e.g. “MacAddressLesson”
Choose a location to save your project
your project now look like this
Now we will need to add 2 files in our project.
Download Link is given at the bottom of this project
IpMacAddressHelper.m will have the code part and MacAddressHelper.h will contain the declaration part, I not go too deep in it and I presume that you know what are .h and .c file means.
Now lets add these files
browse the location of the files and add them
Now you will be able to see the files in the Project solution explorer
Now we will use the function provided in the MacAddressHelper.h file whose definition is written in the MacAddressHelper.m file.
- Open AppDelegate.m
- Add MacAddressHelper.h in header imports. #import “MacAddressHelper.h”
- Add awakeFromNib method in the file and then call the [MacAddressHelper address]; that will return the NSString
- do not forget to add a break point in the end of the method to check the macAddress
- Hit Command+R to run the application
So here is your Mac address that you can use in your application to identify the device. For any question, please feel free to ask and you may comment your questions below. Your suggestions and feedbacks are also welcome.