HiJack In the Box – Part 2 – iPhone HiJack Tutorial
August 21, 2011
This would be a lengthy post and if you would have questions, you an post a comment below.
Now we’ve seen that we can easily integrate an analog sensor (resistive type) on our Part 1, this time our goal will be to make the default OpenGL ES iPhone project template, which is a colored bouncing box, to be controlled with the HiJack device. But on this part, we will first setup our solution, because linking with HiJack is a bit tricky!
First, we can get the source code from the HiJack source tree. There are resources online on how to use SVN, but this will be the least of our worries on this demo.

(yeah I pasted their webpage, but anyway…)
When you’re done with getting the code through SVN, you can see that there is a LibHiJack directory present under the iPhone directory. This is the code that we are to use to reference on our project:

Let us start creating a new iOS project, an OpenGL ES Application:

(you can try to run it and you will see a bouncing grandien-ty box)
When the project is created, we will import the LibHiJack’s files to our project. I tried to reference the LibHiJack’s output which is a static library (“.a”) and the HiJackMgr.h header file, but it will be a bit redundant because we will still need to reference the other header files (“.h”). I thought of using the entire code from the other project instead.
Create a new group named “Lib”:

From the LibHiJack project, drag all of the source files (as seen below) except the .pch (precompiled header) to our new project, under the Lib group. Be sure also to mark the files as “Copy” so we will not ruin the original files:

After this, I know you are itching to build the project, so let us build it! But sadly there will be some nasty errors again:

With this, I made a quick comparison with the LibHijack project, and the aurioTouch Oscilloscope project included along when you get the files (which build nicely). Go to the project file and go to the Build Settings tab button. Also while at it, select the “Levels” view so we can see what the default Xcode settings are and what we will be putting:

The first setting we will change (as what I have seen with the other projects) is the “Compile for Thumb”. Let us change it to “No”:

Then the “Optimization Level” on the Debug setting, change it to “Fastest [-O3]“:

Symbols Hidden by Default = “Yes”

Language Dialect = “C99 [-std=c99]“

Clear “Other C Flags”

Clear “Preprocessor Macros”

Then this is the required part, we would have to add a User-defined value. This can be done by expanding the “Add Build Setting” context menu and selecting “Add User Defined Setting”. Indicate the value as shown below:

Ok then now, I think it should work! Let us try to build it:

But ohno! It seems that it looks for a framework, so I looked at the aurioTouch Oscilloscope code and checked what framework is needed. We would need to add AudioToolbox.framework. To do this, click again the project and use the “Build Phases” tab button to see the “Link Binary with Libraries” section. This is where we would add the framework:

Using the “+” sign, a selection window will show up and then look for AudioToolbox.framework. Select it and use the “Add” button to add it to the list:

Then we can now build the app again!

Whew!
So let us now use the “HiJackMgr.h” header and put it on any implementation (“.m”) file and try to build it. Let us try putting it on HiJackInTheBoxAppDelegate.mm:
![]()
But…

Ohno not again!! Those cryptic errors!
But don’t worry its not our fault. Upon searching around a number of resources, it turns out to be that the code is not compiling C++ code, which our darling LibHiJack was built upon. To resolve this, we would have to rename the HiJackInTheBoxAppDelegate.m to HiJackInTheBoxAppDelegate.mm:

Then build it again:

Cool! now it works!
So now we are done with setting up the project! This post is getting long so I will write out the next part, the actual HiJack code on Part 3.
(trust me, I had taken an entire day and dumped a lot of solutions to the trash to come up with this setup that worked)
;
Have you tried this solution with Xcode4.2 and iOS5.0?
I followed you instructions and changed the default compiler vim LLVM back to GCC but I got the following errors now. A lot of them:
/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSString.h:12: error: stray ‘@’ in program
Cheers,
Michael.
Hello Michael, that I haven’t tried yet as I have only compiled it up to iOS 4.3. I’ll try it and keep you posted (I have not yet downloaded the new Xcode too hehe)
I just got this to work with Xcode4.3.2 using the iOS SDK 5.1. Most of the instructions above worked except I kept getting these ARC errors:
Cast of C pointer type ‘void *’ to Objective-C pointer type ‘HiJackMgr *’ requires a bridged cast
‘NSAutoreleasePool’ is unavailable: not available in automatic reference counting mode
ARC forbids explicit message send of ‘release’
To fix I changed:
Project->Build Settings->CompilerLanguage->Objective-C Automatic Reference Control = YES
Target->Build Settings->CompilerLanguage->Objective-C Automatic Reference Control = YES
With that I was able to successfully build.
Great job! Thanks for sharing this