Saturday, March 31, 2012

Upgrade to Lion for MonoTouch users

These were the steps I took to upgrade from Snow Leopard to Lion to make MonoTouch work with ios sdk 5.1:
1. Install Lion.
2. Check system updates (will install 10.7.3 Lion update if you are not already on it. My usb stick that was purchased from apple store has 10.7.2).
3. Install XCode 4.3 from Mac AppStore (will require your apple login, and will give you the option to delete Xcode 4.2 which I did).
4. Check Monodevelop updates (will install 2.8.6.5 containing XCode 4.3 compatibility).
5. Re-install MonoTouch http://download.xamarin.com/Installer/Monotouch/monotouch-full.dmg This will download MonoTouch 5.2.5 (or whatever the latest version is when you read this blog).
6. Update Versions to latest version if you are using Versions for source control. I use Versions to connect to tfs using svnbridge. More info on svnbridge: http://svnbridge.codeplex.com/
7. Open terminal and run:
sudo xcode-select -switch /Applications/Xcode.app/
to set xcode path to make Versions work properly.
8. Install command tools from xcode/preferences/Downloads

Upgrade OpenFlowSharp to work with retina display

For those of you using OpenFlowSharp for your MonoTouch apps for iOS and is wondering why it is not displaying retina resolution images the following is the fix to make it work:

In ImageUtils.cs line 81, replace:
UIGraphics.BeginImageContext(size);

with:

if (UIScreen.MainScreen.RespondsToSelector(new Selector("scale")))

{

UIGraphics.BeginImageContextWithOptions(size, false, UIScreen.MainScreen.Scale);

}

else

{

UIGraphics.BeginImageContext (size);

}


You'll need the if block to check for "scale" because it is only supported on iOS 4 and above.

iOS sdk 5.1 CATiledLayer Bug - Draw gets called twice for every tile

Ok I've been banging my head as to why the CATiledLayer Draw(RectF rect) method is being called twice resulting in memory crashes in my monotouch app in sdk 5.1. This used to work in 5.0.1 with no problems i.e. tiles are rendered only once as it should. However once I upgraded to Lion 10.7.3 and ios sdk 5.1, this bug appears and each tile seems to be rendered twice. I can tell from a simple Console.WriteLine(rect) in the Draw method which outputs the coordinates of the tile being drawn.

The reason I discovered this is because my app started to crash with SCGen checked (MonoDevelop iPhone Build/Advanced/Runtime Options). This bug is confirmed in apple's official devforum: https://devforums.apple.com/message/638091

Note: you will need to have a login to view the post.

In the meantime, the workaround is to NOT use SCGen for production build (I am already NOT using it for prod builds anyway, I am only using it for dev builds because it is still experimental) and build against 5.0.1 if you still can.

Hopefully Apple will release a fix soon.

FInally...

Finally I have decided to share with the world all my frustrations and discoveries to do with the development world..