Thursday, October 9, 2008

HOW TO PORT APPS OVER FROM 1.1.x to 2.x.x

The creator of Cydia, Saurik writes a great tutorial on how

LayerKit -> CoreAnimation

Pretty much everything in LAyerKit has been moved to QuartzCore. LayerKit was really just the older name of CoreAnimation, and now most anything that was LK* maps to something similar in CA*. The names, however, aren't always the same. For example, LKCurrentTime has become CACurrentMediaTime.

UIFont/UIColor vs. CG/GS*Ref

Fonts and colors are handled by GraphicsServices and CoreGraphics, respectively. This used to be exposed directly in UIKit for 1.x (setColor: for example would normally take a CGColorRef). The new UIKit, however, has wrapped these primitives in Objective-C guises. Converting back/forth between these types is typically easy.

Using PrivateFrameworks

In order to keep application developers from using backend APIs of other applications (i.e., APIs that are going to change often and lead to unstable, brittle applications), Apple has moved most of their internal-use-only libraries into /System/Library/PrivateFrameworks, which is not normally on the link path. To add this back you need to pass this directory to gcc with -F.

Using Undocumented UIKit

The #1 thing to understand about UIKit is that Apple mostly didn't change it. For some unknown backwards compatibility reason they left in most of the 1.x classes, which means most of the code for 1.x can be compiled with only minor naming differences for the new platform. (Thanks goes to Jonathan Zdziarski (NerveGas) for figuring this out.)

UIAlertSheet - UIActionSheet
UIButtonBar - UIToolbar
UISliderControl - UIOldSliderControl
UISwitchControl - _UISwitchSlider
UIWebView - UIWebDocumentView

Alert/Action Sheet Dismissal

Pretty much all usages of dialog boxes involved dismissing the dialog box during a buttonClicked: event. Apple has renamed this to didDismissWithButtonIndex: and does the call to -(vod)dismiss.

Double vs. Single Precision

A few places in the original UIKit libraries Apple was using double's, even though pretty much everywhere they use floats. These places have been changed. One such example is [UIProgressBar setProgressfloat)].

Automatic Keyboard Support

Apple has decided that manually having to manage the keyboards that go with text input fields is stupid, and I must say I agree with them. Unfortunately, this means that code used to manually bring up keyboards is now dangerously out of date: you end up with two keyboards, only one of which normally works.

CoreGraphics vs. ImageIO

Most programs that need to draw things to the screen do not need to have complex data input/output from said graphics buffers. All of this file format and color munging code was probably taking up too much memory, so it got forked out to a different library: ImageIO. Examples: CGImageDestination/Source.

UIApplicationMain(Class)

Previous, UIApplicationMain() was passed the metaclass object of a type that derived from the class UIApplicationMain, which it would then instantiated. Now it optionally takes the names of two separate classes that take on different aspects of UIApplication's functionality. If you pass the name of your old class for both these arguments you will get seemingly identical behavior.

mprotect(), NX, and max_prot

While this information doesn't apply to applications developed for JailBroken devices, it is still useful to understand that Apple has started taking measures to protect against arbitrary code execution. In addition to code signing, pages that were once writable can never be marked executable, which means no JIT compilers or dynamic trampolines (in other words, bye bye performance). This particular issue has been patched out of the kernel by Pwnage.

No comments: