Archive for category iPhoneDev

Hide the TabBar in an iOS App

I recently came across a situation where it was useful to have a UITabBar based application, however the actual tab bar was an unnecessary item on the screen. This post is a mini tutorial on how to make this happen.

Inside “application:didFinishLaunchingWithOptions:” method:

tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:navController1, viewController1, viewController2, nil];
[window addSubview:tabBarController.view];
[self makeTabBarHidden:TRUE];

 

Here is the “makeTabBarHidden” method:

-(void)makeTabBarHidden:(BOOL)hide {
	// Custom code to hide TabBar
	if ( [tabBarController.view.subviews count] < 2 ) {
		return;
	}

	UIView *contentView;

	if ( [[tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] ) {
		contentView = [tabBarController.view.subviews objectAtIndex:1];
	} else {
		contentView = [tabBarController.view.subviews objectAtIndex:0];
	}

	if (hide) {
		contentView.frame = tabBarController.view.bounds;
	}
	else {
		contentView.frame = CGRectMake(tabBarController.view.bounds.origin.x,
									   tabBarController.view.bounds.origin.y,
									   tabBarController.view.bounds.size.width,
									   tabBarController.view.bounds.size.height - tabBarController.tabBar.frame.size.height);
	}

	tabBarController.tabBar.hidden = hide;
}

 

And you are probably wondering how to change the views that are normally controlled by the tab bar? Here is the answer…just simply change the selectedIndex property of the tab bar.

tabBarController.selectedIndex = 1;

 

Part of this code came from a post I found on iPhoneDevSDK.com, so I took it one step further and made it a complete solution.

CocosDenshion Sound Engine

Version 0.99 of Cocos2d for the iPhone was just released this week. I am using the Cocos2d framework in my game, and wanted to post a short tutorial/sample code for the CocosDenshion sound engine that is shipping with the latest version.

I am going to start off with the the basic Hello World example that is created for you when you create a new Cocos2d project.

 

In the HelloWorld.h file add the following lines of code to import the needed files:

#import "SimpleAudioEngine.h"
#import "CocosDenshion.h"
#import "CDAudioManager.h"

 

Now we will move to the HelloWorld.m file to add the rest of the code. Inside the init method will will preload the background music so there is no lag when opening this layer. Since we only have one layer, it makes no difference. This will help when you have multiple layers in a game. One thing to note, the backgroundMusicVolume can be set from the range of 0.0 to 1.0. If you load a new background music file, you will need to set this again.

SimpleAudioEngine *sae = [SimpleAudioEngine sharedEngine];
if (sae != nil) {
	[sae preloadBackgroundMusic:@"mario-theme.mp3"];
	if (sae.willPlayBackgroundMusic) {
		sae.backgroundMusicVolume = 0.5f;
	}
}	

 

To play the background sound and other sounds use the following code:

// Start the background music from the beginning and stop the background music
[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"mario-theme.mp3"];
[[SimpleAudioEngine sharedEngine] stopBackgroundMusic];

// Mute and unmute all sounds
[CDAudioManager sharedManager].mute = TRUE;
[CDAudioManager sharedManager].mute = FALSE;

// Pause and unpause the background music
[[SimpleAudioEngine sharedEngine] pauseBackgroundMusic];
[[SimpleAudioEngine sharedEngine] resumeBackgroundMusic];

 

As you can see, CocosDenshion is very simple and easy to use. More information on it can be found here.
If you would like to see this in working action, then head on over to my github repository and download the sample project.
http://github.com/ndubbs/CocosDenshion-Example
As always, comments are welcomed and greatly appreciated.

Check Network Connectivity

I figured I would put together a simple tutorial since I’ve been getting a lot of traffic based on “iPhone Human Interface Guidelines.” This is probably due to one of my earlier blog post, “Developing My First iPhone App.” I failed to adhere to the guidelines in the beginning, so my app was originally rejected. Here is a simple tutorial so you don’t have the same issue as I did.

 

Download the Reachability project from Apple. The link to the project is:
http://developer.apple.com/iphone/library/samplecode/Reachability/index.html

 

The two files we will need are: Reachability.h and Reachability.m

 

Add SystemConiguration Framework:
1. Control click (right click) on the Frameworks folder and select Add then select Existing Frameworks.
2. Scroll down and select SystemConfiguration.framework.
3. Click Add.
4. Control click (right click) on the project icon and select Add then select Existing Files.
5. Find the Classes folder in the Reachability project, and select the files Reachability.h and Reachability.m.
6. Click Add, then make sure the check box is selected for “Copy items into destination group’s folder (if needed).”
7. Click Add.

 

Inside ViewController.h file, add the following statement to the top of the header file.

#import "Reachability.h"

 

Inside the interface definition of the view controller, add the variable definitions:

NSString *urlAddress;
NSURL *url;
NSURLRequest *requestObj;
NetworkStatus remoteHostStatus;
NetworkStatus internetConnectionStatus;

 

Add the following properties:

@property (nonatomic, retain) NSString *urlAddress;
@property (nonatomic, retain) NSURL *url;
@property (nonatomic, retain) NSURLRequest *requestObj;
@property NetworkStatus remoteHostStatus;
@property NetworkStatus internetConnectionStatus;

 

Inside ViewController.m file add the synthesize statements after the implementation statement:

@synthesize webView, urlAddress, url, requestObj;
@synthesize remoteHostStatus, internetConnectionStatus;

 

Inside the viewDidLoad method, add the following lines of code to set the variables:

[[Reachability sharedReachability] setAddress:@"http://www.apple.com"];
[[Reachability sharedReachability] setNetworkStatusNotificationsEnabled:YES];

 

Inside the programming logic, use the following lines of code to test network connectivity. Substitute the code you would like to execute where the “NSLog(@”Connection Made”)” statement is.

// Query the SystemConfiguration framework for the state of the device's network connections.
self.remoteHostStatus = [[Reachability sharedReachability] remoteHostStatus];
self.internetConnectionStatus = [[Reachability sharedReachability] internetConnectionStatus];

// Check if there is a connection
if (self.internetConnectionStatus == NotReachable && self.remoteHostStatus == NotReachable)
{
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error Loading"
                                     message:@"No Internet   Connection"
                                     delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
     [alert show];
     [alert release];
} else {
        NSLog(@"Connection Made");
}

 

Don’t forget to clean up and add the following statements to the dealloc method.

[urlAddress release];
[url release];
[requestObj release];

Getting Started with Cocos2d

Step 1: Download Cocos2d from the project website.

Step 2: Unzip the downloaded file in Step 1. If you are running Snow Leopard, it most likely will be in the downloads folder. Move the newly unzipped folder to the Desktop.

Step 3: Open Terminal and change the directory to the cocos2d folder on the desktop.

 cd desktop/cocos2d-iphone-0.8.2

Step 4: Run the install template script.

./install_template.sh

The process is complete. Startup XCode and have fun!

PA Traffic Cams Survey Results

PA Traffic Cams iPhone iPod Touch App
Apple’s iTunes is a little lacking in the department of rating apps. Mostly when anyone rates an app they do so when they are deleting it from their iPhone, or if they really really love the app. Another thing that is lacking is allowing the developers to have a line of communication with the app users. I thought a survey might help bridge this gap and help me to communicate with the users of my app. I’ve had a survey online since July to collect some feedback from the users of my app.

Results:

Out of 62 people who have filled out the survey, PA Traffic Cams has an overall rating of 3.9 out of 5. Mostly everyone said they would recommend the app or already has recommended it. There were 4 people who said they wouldn’t.

Features:

Over half of the responders have said they loved the traffic speed map feature, and almost all of the rest have found it moderately to somewhat useful. I’m glad that it was a useful feature. Google has released a newer version of their maps. I’m waiting on them to implement this feature into the latest version of their maps. Since I am running the older version, it runs a little bit on the slow side.

One thing to note, I do not control how many cameras or in which location the cameras are placed. PennDOT is solely responsible for the cameras, and I am in no way shape or form associated with them. I merely have created an app to allow users to easily navigate and view them. I try my best to check PennDOT’s website and update the app with new cameras when they are made available. If you know a link to any cameras not on the app, please send me an email and I will work on adding them.

A few of you have requested making this app for the BlackBerry. I’m sure people on the Android will also want this app. I unfortunately do not own a BlackBerry or an Android which creates a little bit of a challenge for me. I can test the app in the simulators, but I have no way to know if it will actually work on the device. I don’t ever want to put out software that does not function. Things may change in the future, but for the moment I will not be developing for the other phones.

Thank You!

Thank you to everyone who has filled out the survey. I do appreciate the time everyone took to fill it out. Your feedback will allow me to determine what features to add in upcoming releases. Speaking of which… If you have an idea please send me an email, I would love to hear about it.

Back in the Saddle

For over the past year and a half, I’ve been working full-time and then taking classes on Saturdays. I would have three classes with a 30 minute lunch between the second and third classes. While this has been very challenging, it also has been just as rewarding. Taking the business classes has helped me to grow as a better developer.

What’s next?

I finished the MBA up this past Sunday, and now I have some free time again.
So, I will be working on some iPhone development in my free time. I plan on writing about it and providing some things I find useful and would like to share. I also plan on putting out some coding examples as well as doing a Cocos2d presentation for Cocoaheads Pittsburgh. Stay tuned in and may you have a happy holiday season!

DC Traffic Cams now available for the iPhone/iPod Touch

DC Traffic Cams iPhone/iPod Touch app is now available in iTunes. Conveniently view Washington DC’s District Department of Transportation traffic camera images at the touch of a finger. Most of the major Washington DC area roadways are included in this application. Other features include a map of traffic speeds, and a traffic feed of accidents, construction, and road closings. Check it out!

Quacktastic Lite now available in iTunes

Quacktastic Lite iPhone/iPod Touch app is now available in iTunes.  This is the free version of Quacktastic which contains ads.  Check it out!

Minor Change in iTunes

PA Traffic Cams iPhone AppI was brainstorming about continuous improvement for my iPhone/iPod Touch apps. I think the information I’m learning in my MBA classes is helping steer my thought process lately, which is totally a good thing. Anyhow, I noticed that users were not being presented with a good image in iTunes of what PA Traffic Cams actually does. So I replaced the primary screenshot with the camera view image. Now users are presented with a screenshot of a camera showing traffic. I think this change should provide a better experience for the user.

It is probably a small ratio of people who take the time to click the next arrow, or fully read the entire description. Having the “wrong” image as the primary screenshot has probably deterred people from downloading my app. This one change has produced a significant improvement!

In other news, I also created a short survey of questions on PA Traffic Cams. Please help me out and answer the questions, so that I can provide the best possible app that I can. The survey is available on the PA Traffic Cams website.

PA Traffic Cams 1.1 Available

PA Traffic Cams iPhone iPod Touch AppPA Traffic Cams version 1.1 is now available in the iTunes App Store. New features in this version included a interface enhancements and traffic maps with speeds for Pittsburgh, Philadelphia, and Allentown. This version also fixes some cameras in Harrisburg, Scranton/Dunmore, and Allentown.

PA Traffic Cams Website

Don”t forget to check out my other iPhone/iPod Touch app. Quacktastic is a quacking blue duck that is sure to entertain kids as well as adults.