Landscape Orientation

March 31, 2009 § Leave a comment

In info.plist set UIInterfaceOrientation = UIInterfaceOrientationLandscapeRight

Delegate:

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

ViewController

-(BOOL)shouldAutorotateToInterfaceOrientation:

(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

Maximize iPhone UI Screen

March 31, 2009 § Leave a comment

Some iphone developers skip this step. To make your app appear professional, I would highly recommend this tiny step. Maximize the portrait screen by hidding the status bar is a small investment with greater return in User Experience. It is ugly to show the battery and time on certain applications.

Under Resource folder, you can add a new item to Info.plist. Enter a new Key “UIStatusBarHidden”. Right click the select ValueType: Boolean. You may have to highlight the entire row on UIStatusBarHidden to activate the proper right-click menu. Click the check box. You are done. This is that simple.

When to go with AVAudioPlayer on iPhone SDK

March 28, 2009 § Leave a comment

How do we make decision on which Audio framework to use? Beside the obvious reasons such as AVAudioPlayer support OS 2.2 and above, AVAudioPlayer won’t have 30 sec limitation, there is another undocumented audio benefit. AVAudioPlayer play significant louder, almost twice as loud than the same audio file played by AudioServicesPlaySystemSound.

If you desire dynamic sounds varying from low to high, AVAudioPlayer is definitely the best choice in audio selection.

// Using AVAudioPlayer
AVAudioPlayer *player;
NSString *soundPath = [[NSBundle mainBundle] pathForResource:@”sound” ofType:@”wav”];
player =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath: soundPath] error:nil];
player.volume = 1.0;
player.numberOfLoops = 0;
[player prepareToPlay];
[player play];

// Using AudioServicesPlaySystemSound
NSString *soundPath = [[NSBundle mainBundle] pathForResource:@”sound” ofType:@”wav”];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:soundPath], &soundID);
AudioServicesPlaySystemSound (soundID);
[soundPath release];

Isolate errors not related to iPhone simulator

March 28, 2009 § Leave a comment

This is a very useful technique to troubleshoot on iPhone simulator. To avoid getting errors on triggering features not supported by simulator, you can use the following technique to run code for simulator, different block of codes on device. Use UIAlertView to return the message on simulator. I have never seen iPhone SDK developers reference it. It is extremely useful.

Features that crush your simulator:

  • Open Email
  • Open website
  • Open Camera
  • Open any native iphone app

