Skip to content →

diego.org Posts

Targeting the iPhone 4

Are you releasing a flashlight app for the iPhone 4 or writing an application that use the capabilities of a certain device? Apple provides a UIKit Dictionary key called UIRequiredDeviceCapabilities for this purpose.

Apple define this key as: UIRequiredDeviceCapabilities (Array or Dictionary – iOS) lets iTunes and the App Store know which device-related features an application requires in order to run. iTunes and the mobile App Store use this list to prevent customers from installing applications on a device that does not support the listed capabilities.

You set this key in the Info.plist. Here is an example which tells the App Store that your app requires a camera flash. You can use this if your app only runs on the iPhone 4:

	<key>UIRequiredDeviceCapabilities</key>
	<array>
		<string>camera-flash</string>
	</array>

More: UIKit Keys

Comments closed

iPhone Custom Fonts with FontLabel

Need to use your own custom font? Or you want to support a certain font that isn’t on older iPhonts? Check out the project FontLabel.

To use FontLabel:
1. Get a copy of the project: https://github.com/zynga/FontLabel.git

2. Add the files to your project:

3. Add a font file to your project. You can find several free fonts here: http://www.webpagepublicity.com/free-fonts.html

4. In your AppDelegate, add the import:

#import "FontManager.h"

And then load the font file in the didFinishLaunchingWithOptions:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
	// Load Custom Fonts
	[[FontManager sharedManager] loadFont:@"FuturaBoldBT"];
}

In my example, I used the font “FuturaBoldBT.ttf

5. Finally create a FontLabel, which is just a subclass of UILabel:

-(void) displayMyLabel {
        FontLabel * myLabel = [[FontLabel alloc] initWithFrame:CGRectMake(10, 30, 50, 30)
												fontName:@"FuturaBoldBT" pointSize:26.0f];
	myLabel.textAlignment = UITextAlignmentCenter;
	myLabell.textColor = UIColor.whiteColor;
	[myLabel setBackgroundColor:UIColor.clearColor];
	[self addSubview:myLabel];
}
Comments closed

sgx error (background gpu access not permitted)

I recently started seeing this error in my Cocos 2d iPhone application running on iOS 4.1:

sgx error (background gpu access not permitted):
Program received signal: “SIGABRT”.

After searching around, I found this thread on the cocos2d forum.

I modified my code in the ApplicationDelegate to look like:

- (void)applicationDidEnterBackground:(UIApplication *)application
{
	[[CCDirector sharedDirector] stopAnimation];
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
	[[CCDirector sharedDirector] startAnimation];
}

- (void)applicationWillResignActive:(UIApplication *)application
{
	[[CCDirector sharedDirector] pause];
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
	[[CCDirector sharedDirector] resume];
}

This solved my problem. I hope it helps someone else.

2 Comments

iTerm crashing on launch

I’ve recently been using iTerm on the Mac. I was happily using it, until it started crashing on launch. After searching around on the internet, I finally figure out what is wrong. The issue occurred because I was using an external display. When not connected to the external display the app would crash.

I found details in this bug here: http://sourceforge.net/tracker/index.php?func=detail&aid=2889711&group_id=67789&atid=518973

There are 2 easy ways to solve this problem.

1. In the normal terminal type:

defaults delete net.sourceforge.iTerm "NSWindow Frame iTerm Window 0"

2. Open ~/Library/Preferences/net.sourceforge.iTerm.plist and removed the following entry:
NSWindow Frame iTerm Window 0:

One Comment

Buying an Apple Product

Apple is very secretive about it’s products and releases. This makes it very difficult to know if it’s a good time to buy a particular Apple product.

To aid you in your decision, Macrumors.com has a Buyer’s Guide. This guide lists the release history of each product and gives a recommendation as to if now is a good time to buy or not.

If you’re looking to buy a new mac, iphone, monitor, etc.. this guide should be your first stop.

Comments closed

Naked Domains in Google App Engine

After setting up an app in the google app engine with a domain name, I found that accessing the domain via the naked domain name (no www.) would not work.

Worked:
http://www.mydomain.com

Didn’t work:
http://mydomain.com

After search for a while, I came across this answer:
http://www.google.com/support/a/bin/answer.py?hl=en&answer=91080

The solution is to forward mydomain.com to www.mydomain.com with your domain registrar. After doing this, it worked as expected.

Comments closed

iPhone Development Helper: Fill up your Address Book

AddressBookFill is a simple application which populates your address book with contacts. This is useful when developing for the iPhone and working on the emulator.

On many occasions, I’ve spent quite a bit of time adding contacts to the emulator to test something. Then when I change emulator version, they all get erased. This is very frustrating. So I put together this simple application which allow you to programatically fill up your address book.

Currenly the address book is populated with U.S. Presidents. Values are set for:
* first name
* last name
* photo
* phone number
* birthday

I’ll make it more robust in the future. But you may find this useful for now. The code might also be interesting if you’re learning how to program the address book.

Download: addressbookfill-10.tar.gz

3 Comments

ASIHTTPRequest – Uploading Photos

Recently I used ASIHTTPRequest to upload images and other data from an iPhone application to a web server. I search around and looked at all the different options and this was best and easiest to use. It’s open source and comes with lots of good examples. I was particularly impressed with the network queue.

The one thing I did not find, was sample code for was posting an image to a server. Here is some sample code:

// Initilize Queue
[networkQueue setUploadProgressDelegate:statusProgressView];
[networkQueue setRequestDidFinishSelector:@selector(imageRequestDidFinish:)];
[networkQueue setQueueDidFinishSelector:@selector(imageQueueDidFinish:)];
[networkQueue setRequestDidFailSelector:@selector(requestDidFail:)];
[networkQueue setShowAccurateProgress:true];
[networkQueue setDelegate:self];

// Initilize Variables
NSURL *url;
ASIFormDataRequest * request;

// Add Image
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 
     NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *dataPath = [documentsDirectory 
     stringByAppendingPathComponent:@"myImage.jpg"];

// Get Image
NSData *imageData = [[[NSData alloc] 
     initWithContentsOfFile:dataPath] autorelease];

// Return if there is no image
if(imageData != nil){
	url = [NSURL URLWithString:@"http://myserver/upload.php"];
	request = [[[ASIFormDataRequest alloc] initWithURL:url] autorelease];
	[request setPostValue:@"myImageName" forKey:@"name"];
	[request setData:imageData forKey:@"file"];	
	[request setDidFailSelector:@selector(requestWentWrong:)];
	[request setTimeOutSeconds:500];
	[networkQueue addOperation:request];
	queueCount++;
}
[networkQueue go];	

Note: It’s not necessary to use a queue here because I’m only uploading 1 thing. But in my application I’m uploading many things and a queue was helpful. It also runs in the asynchronously in the background, which prevents the UI from getting locked up.

Note 2: When sending large files you should use “setFile” instead of “setData”. Files are then read from disk instead of memory. Here is an updated example. Thanks again to Ben Copsey for this library and his useful comments below.

NSString *imagePath = [documentsDirectory 
     stringByAppendingPathComponent:@"myImage.jpg"];
url = [NSURL URLWithString:@"http://myserver/upload.php"];
ASIFormDataRequest *request = 
    [[[ASIFormDataRequest alloc] initWithURL:url] autorelease];
[request setPostValue:@"myImageName" forKey:@"name"];
[request setFile:imagePath forKey:@"photo"];

More info on streaming here: http://allseeing-i.com/ASIHTTPRequest/How-to-use#streaming

16 Comments

WD My Book 1 TB Hard Drive – Partition Failed

I recently bought at Western Digital My Book 1 TB Hard Drive for my MacBook Pro. I wanted to use it for Time Machine backups, which meant that I needed for format it as Mac OS Extended. It came pre-formatted as FAT.

I used Disk Utility to partition it and got an error a few seconds into it.
wd-error
The error window said: “Partition failed. Partition failed with error: File system formatter failed”.

After pulling my hair out for a while, I finally figured it out…

I’m not exactly sure the reason why, but Mac OX has an issue with a “Master Boot Record” bigger than 512mb. Luckily the solution is easy.

1. Open up Disk Utility.

2. Select your drive on the left hand side.

3. Then click on the “Partition” tab.

4. Choose Volume Scheme: “1 Partition” and select the format: “Mac OS Extended (Journaled)”
wd-options

5. Then click on the “Options” button.

6. Here is the important part. Choose “GUID Partition Table” instead of “Master Boot Record”. Then click “OK”.
wd-partition

7. Now click “Apply” to start the partition process. That’s it!

2 Comments

Undefined symbols: _SCNetworkReachabilityCreateWithName

I was recently adding some code to check for the availability of the network, so I can display an error to the user if unavailable.

I looked at the SeismicXML application and borrowed the following code:

// Use the SystemConfiguration framework to determine if the host that provides
// the RSS feed is available.
- (BOOL)isDataSourceAvailable
{
    static BOOL checkNetwork = YES;
    if (checkNetwork) { 
// Since checking the reachability of a host can be expensive, 
// cache the result and perform the reachability check once.
        checkNetwork = NO;
        
        Boolean success;    
        const char *host_name = "earthquake.usgs.gov";
		//const char *host_name = "localhost";

        SCNetworkReachabilityRef reachability =
SCNetworkReachabilityCreateWithName(NULL, host_name);
        SCNetworkReachabilityFlags flags;
        success = SCNetworkReachabilityGetFlags(reachability, &amp;amp;flags);
        _isDataSourceAvailable = success &amp;amp;&amp;amp; 
(flags &amp;amp; kSCNetworkFlagsReachable) &amp;amp;&amp;amp; 
!(flags &amp;amp; kSCNetworkFlagsConnectionRequired);
        CFRelease(reachability);
    }
    return _isDataSourceAvailable;
}

I wouldn’t compile unless I added the following import:

#import <SystemConfiguration/SystemConfiguration.h> 

After adding this I still go 2 more errors, but these were a bit more cryptic.

 Undefined symbols:
"_SCNetworkReachabilityCreateWithName", referenced from:
-[TheElementsAppDelegate isDataSourceAvailable] in TheElementsAppDelegate.o
"_SCNetworkReachabilityGetFlags", referenced from:
-[TheElementsAppDelegate isDataSourceAvailable] in TheElementsAppDelegate.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

After some digging around I realized that I was missing the SystemConfiguration.framework framework.

So here is what I did to add it.
1. I right click on “Frameworks” and choose: Add < Existing Framework
add_framework

2. Browsed to the file: /System/Library/Frameworks/SystemConfiguration.framework

3. Rebuilt the project and my error was gone.

7 Comments