Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Tuesday, 31 July 2012

Could Not Instantiate Class Named 'NSLayoutConstraint'

Back into iPhone development again, I found myself briefly scratching my head at an app crashing when testing on one of my real devices, but not another. The console shows a stack trace with the pertinent complaint being


*** Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named NSLayoutConstraint'*** 

Well that's no good now is it ? I found that it runs just fine on my iPhone running iOS 6 beta 3, but crashes out with the above error when running on my iPod 5.1. It turns out that the new Xcode has introduced some new functionality into the Interface Builder, some of which is enabled by default when creating new XIBs.

The offending item is this case, is the use of "Autolayout" of interfaces. It seems that when using Xcode to create new interfaces, Autolayout is checked by default, even though it is a feature available for iOS 6 onwards. My project targets iOS 4, so I was a bit surprised to see it assume such a breaking setting, but maybe that is just because the Xcode version I am using is also still in beta (Version 4.5 4g125j).

The fix is quite simple, Select the XIB which is failing to load, and from the panes down the right, find the one entitled "Interface Builder Document". Under here, are settings for deployment versions (which represents the minimum version you want to support), which can be changed to match your expectations.





Selecting the correct version will result in the build failing, quoting a build error such that:

Auto Layout on iOS Versions prior to 6.0

Underneath this setting, is a checkbox entitled "Use Autolayout" which should be unchecked, as per the build error. Rinse and repeat for any other XIBs you have created using Xcode 4.5.

Thursday, 9 February 2012

Rotating BlackBerry Playbook Simulator

I'll keep this one short and snappy.

If you want to change from the default 'landscape' mode, click and hold the mouse from the bottom right hand edge of the simulator (just anywhere in the black section will do) and drag towards the centre of the screen, and release.

Monday, 24 October 2011

Custom HTTP Headers in iPhone UIWebView


If you've done much coding for iPhones, you'll likely have come across the UIWebView class. It is what allows you to use an embeddable web browser component, within your app. It's a useful component that lets you view web pages straight from within your app, using the very capable rendering capabilities granted to the iPhone's full Safari browser.

The problem I faced today, however, was that I needed to customise some of the HTTP headers that are sent to servers, when using the UIWebView component. Turns out that this is possible, although not as straight forward as I first expected. Why might you want to do this? Well you might want to alter the HTTP User Agent string, add some custom headers that your server requires, alter the language supported by the Accept header or you might well just be really curious.

Read the solution after the break.

Thursday, 15 September 2011

BlackBerry - Eclipse Error - Invalid Regex in BlackBerry_App_Descriptor.xml

If you ever see this error from Eclipse whilst doing BlackBerry development,

InvalidRegex: Pattern value '([a-zA-Z_]{1,63}[\s-a-zA-Z_0-9.]{0,63}[;]?)*' is not a valid regular expression


you should of course follow the hint in the error and check that none of your values in your BlackBerry_App_Descriptor.xml will fail the regex.

However, there is a very strange case whereby you will see this error regardless of your values. In fact, creating a new project straight from Eclipse will still show the error.

Turns out this could be caused by having Java JRE 7 installed on your machine. The BlackBerry plugin doesn't support this yet, Eclipse might be trying to use that.

The fix? You simply have to edit the eclipse.ini that will live in the same directory as your eclipse.exe that you use to start the IDE. Closing Eclipse and making a backup of eclipse.ini before you do this would be a good idea.

Find the line "openFile" and immediately after, add the following:

-vm
C:/Program Files/Java/jre6/bin/javaw.exe [or wherever your jre6 directory might be]

Cross your fingers and restart Eclipse.
Rebuild your projects.

Wow I hate programming for BlackBerry. Is it not dead yet? Seriously any platform that needs a site like this (http://isthesigningserverdown.com/) needs to get itself sorted.

Thursday, 31 March 2011

WP7 - URI Mapper

Overview
I am always on the lookout for ways to improve code; short term benefits are nice but there is a great feeling in identifying potential problems way in advance, and putting in the framework early to make life easier later. Using a UriMapping when developing WP7 apps is one of the many ways you can help eliminate annoyances later.


So first of all, a brief description of how page navigation works in WP7, what a UriMapper is, and why it pays to use it. Scroll down passed these descriptions if you'd rather just see how to implement one.