– (IBAction) soundTricorderButton:(id)sender {
#if TARGET_IPHONE_SIMULATOR
//compiler specific code
UIAlertView *alertView;
alertView = [[[UIAlertView alloc] initWithTitle:@”Alert View” message:@”http://www.google.com” delegate:self cancelButtonTitle:@”OK” otherButtonTitles:nil] autorelease];
[alertView show];
#else
// device specific code
NSURL *url = [[NSURL alloc] initWithSet:@”http://www.google.com”%5D;
[[UIApplication sharedApplication] openURL:url];
[url release];
#endif
}

Xcode corrupted? Fragile Yes!

March 28, 2009 § Leave a comment

I encounter a strange yet unexplained error on Xcode and it is not related to the syntax. The code is exactly the same. The only difference is 1) I copy and paste the code from the blog 2) I enter the code from scratch.

error:syntax error before ‘@’ token
error:syntax error at ‘OTHER’ token
…repeat the same error line many times…

It is not easy to spot the issue. When you copy and paste the code outside Xcode, you doube quote may be in formatted curly quote, not the keyboard doube straight quote. Xcode will see this as error.

Should I rename UIViewController after change of heart – DON’T

March 28, 2009 § Leave a comment

Interface Builder is one of the most undocumented and most important part of iPhone SDK development. You can search the latest developer books on iPhone SDK or books specific on Xcode and still find no practical guide in debugging problems.

I found many iphone SDK developers won’t share their debugging experience. I am sharing these hard-earned tips here.

Don’t ever think of renaming the project name, UIViewController, etc after you change your mind. If you are using Xcode template Utility application, you would mess up the connections from Interface Builder and couldn’t get the application to run properly.

If you want to keep the same project name, just copy entire project folder outside Xcode. Rename the backup folder with different name. Create a new project with proper name.

iPhone SDK Simulator

March 28, 2009 § 1 Comment

This is another block of errors on Xcode Console. Your app fail on both iPhone simulator and device. However your Xcode shows no errors or warnings after Build and Debug.

Errors from Console:

WARNING: Falling back to active SDK directory at: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.2.sdk

Loading program into debugger…
GNU gdb 6.3.50-20050815 (Apple version gdb-963) (Sun Nov  2 03:13:07 UTC 2008)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type “show copying” to see the conditions.
There is absolutely no warranty for GDB.  Type “show warranty” for details.
This GDB was configured as “–host=i386-apple-darwin –target=arm-apple-darwin”.tty /dev/ttys000
warning: Unable to read symbols from “dyld” (prefix __dyld_) (not yet mapped into memory).
warning: Unable to read symbols from “Foundation” (not yet mapped into memory).
warning: Unable to read symbols from “UIKit” (not yet mapped into memory).
warning: Unable to read symbols from “CoreGraphics” (not yet mapped into memory).
warning: Unable to read symbols from “AudioToolbox” (not yet mapped into memory).
warning: Unable to read symbols from “AVFoundation” (not yet mapped into memory).
warning: Unable to read symbols from “QuartzCore” (not yet mapped into memory).
warning: Unable to read symbols from “CoreLocation” (not yet mapped into memory).
warning: Unable to read symbols from “libgcc_s.1.dylib” (not yet mapped into memory).
warning: Unable to read symbols from “libSystem.B.dylib” (not yet mapped into memory).
warning: Unable to read symbols from “libobjc.A.dylib” (not yet mapped into memory).
warning: Unable to read symbols from “CoreFoundation” (not yet mapped into memory).
Program loaded.
target remote-mobile /tmp/.XcodeGDBRemote-127-20
Switching to remote protocol
mem 0x1000 0x3fffffff cache
mem 0x40000000 0xffffffff none
mem 0x00000000 0x0fff none
sharedlibrary apply-load-rules all

It happened to me. I found no errors. I repeatedly remove block of codes and UIButtons on Interface Builder, then recreate the code blocks and UIButtons from scratch. Renaming the problematic UIbutton names and methods that fail the console won’t help. Restarting computer and Xcode won’t help. Restoring the device won’t help.

How did I end up there. I was working on recording and playing music via Audio Queue Services,. I learn that it is a very bad idea to add such feature on top of existing app. Even it didn’t add any errors and warning, it corrupted simulator and device overloading the buffer on simulator and device. Restarting and restoring device won’t remove these overloaded buffer. As soon as I remove all the threads from Audio Queue Services, warning on Simulator Console related to UUID will disappear.

WARNING: Falling back to active SDK directory at: /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.2.sdk

warning: UUID mismatch detected with the loaded library – on disk is:
/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.2.sdk/System/Library/Frameworks/Foundation.framework/Foundation
=uuid-mismatch-with-loaded-file,file=”/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.2.sdk/System/Library/Frameworks/Foundation.framework/Foundation”

….

Approach:
If you have a UIAction method containing multiple tasks, it is best if you comment out each small block of codes using /* … your code …. */. Build it on the console and see which small block of codes give you the above error.

The simulator error on console warning: Unable to read symbols from “dyld” (prefix __dyld_) (not yet mapped into memory). may refer to how Xcode fails to recognize your code. If you have been making many changes on the same block of codes especially you have moved the UIButton around on InterfaceBuilder or you have made many slight changes on UIButton, Xcode will break.

You may not see any syntax error or warning on Xcode. However it will fail on simulator and it will display the errors on Console.

After spending hours and hours in troubleshooting block of codes that are working at some point and fail later with no good explanation, I discover the simple recovery is to just type the same code again.

Again this is a very common errors most iPhone developers quoted. I find out how to resolve and narrow the sources of problems after hours and hours of investigation. It certainly deserves to mention them.

Where Am I?

You are currently viewing the archives for March, 2009 at Web Builders.