Skip to content
Dec 6 10

How to parse URL from RSS feed with NSXMLParser

by paddoum

When you parse URL from RSS feeds there are, most of the time, unwanted characters (not directly visible) that prevent you from opening a page from within your iPhone app. The solution below is not perfect but does the job.

// Get the actual string
NSString *storyURL = [NSString stringWithFormat:@"%@", self.selectedURL];
// Break it at control characters. This will give an array with multiple objects
NSArray *brokenString = [storyURL componentsSeparatedByCharactersInSet:[NSCharacterSet controlCharacterSet]];
// Get the clean URL
NSString *webURL = [NSString stringWithFormat:@"%@", [brokenString objectAtIndex:0]];

Nov 17 10

A great way to improve NSLog

by paddoum

NSLog has always been my weapon of choice when I needed to debug in my early days of iPhone development. Recently I came across a very interesting post from Vincent Gable which has created a macro called LOG_EXPR(x) that prints out x, no matter what type x is, without having to worry about format-strings (and related crashes from eg. printing a C-string the same way as an NSString). It works on Mac OS X and iOS.

Here is the macro:

#define LOG_EXPR(_X_) do{\
 	__typeof__(_X_) _Y_ = (_X_);\
 	const char * _TYPE_CODE_ = @encode(__typeof__(_X_));\
 	NSString *_STR_ = VTPG_DDToStringFromTypeAndValue(_TYPE_CODE_, &_Y_);\
 	if(_STR_)\
 		NSLog(@"%s = %@", #_X_, _STR_);\
 	else\
 		NSLog(@"Unknown _TYPE_CODE_: %s for expression %s in function %s, file %s, line %d", _TYPE_CODE_, #_X_, __func__, __FILE__, __LINE__);\
 }while(0)



Download VTPG_Common.m and VTPG_Common.h from Vincent Gable’s github repository, and add them to your Xcode project.

Now just add the line #import “VTPG_Common.h” to your prefix file (named _Prefix.pch by default), after the #ifdef __OBJC__, for example:

#ifdef __OBJC__
    #import 
    // maybe other files, depending on project  template...
    #import "VTPG_Common.h"
#endif

Now LOG_EXPR() will work everywhere in your project.

May 3 10

Why my iPhone App did fail to properly launch ONLY when downloaded from the iPhone app store and NOT in development mode?

by paddoum

iPhone apps development is always full of surprise to say the least. It’s always very frustrating to experience an iphone apps crash especially when downloaded from the iTunes app store (Following approval by Apple). It happened only with 3G device (Worked fine on the 3GS) and it didn’t “crash” when ran in debug mode on the simulator or on my iPhone

It appears that iPhone OS uses a watchdog timer when applications are launched. If an iPhone app takes too long to complete its initial startup, the operating system terminates the application (my app actually needs to parse a large xml file into a Core Data base when it launches). iPhone apps terminated for this reason will have the exception code 0x8badf00d and related information noted in the associated crash report.

I didn’t experience this issue with my iPhone app when debugging because when Xcode launches an application, the watchdog timer is disabled to compensate for additional overhead that may be incurred when Xcode attaches the debugger ( I have never read any xcode tutorial regarding this topic by the way). As a result, your iPhone app long startup may initially escape your attention if you are exclusively testing by running from Xcode.

I didn’t experience this issue with my iPhone 3GS either because it has a better processor than the iPhone 3G.

If considerable work must be done at launch, Apple recommends to consider performing that work on a secondary thread and visually indicating the activity which I did to solve this specific issue.

UPDATE: And the solution is….

First you create a method that you want to run in the background:

-(void) methodIwantToRunInTheBackground {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

///Whatever you need here

///Remove the text and the spinner from the view
	[updatingLabel removeFromSuperview];
	[spinner stopAnimating];
///stop ignoring touch to the screen
	[[UIApplication sharedApplication] endIgnoringInteractionEvents];
/// Drain the pool
	[pool drain];
}

An then you create the updating label an the spinner where you want to trigger it ( viewDidLoad for me) :

-(void)viewDidLoad{

	///Updating label
	updatingLabel = [[UILabel alloc] initWithFrame:CGRectMake(110,135, 100, 100)];
	updatingLabel.backgroundColor = [UIColor clearColor];
	updatingLabel.textAlignment =UITextAlignmentCenter;
	updatingLabel.textColor = [UIColor grayColor];
	updatingLabel.text = @"Updating....";
	[self.view addSubview:updatingLabel];
	[updatingLabel release];

	///Spinner display
	spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
	[spinner setCenter:CGPointMake(320/2.0, 460/2.0)]; // I do this because I'm in landscape mode
	// spinner is not visible until started
	[self.view addSubview:spinner];
	[spinner release];
	[spinner startAnimating];

////Star ignoring touchs
	[[UIApplication sharedApplication] beginIgnoringInteractionEvents];

///Run your your method in the background as a different thread
	[self performSelectorInBackground:@selector(methodIwantToRunInTheBackground) withObject:nil];

}
Apr 19 10

How do I specify both icons for a universal iPhone/iPad app?

by paddoum

Add a CFBundleIconFiles key of type Array to your Info.plist. The array should contain 2 string items: the filenames of the two icons. The OS will then automatically choose the correct icon for each platform based on their pixel dimensions.

You can keep the CFBundleIconFile key and have it point to the icon file for the iPhone for 3.0/3.1 compatibility.

Mar 23 10

How to create an iPhone in-app web browser

by paddoum

I have been looking for a while for an in-app browser without finding exactly what I wanted. I eventually figure that the in-app browser from the three20 library had exactly the features that I wanted : 1) basic navigation, 2)ability to add the browser to my navigation controller and 3) option to open web links in Safari for better surf if needed.

