The Blog

Objective-C: Getting App Version Programmatically!

Getting the current App version programmatically can be useful in a lot of contexts, for eg. to show it on an “About” window.

Is easy to get your App version in Objective-C:

NSString* AppVer = [[[NSBundle mainBundle] infoDictionary] objectForKey:@”CFBundleVersion”];

Objective-C: Quickly Iterate Over an NSArray

Ever wondered how could you quickly iterate over an NSArray?

In OSX 10.5+ or iOS it’s easy as:

for (id currentArrayElement in myArray) {
       //…do something useful with currentArrayElement
       NSLog(@”%@”, currentArrayElement); // Print all elements in NSArray
}

If you’re coding for OSX 10.4 and previous you should do this instead:

int i;
for (i = 0; i < [myArray count]; i++) {
       id currentArrayElement = [myArray objectAtIndex:i];
       //…do something useful with currentArrayElement
       NSLog(@”%@”, currentArrayElement); // Print all elements in NSArray
}

Enjoy!

STKeys Update: 4.1.1!

STKeys the popular Thomson key recovery App for Mac has been updated!

This update issue the following new features/bug fixes: (4.1.1 – Master Localized)

  • Final version of the Portuguese localization
  • Experimental Greek localization
  • Active Mode: Wireless networks list UI overlap corrected

Update your STKeys now, to get the latest features.

If you don’t already have STKeys, check it out here: STKeys 4

C/C++: Compiling on iOS

C language is great because it’s one of the most used today and has compilers widely available for most architectures. The propose of this post is to explain how to compile your own C/C++ projects under the new iOS versions like 3, 4 and 5.x.

Nowadays, compiling C/C++ for iPhone, isn’t to easy like before, there are three major problems:

- No LibGCC available on Cydia. The famous GCC Compiler has been ported to the iPhone (you can found it as GNU C Compiler on Cydia). GCC depends on LibGCC  witch is no longer available on Cydia (since iOS 2.0) so it’s impossible to install CGG.

- The C Standard Library is not completely installed on iOS.

- Apple Code Sign. Saurik (Cydia developer) has already explain that…

“Starting with the recent beta releases of the iPhoneOS, Apple has started requiring that all code on the device is signed. This is mostly to make it impossible for programs running through Apple’s AppStore to download more software and run it (so no competition for AppStore).”

Fortunately right now an compatible with iOS 5 there’s an open source project that aims to port GCC and it’s dependencies to the iPhone. The project is called iPhone-GCC-Full.

To start you’ll need to get some components:

  • CSU – Go to Cydia and search and install csu.
  • Link Identify Editor (aka ldid) – Go to Cydia and search and install ldid.
  • LibGCC: http://code.google.com/p/iphone-gcc-full/downloads/detail?name=libgcc.deb
  • GCC: http://code.google.com/p/iphone-gcc-full/downloads/detail?name=iphone-gcc.deb
  • Headers/Libraries: http://code.google.com/p/iphone-gcc-full/downloads/detail?name=headers-libs.deb

After downloading those components, launch Cyberduck or your favorite SFTP software and upload the files into /private/var/root on your iPhone.

Now, connect to your iPhone via SSH using Terminal in your Mac and install the downloaded packages:

your-mac:~ you$  ssh root@your-iphone.local

root@your-iphone.local’s password: : …   // The default password is “alpine”

your-iphone:~ you$ dpkg -install libgcc.deb

your-iphone:~ you$  dpkg -install iphone-gcc.deb

your-iphone:~ you$  dpkg -install headers-libs.deb

Now you can compile your applications like you do in your computer, by issuing for e.g. “cpp -o helloworld helloworld.c”.

After compiling if you try to run your app iPhone just says “Killed” when you launch it! This is Code Sign working… In order to solve this issue it’s necessary to sign the application. There are 3 options to sign apps or make it run but, the best option is called Pseudo-Signing:

“To get around this, I wrote a tool called ldid that, among other things, can generate the SHA1 hashes that are checked by Apple’s iPhoneOS kernel” - (The other signing options are here: http://www.saurik.com/id/8)

Issue the following on your iPhone Terminal:

your-iphone:~ you$ ldid -S helloworld

Now if you try to run your app it will work!! Enjoy the freedom of having your small or huge utilities running in your pocket anytime you need them! Don’t forget to install MobileTerminal to run your Apps.

Hope this guide was helpful!