[Tutorial] Import IOKit framework into Xcode project
While you’re developing iOS project on Xcode, you may need IOKit framework for some reason, such as get UDID of iDevice …etc, or using on Yalu’s project…
So, in this article, I tried to write down how I import IOKit framework into a Xcode project.
Things you need are:
- Xcode 8 (This sample was builded on Xcode version 8 in macOS 10.12)
- iOS SDK (It should be installed with your Xcode)
- Trident – IOKit header files
Import Error
When you try to use IOKit, for instance:
#import <IOKit/IOKitLib.h>
Step 1:Import IOKit Framework
Different from IOKit as a libraries on iOS 5, Apple change IOKit from library into framework on iOS 7.
So first of all, we need to import the IOKit framework in Xcode.app into our project
if you try to type in your terminal
$ find /Applications/Xcode.app/ -name IOKit.framework
you will find 5 different IOKit framework of 5 different platforms in Xcode.app
We need “iPhoneOS.platform” recently, the path is:
0 1 2 |
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/IOKit.framework |
Then go to application Target → General in Xcode project tab, and find “Link Frameworks and Libraries“.
Press the add button on the bottom left and use “Add Other” button to find the framework in the specific path.
Find the IOKit.framework on the path I mentioned above and add it, after you finish it, it will show up in the area of “Link Frameworks and Libraries”
Also remember check if the IOKit.framework also shows up at the area of “Link Binary with Libraries” at application Target → Build Phases in Xcode project tab
Step 2:Add header files of IOKit
I read some article on internet said that header files of IOKit framework will be at
0 1 2 |
Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks/IOKit.framework/Headers |
but I couldn’t find any header files in the path, so I tried another way.
I use the header files in Trident and add it to my project.
First, download it form GitHub, what we need is a folder in it Trident-master/Headers/IOKit
called IOKit
Copy the IOKit folder to $(SRCROOT) – the path to the directory containing your Xcode project
Then link the folder to your project, drag the folder to the project’s “Groups & Files” area
Step 3:Make Xcode find header files you added
Go to application Target → Build Setting in Xcode project tab, and search “
and add $(SRCROOT)
into the item, remember change the option to “recursive”
Then it done.
Remember to clean your project (CMD+SHIFT+K) and build it again
Thanks! This is very helpful.
Thanks.
thaaaanks! you saved me tons of time
Is possible to share this app install with out computer
Not really got what you mean
I have done all your steps but XCode keeps telling me “No such module named ‘IOKit'” when I try to write “import IOKit”