I slightly changed the code so no need to add the three20 library to your project. I also added a source that you can find HERE. The webview is now called from a UIButton from the Favorite screen.

URL is passed to the webView controller using the – (id)initWithURLPassed:(NSString *)initURL method.

UPDATE: Made a change in dealloc method.

read more…

Mar 11 10

Approach Guides Wine is now available on the App Store

by paddoum

Approach Guides Wine is the ultimate wine app, helping you navigate any Italian wine list with ease and choose wine with confidence.

Select wine by style, grape, region or food pairing and find information on all of Italy’s grapes, regions and vintages.

Further, AG Wine does not require an internet connection, so this information is always available. It’s like having a sommelier right in your pocket.

KEY FEATURES

* Choose wine with confidence. AG Wine helps you navigate any wine list with ease.
* 4 “never-fail” approaches to finding a great wine: by style, by grape, by region, and by food pairing.
* Super-fast access to wine information, from any location — no internet connection needed.
* Like having a sommelier in your pocket. AG Wine’s recommendations focus on attractively-priced, high-quality wines.
* Build and expand your wine knowledge with our detailed reviews of Italy’s grapes, regions, and DOCs.
* Wine information you can trust. AG Wine operates 100% independently, so you can be confident that you are getting the best advice.
* Start with Italy’s wines. Existing customers will receive discounted pricing on all incremental countries.
* Connects to Facebook and Twitter; emails tasting notes and descriptions.

WHY WE’RE DIFFERENT

Have you ever looked at a wine list and not known where to begin? Approach Guides Wine solves this problem by giving you a strategy to take on any Italian wine list — offering recommendations on which regions, DOCs, grapes, and vintages to look out for and which to avoid. With this critical information, no matter your level of wine knowledge, you can make an informed wine choice that is sure to meet your expectations.

Feb 28 10

AG Wine iPhone App

by paddoum

We are about to launch our AG Wine iPhone app and would LOVE some feedback : http://www.agwine.com/survey/

Feb 25 10

How to to get Twitter authenticating with OAuth token from you iPhone app

by paddoum

After allowing AGWine iPhone app users to update their Facebook status we thought that the next great feature would be to allow them to tweet.

The best twitter engine in the street right now and available to everyone is the MGTwitterEngine developed by Matt Gemmel.

What you might find a bit frustrating is that when you use this library alone the source line on the Twitter page will say “From someone you don’t know” rather than your app name. To achieve the latter you need to comply with OAuth which is an open protocol developed to allow secure API authorization in a simple and standard method from desktop and web applications.

Ben Gottlieb created an easily buildable project with no dependencies that will allow your iPhone app to access Twitter via Oauth. He included the source taken from several other open frameworks and avoided to do the whole thing as a static library since most developers are already using Matt Gemmell’s code MGTwitterEngine. The solution offered is by far the most advanced I have seen lately and it will most certainly help you to save a lot of time.
read more…

Feb 6 10

How to deal with memory leaks on the iPhone

by paddoum

Dealing with memory on the iPhone is one of the most difficult challenges that you will face as a new iPhone developer.

One thing that you have to worry about with memory management is the “retain count” of an object. The retain count is how the system keeps track of the memory used by an object. If an object’s retain count is zero and your attempt to access it your app will crash; if you do not make sure the retain count of your object is 0 when the object goes out of focus you will have a memory leak.

The solution is to add the following snippet wherever you have a doubt about the retain count of an object:

NSLog(@"Retain Count:%i", [myObject retainCount]);

It helped me a lot fighting against iPhone apps random crash!

I also recommend the Xcode tutorial provided by Owen Goss on Mobile Orchard

Feb 3 10

How to get alternate background color for UITableViewCell in Xcode

by paddoum

I found a very efficient way to do it :





- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
 cell.backgroundColor = (indexPath.row%2)?[UIColor grayColor]:[UIColor clearColor];
 }

I also recommend Olivier Drobnik snippet to solve the following dilemma : “How can I make my cells alternate colors across multiple sections if the sections don’t always have the same number of rows?”