iPhone Configuration Utility

Link to the iPhone Configuration Utility


Validate email address on the iPhone

Here is some simple code that allows you to validate email addresses that have been entered by a user on an iPhone. It does use NSPredicate, which is only available on OS 3.0 and above;

	NSString *email = [newEmailAddress.text lowercaseString];
	NSString *emailRegEx =
    @"(?:[a-z0-9!#$%\\&'*+/=?\\^_`{|}~-]+(?:\\.[a-z0-9!#$%\\&'*+/=?\\^_`{|}"
    @"~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\"
    @"x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-"
    @"z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5"
    @"]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-"
    @"9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21"
    @"-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])";

	NSPredicate *regExPredicate =[NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegEx];
	BOOL myStringMatchesRegEx = [regExPredicate evaluateWithObject:email];
	if(!myStringMatchesRegEx){
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Correct Email" message:@"Please enter a valid email address" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
		[alert show];
		[alert release];
	}

The code is based on this article which describes this in a lot more detail.


switch case compile error

If you are using a switch case similar to the one below:

	switch (row) {
		case 0:
			int i;
			i = row + 10;
			NSLog(@"%d",i);
			break;
		default:
			break;
	}

You’ll get a compile error, “Expected expression before ‘int’”. If you need to declare a variable enclose the code in curly braces and the error goes away….

	switch (row) {
		case 0:
		{
			int i;
			i = row + 10;
			NSLog(@"%d",i);
			break;
		}
		default:
			break;
	}

Note that the error only occurs if the variable declaration is the first statement in the code block.


Great tool for iPhone Mockups

Used OmniGraffle to produce mockups for my latest iPhone project, its pretty easy yo use and there are a number of good stencils that allow for most of the UI Kit controls and even the iPad!


SVN, pbxuser and Xcode

UPDATE: unfortunately this only works for new projects!

Recently needed to change the way svn dealt with pbxuser files, found the following article that shows you how to tell svn to ignore certain files, but before I could do anything I had to be able to see the “hidden” svn folder where this article came in handy!

I’ve copied the crucial snippets here so that I don’t lose them….

Show hidden files

From Terminal run the following command…

defaults write com.apple.Finder AppleShowAllFiles YES

Then you need to get Finder to relaunch, hold down the option key and click the Finder icon in the Dock, then select Relaunch

Now when you look at folders any hidden ones are visible, including the important .svn

SVN Ignore files

Step 1. Open the subversion configuration file
~/.subversion/config
NOTE: If the “.subversion” directory doesn’t exist yet then run this command which fails but will create the necessary files to get you started:
svn status

Step 2. Enable “global-ignores” and add new things to ignore
Find the line that contains the text “global-ignores” and append the following text:
build *~.nib *.so *.pbxuser *.mode* *.perspective*

Step 3. Enable “auto-properties”
Located and uncomment (e.g. remove the leading “#” character) the line that looks like this:
# enable-auto-props = yes

Step 4. Add additional properties
Then go to the end of the file, in the [auto-props] section, and append these lines:
*.mode* = svn:mime-type=text/X-xcode
*.pbxuser = svn:mime-type=text/X-xcode
*.perspective* = svn:mime-type=text/X-xcode
*.pbxproj = svn:mime-type=text/X-xcode


Programmatically Exit iPhone App

To terminate your app from within your code execute the following command…

exit(0);


UIAlertView with UITextField – REJECT

A project I’m working on contains an alert that uses the addTextFieldWithValue:label: private API, this approach has been popular/recommended by a number of developers/blogs, but now that Apple have their automated checking for Private API’s any apps using this technique will be rejected….

“3.3.1 Applications may only use Documented APIs in the manner prescribed by Apple and must not use or call any private APIs.”

The following non-public APIs are included in your application:
addTextFieldWithValue:label:
textFieldAtIndex:

Jeff LaMarche has a great article that shows an alternative, that doesn’t use any Private API’s and therefore shouldn’t get you rejected.


Label with line breaks

To have a label recognise line breaks in the text that you enter in the Interface Builder, set the number of lines to 0, and when you want a new line press both the Option key and the Return key


Core Data – Updated model

After creating a new version of your data model, and adding the relevant code to handle lightweight migration, to actually get your code to run ensure that you do a clean all targets otherwise you get merge model errors!


iPhone mipmaps

Here is some code that shows the glTexParameterf values that need to be set to automatically generate mipmaps and to get OpenGL to use them

glBindTexture(GL_TEXTURE_2D, texture[0]);

//Next 2 lines are required if not mipmap
//glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
//glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

//Next 3 lines required if mipmap
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_GENERATE_MIPMAP, GL_TRUE);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData);


Previous Entries Next Entries