SQLite Wrapper

April 20th, 2010 No comments

I created this code a while back when I was still targeting older iPhone OS i.e. 2.0 and above. I’ve found really useful when I need to throw things at a local SQL database on the device, since it’s creation I’ve moved up to target OS 3.0 and above only. Though I’ve migrated my latest app to these later targets I still have yet to migrate the database code over to user Core Data. :( It’s just not a priority and using the SQLite database directly still works perfectly on the later OS versions, though I would really like to get the benefits of using Core Data. Ah well maybe version 1.1 of the application.

The wrapper is written in c++ as I felt it was more kind to the usage of the SQLite API plus I ended up move the core of the original project that the code came from over to c++ due to performance issues (it was doing a lot of work and an iPhone is not my macbook).

//
//  Database.h
//
//  Created by Robert on 20/07/2009.
//  Copyright 2009 Electric TopHat Ltd. All rights reserved.
//

#import
#import

// ---------------------------------------------
// Database Access Class
// ---------------------------------------------
class Database
{
#pragma mark ---------------------------------------------------------
#pragma mark === Constructor / Destructor Functions  ===
#pragma mark ---------------------------------------------------------
public: // Functions

// ---------------------------------------------
// Constructor
// ---------------------------------------------
Database( NSString * _name, NSString * _createString = nil );

// ---------------------------------------------
// Destructor
// ---------------------------------------------
~Database();

#pragma mark ---------------------------------------------------------
#pragma mark === End Constructor / Destructor Functions  ===
#pragma mark ---------------------------------------------------------

#pragma mark ---------------------------------------------------------
#pragma mark === Public Functions  ===
#pragma mark ---------------------------------------------------------
public:

// ---------------------------------------------
// execute a single sql statement
// ---------------------------------------------
Boolean execute( NSString * _sql, NSMutableArray * _results = nil );
Boolean execute( NSString * _sql, NSMutableDictionary * _result );
// ---------------------------------------------

// ---------------------------------------------
// Table has Column
// ---------------------------------------------
Boolean hasTableColumn( NSString * _tableName, NSString * _columnName );
Boolean tableColumns( NSString * _tableName, NSMutableArray * _results );
// ---------------------------------------------

// ---------------------------------------------
// Alter the table
// ---------------------------------------------
Boolean updateTable( NSString * create, NSString * insert, NSString * _name );
// ---------------------------------------------

// ---------------------------------------------
// Return the error string
// ---------------------------------------------
NSString * error() { return m_error; };
// ---------------------------------------------

#pragma mark ---------------------------------------------------------
#pragma mark === End Public Functions  ===
#pragma mark ---------------------------------------------------------

#pragma mark ---------------------------------------------------------
#pragma mark === Private Functions  ===
#pragma mark ---------------------------------------------------------
private: //Functions

Boolean createWithBundleDatabaseWithName(NSString* _name);
Boolean createAnEmptyDatabaseWithName(NSString* _name, NSString * _createStatement);

#pragma mark ---------------------------------------------------------
#pragma mark === End Private Functions  ===
#pragma mark ---------------------------------------------------------

#pragma mark ---------------------------------------------------------
#pragma mark === Protected Data  ===
#pragma mark ---------------------------------------------------------
protected: // Data

// -------------------------
// Error String
// -------------------------
NSString *		m_error;
// -------------------------

// -------------------------
// sql database
// -------------------------
sqlite3 *		m_database;
// -------------------------

#pragma mark ---------------------------------------------------------
#pragma mark === End Private Data  ===
#pragma mark ---------------------------------------------------------

};
// ---------------------------------------------

The above API is very simple or I hope it is. The basic idea is to provide a minimum wrapper round the core SQLite API though later on I did end up providing an additional helper function ‘updateTable‘. So what goes on?

Construction

The class constructor takes a ‘name‘ and an optional sql command, the ‘name’ is the name of the database file that will be created on disk. The first time you construct the database class it will first try to copy a database of the same name from your application bundle onto the disk, if the database file is not found in your bundle it will create one and optionally run an sql command (this can be used to create the desired table structure). The second time you construct the database class it will use the RW database contained in the applications working directory.

Execute

The class provides a very simple interface to run SQL commands, just create a string and call the execute command. You can optionally provide a mutable dictionary or a mutable array to return data from the database. Note that the array will contain a dictionary for each row provided and the key values are those requested in your sql statement  or the column name.

Helper Functions

The class provides a few little helper functions:

  • hasTableColumn : has the table got the column.
  • tableColumns : return all the table columns associated with a table.
  • updateTable : this can be used to make changes to your table (though I will need to document it more sorry).

WARNING : If you want to include c++ class’s in your project you must change the .m file extension to .mm this will inform the compiler that you are using Objective-C++ else you will get a lot of compile errors.

I’ve tried to keep it simple, so if you know how to write SQL statements and don’t want to worry about the low level API or C++ just scares you then hopefully this is for you. As always the code is as is and use it at your own risk, feel free to alter, hack or otherwise distribute the code and if you have any questions please feel free to get in touch.

Download : Database.hDatabase

Sample Project : SqliteDBWrapperSample

Thanks for reading.

iPhone Date Range Editor

February 19th, 2010 No comments

Date range editing is a useful when dealing with calendars or time periods, the iPhone calendar provides a nice simple way of editing a date range. Just open up the Calendar hit the + button and edit the events date range, you get a lovely screen that looks like the image below:



Calendar Date Rang Editor

Unfortunately UIkit does not provide a basic control to edit a date range editor, it does provide the UIDatePicker which can be used to build your own date range editor and this is what I have set about to do. The basic idea is to emulate the basic functionality implemented in the calendar date range editor, i.e. The start and end dates can be selected which in turn alters the date displayed in the UIDatePicker and the control provides basic error detection changing the start date red when invalid and prevent savings if there is an invalid date range.

The following is the result of my attempt to recreate this control in a simple and customisable way, the header file below is rather long but there are only a few items exposed to interface builder to make it easy to setup.

//
//  UIViewControllerDateRangeEditor.h
//  UIViewControllerDateRangeEditor
//

#import

@interface UIViewControllerDateRangeEditor : UIViewController
{
@private

// ----------------------------------------
// control objects
// ----------------------------------------
IBOutlet UIBarButtonItem *	leftBarButton;          // Navigation Button to be used on the left    : Cancel
IBOutlet UIBarButtonItem *	rightBarButton;      // Navigation Button to be used on the right  : Save
// ----------------------------------------

// ----------------------------------------
// Display Content
// ----------------------------------------
IBOutlet UILabel  *			startLabel;                   // start label : used for highlighting and is not altered
IBOutlet UILabel  *			startDate;                     // start date label : used for highlighting and contains the current start date

IBOutlet UILabel  *			endLabel;                     // end label : used for highlighting and is not altered
IBOutlet UILabel  *			endDate;                      // end date label : used for highlighting and contains the current end date
// ----------------------------------------

// ----------------------------------------
// control objects
// ----------------------------------------
IBOutlet UIDatePicker *		datePicker;       // date picker : link the value change to the dateChanged action
// ----------------------------------------

// ----------------------------------------
// Start Date Colors
// ----------------------------------------
UIColor *					normalColor;
UIColor *					highlightColor;
// ----------------------------------------

// ----------------------------------------
// Buttons
// ----------------------------------------
IBOutlet UIButton *			buttonStart;              // button that is to be highlighted at the start
UIButton *					buttonSelected;
UIImage  *					buttonImage;
// ----------------------------------------

// ----------------------------------------
// Date Formatter
// ----------------------------------------
NSDateFormatter *			dateFormatter;
// ----------------------------------------

// ----------------------------------------
// current dateValue
// ----------------------------------------
NSTimeInterval				startTimeInterval;
NSTimeInterval				endTimeInterval;

NSTimeInterval				minTimeInterval;
NSTimeInterval				maxTimeInterval;
// ----------------------------------------

// ----------------------------------------
Boolean						editingStartDate;
Boolean						savePressed;
Boolean						delayReset;
// ----------------------------------------
}

@property (nonatomic) NSTimeInterval startTimeInterval;
@property (nonatomic) NSTimeInterval endTimeInterval;

@property (nonatomic) NSTimeInterval minTimeInterval;
@property (nonatomic) NSTimeInterval maxTimeInterval;

@property (nonatomic, readonly) Boolean savePressed;

- (void) reset;

- (IBAction) cancel:(id)sender;
- (IBAction) save:(id)sender;

- (IBAction) dateChanged:(id)sender;

- (IBAction) selectStartDate:(id)sender;
- (IBAction) selectEndDate:(id)sender;

@end

The View controller provided with this article should permit you to create your own custom date range editor using interface builder, this can either be loaded manually or via the main nib. The sample project provide demonstrates how the view controller is setup and how you can use it in your own project.



Sample Images

Download : UIViewControllerDateRangeEditor.h, UIViewControllerDateRangeEditor.m

Sample Project : UIViewControllerDateRangeEditor

Example Usage :


// -------------------------------------------------------------------
// load  the date range editor and push it onto the view stack
// -------------------------------------------------------------------
- (IBAction) editDateRange:(id)sender
{
if ( editor == nil )
{
editor = [[UIViewControllerDateRangeEditor alloc] initWithNibName:@"UIViewControllerDateRangeEditor" bundle:nil];
editor.title = @"Edit";
}

editor.startTimeInterval = startTime;
editor.endTimeInterval   = endTime;

[[self navigationController] pushViewController:editor animated:TRUE];
}

// -------------------------------------------------------------------
// when the controller returns from the editor copy the date out if save has been
// pressed and reset the controller.
// -------------------------------------------------------------------
- (void) viewWillAppear:(BOOL)animated
{
if ( editor )
{
if ( editor.savePressed )
{
startTime = editor.startTimeInterval;
endTime = editor.endTimeInterval;
}

[editor reset];
}
}

As always the source is provided as is and use it at your own risk, feel free to alter and extend as you see fit. Have fun.

Loading from a nib

February 3rd, 2010 No comments

Interface builder is a great tool provide with the xCode and I make good use of it when building iPhone projects, if you are scared by this Tool please take the time to play or watch some of the many tutorials online. I started using during my first iPhone project and I have not looked back since. l usually build basic / functional user interfaces, then handing it over to a proper designer / artist to change coder art into a work of beauty. It has really helped our development process, as I can try and concentrate on product functionality and not worry so much about how it looks. Though there I must admit that there is always a bit of too and fro that must be done, as lots of things it is not a one way street.

In the past I’ve split a project into several nib’s each one containing a one or more views and a single Controller object, this permits functionality to be split and sectioned easily. Having multiple nibs also reduces the lightly hood of trashing others work and limit bugs to a particular area.

In the latest project I have had to take one step further where a nib can contain a single view, this permits the same view higher-archy to be constructed multiple times (such as for a table view).

It’s so easy to use nib’s and decode / load them multiple times. The usual way to load a nib is using the view controller function initWithNibName:bundle: but in some cases you don’t want to construct a view controller, you really only want the view. Well the easies way round that is to load the nib using the NSBundle, this will provide an array of constructed objects (UIView, NSObjects, etc). This is really simple as the code below demonstrates.

// -----------------------------------------------------
// Load the first view from the nib
// -----------------------------------------------------
+ (UIView*) loadFirstViewFromNibName:(NSString*)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
	NSBundle * bundle = ( nibBundleOrNil ) ? nibBundleOrNil : [NSBundle mainBundle];
	NSArray * nib = [bundle loadNibNamed:nibNameOrNil owner:self options:nil];

	for ( NSObject * obj in nib )
	{
		if ( [obj isKindOfClass:[UIView class]] )
		{
			return (UIView*)obj;
		}
	}

	return nil;
}

Note : You will still need to retain the returned object.

Loading stuff from a nib in this way has great potential, I use this method to load individual UINavigationControllers when I want to branch the navigation off and return to the same point in the previous navigation controller. You branch of like this using the presentModalViewController function and dismissModalViewControllerAnimated to return. The code snippet below shows the simple alteration need to load a navigation controller.

// -----------------------------------------------------
// Load the first navigation controller from the nib
// -----------------------------------------------------
+ (UINavigationController*) loadNavigationControllerFromNibName:(NSString*)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
	NSBundle * bundle = ( nibBundleOrNil ) ? nibBundleOrNil : [NSBundle mainBundle];
	NSArray * nib = [bundle loadNibNamed:nibNameOrNil owner:self options:nil];

	for ( NSObject * obj in nib )
	{
		if ( [obj isKindOfClass:[UINavigationController class]] )
		{
			return (UINavigationController*)obj;
		}
	}

	return nil;
}

Just some small code snips this time, but as always please feel free to use and alter as you see fit. If you have any questions please leave a comment or get in touch by other means. Thanks.

Full Screen Animator for a UIImageView

January 21st, 2010 2 comments

The UIImageView provided by UIKit is a very useful class, it provides a very simple way to add Images into a View hierarchy. It also provides a basic way to provide texture animation, though it does have it’s limitations. 1) you have to load all the images up front, which is fine for a bunch of small images but you don’t really want to do that for fullscreen animations with more than 10 frames. You will start to run low on memory and if you are unable to free enough memory to OS will kill your application. 2) there is no callback support provided when using the UIImageView animations, all you can do is start / stop and check to see if it is animating. If you want to do anything else you need to create your own timer and hope that you get the timing right. The following code is to try and build upon the UIImageView and provide a simple way to add full screen texture animations to your project and have the ability to receive callbacks when an animation starts / stops and when a frame changed.

The UIImageView provides the following API for texture animation:

startAnimating
Starts animating the images in the receiver.

- (void)startAnimating

stopAnimating
Stops animating the images in the receiver.

- (void)stopAnimating

isAnimating
Returns a Boolean value indicating whether the animation is running.

- (BOOL)isAnimating

animationDuration
The amount of time it takes to go through one cycle of the images.

@property(nonatomic) NSTimeInterval animationDuration

animationImages
An array of UIImage objects to use for an animation.

@property(nonatomic, copy) NSArray *animationImages

animationRepeatCount
Specifies the number of times to repeat the animation.

@property(nonatomic) NSInteger animationRepeatCount

So how do you use it? Apples developers have made it really simple, load an array UIImages. Add the image array into the UIImageView via the animationImages property, set the animations total duration. Insert the View into the hierarchy if it’s not already in there and start the animation using the function startAnimating. Simple and easy, I wanted to provide some thing similar and I copied the provided APU and add the extra functionality I wanted, such as callbacks.

UIImageViewAnimator header file:

//
//  UIImageViewAnimator.h
//
//  Created on 16/01/2010.
//

#import <UIKit/UIKit.h>

@interface UIImageViewAnimator : UIView
{
@private
// Image View to Animate.
IBOutlet UIImageView *	imageview;

// Timer
NSTimer *				animtimer;
// Array of Image Names
NSArray *				imageNames;
// Current Animation Index
NSInteger				index;
// Animation Duration
NSTimeInterval			duration;

id						context;
id						delegate;
SEL						frameChangeSelector;
SEL						startSelector;
SEL						stopSelector;

Boolean					cacheImages;
Boolean					reverse;
Boolean					imageset;
}

@property (nonatomic)			NSInteger		index;
@property (nonatomic,readonly)	NSInteger		count;
@property (nonatomic,copy)		NSArray *		imageNames;
@property (nonatomic)			NSTimeInterval	duration;
@property (nonatomic)			Boolean			cacheImages;
@property (nonatomic)			Boolean			reverse;

@property (nonatomic,retain)	id				delegate;
@property (nonatomic)			SEL				startSelector;
@property (nonatomic)			SEL				stopSelector;
@property (nonatomic)			SEL				frameChangeSelector;

- (void) startAnimating;
- (void) startAnimatingWithContext:(id)_context;
- (void) stopAnimating;
- (Boolean) isAnimating;

- (void) precache;

@end

The big difference between the two implementations is that you provide an array of Image Names rather than an array of UIImage’s, this will let the underlying animation code dynamically load the images as they are needed reducing the amount of memory used and decreasing the lightly hood of running out of memory. There is also an extra startAnimating that takes a context or user data object, this will be stored and passed back to the callbacks, the callbacks are called (if provided, they are optional) when the animation is started / stopped and when a frame has been incremented.

Caching:
The code provides two ways of loading images, the caching system uses the [UIImage NamesImage:@"name"] function, this provides a texture cache provided by UIKit if we start to run low on resources the OS will automatically flush some of the images that are not being used. The non-caching system uses the [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@”name” ofType:nil] function this will by pass the OS image cache and when the image is released it’s memory will also be freed. I think that at some point I want to implement a better of doing this.

The code implementation is in no way perfect and really could do with a bit more work, but it has been implemented to meet my needs. Feel free to extend and re-work it as much as you like I have a few changes that I would really like to make but time as always is against me.

Download : UIImageViewAnimator.h, UIImageViewAnimator.m

Sample Project : UIImageViewAnimatorSample

Example Use :

// This sample code and may not compile as it is.

// Fill the animator with the image list
- (void) createAnimation
{
      NSMutableArray * dataset = [NSMutableArray arrayWithCapacity:20];
      for ( int i=0; i<20; i++ )
      {
            NSString * imageName = [NSString stringWithFormat:@"animationImageName%d.png",i];
            [dataset addObject:imageName];
      }

      // image animator constructed inside a nib
      [imageAnimator setImageNames:dataset];

      // set the duration to show the 20 images in 2 seconds
      // thats 1 every tenth of a seconds, though it may be
      // slower due to having to load each individual image.
      [imageAnimator setDuration:2];

      // This will use a different loading function
      // where the OS will try and keep as much
      // of the image data in memory as possible.
      // It may improve the speed of the second
      // playback.
      [imageAnimator setCacheImages:TRUE];

      // Setup the delegates and callbacks
      [imageAnimator setDelegate:self];
      [imageAnimator setStartSelector:@selector(start:)];
      [imageAnimator setStopSelector:@selector(stop:)];
}

- (void) start:(id)_context
{
       NSLog( @"Animation playback has been triggered" );
}

- (void) stop:(id)_context
{
       NSLog( @"Animation playback has finished" );
}

- (void) playAnimation
{
        // If the animation has a few images
        // you can try to pre load all the images
        // this will proved a faster/smoother
        // animation as they will be resident
       // in main memory.
       //[imageAnimator preCache];

       // Reverse will permit you to
       // play the animation backwards
       // Note : You will need to set the
       // index to be the last frame to
       // make use of this feature.
       //[imageAnimator setIndex:[imageAnimator count]-1];
       //[imageAnimator setReverse:TRUE];

       // start the animation playing
       [imageAnimator startAnimating];
}

Note : The current implementation requires the animator to be constructed and setup via Interface Builder. The simplest way to do is change the root views class to be that of the UIImageViewAnimator, add a UIImageView into the high-archy and link the image view to the animator.

Extending the UIModal Transitions

January 8th, 2010 No comments

On of the nice things about the UINavigationController is that it will keep track of the view controllers that have been presented which in turn permits the application to dismiss a controller and return to the previous one. The only problem I faced was was altering the transition animations being used to present and dismiss the views. This is not such a big problem when using OS3.0 and above as Apple have now provided a property to change transition animation, though it is a bit limited (see below):

modalTransitionStyle
The transition style to use when presenting the current view controller modally.

@property (nonatomic, assign) UIModalTransitionStyle modalTransitionStyle

UIModalTransitionStyleCoverVertical
When the view controller is presented, its view slides up from the bottom of the screen. On dismissal, the view slides back down. This is the default transition style.

UIModalTransitionStyleFlipHorizontal
When the view controller is presented, the current view initiates a horizontal 3D flip from right-to-left, resulting in the revealing of the new view as if it were on the back of the previous view. On dismissal, the flip occurs from left-to-right, returning to the original view.

UIModalTransitionStyleCrossDissolve
When the view controller is presented, the current view fades out while the new view fades in at the same time. On dismissal, a similar type of cross-fade is used to return to the original view.

There are more transition animations provided by the OS, these have been available to users for OS2.0, so why not support them as well? Another problem is lack of support for altering these animations OS versions prior to OS3.0.

What I really wanted was the ability to play any of the transition provided by the OS and that the transitions to be the same no matter what version the OS the user was running and that’s what I set out to create.

The first question I had was where to put the code? It had to be easily available to my derived View Controllers and also be easy to remove. There where a couple of options 1) derive a new class off the UIViewController and inherit form that or 2) extend the UIViewController provided by UIKit. One of the nice features of Objective-C (if you don’t know) is the ability to extend a class’s functionality, providing an easy way to integrate code into a class even if you don’t have the original source code. I picked the later method as it would permit the additional code to be available to any of the UIViewControllers in my project all I had to do was include the extended class’s header in the .m file and the code could be used.

Below is the header file that I created to extend the UIKit UIViewController:

//
//  UIViewController-Extended.h
//
//  Created by Robert on 17/12/2009.
//

#import <UIKit/UIKit.h>

typedef enum
{
UIViewControllerAnimationTransitionNone = 0,
UIViewControllerAnimationTransitionFade,
UIViewControllerAnimationTransitionPushFromTop,
UIViewControllerAnimationTransitionPushFromRight,
UIViewControllerAnimationTransitionPushFromBottom,
UIViewControllerAnimationTransitionPushFromLeft,
UIViewControllerAnimationTransitionMoveInFromTop,
UIViewControllerAnimationTransitionMoveInFromRight,
UIViewControllerAnimationTransitionMoveInFromBottom,
UIViewControllerAnimationTransitionMoveInFromLeft,
UIViewControllerAnimationTransitionRevealFromTop,
UIViewControllerAnimationTransitionRevealFromRight,
UIViewControllerAnimationTransitionRevealFromBottom,
UIViewControllerAnimationTransitionRevealFromLeft,

UIViewControllerAnimationTransitionFlipFromLeft,
UIViewControllerAnimationTransitionFlipFromRight,
UIViewControllerAnimationTransitionCurlUp,
UIViewControllerAnimationTransitionCurlDown,
} UIViewControllerAnimationTransition;

@interface UIViewController (UIViewController_Expanded)

- (void)dismissModalViewControllerWithAnimatedTransition:(UIViewControllerAnimationTransition)transition;
- (void)presentModalViewController:(UIViewController*)viewController withAnimatedTransition:(UIViewControllerAnimationTransition)transition;

- (void)dismissModalViewControllerWithAnimatedTransition:(UIViewControllerAnimationTransition)transition WithDuration:(float)duration;
- (void)presentModalViewController:(UIViewController*)viewController withAnimatedTransition:(UIViewControllerAnimationTransition)transition WithDuration:(float)duration;

@end

The class interface is very simple, there is a list of the supported transition (these are all available) and four functions that are used invoke these transitions. Two functions to Present a modal and two to dismiss, unfortunately Objective -C does not support default function variables like c++ (correct me if I’m wrong) which is the reason for four functions where I would rather have two.

The class implementation is not as tidy (please feel to improve it) but it works, I’ve tested it on both OS3.0 / OS2.2 and have run into no issues as yet. The only real problem I have with it is that I have to turn views bounds clipping off,  this was so that the UINavigationBar was displayed. If you don’t use a naviagion bar you can remove that code.

Example use:

//
//  CustomViewController.m
//

#import "CustomViewController.h"
#import "UIViewController-Extended.h"

@implementation CustomViewController

...

// -------------------------------------------------------------------
// display the setup view controller
// -------------------------------------------------------------------
- (IBAction) displaySetupPage:(id)_sender
{
if ( setupController == nil )
{
setupController = [[CustomSetupController alloc] initWithNibName:@"Setup" bundle:nil];
}

[self presentModalViewController:controller withAnimatedTransition:UIViewControllerAnimationTransitionFlipFromRight];
}

...

@end

As always the source is provided as is and use it at your own risk, feel free to alter and extend as you see fit. Have fun.

Download : UIViewController-Extended.h, UIViewController-Extended.m

Sample Project : UIModuleTransitionSample

iPhone YouTubePlayer

December 18th, 2009 No comments

youtubeI’ve been plodding away on a project (it’s getting there almost) and one of the things that I really wanted was to provide video tutorials for the user. I really don’t want to package all these videos with the application, really once you’ve watched them once you will probably never look at them again (If I’m wrong about that let me know ).

The new idea is to stream them down to the device, once option was to use the MoviePlayer provided with the sdk. This is fine if you want to host your own video content, but I’m not that confident that I would be able to provide a reliable content service. Whats the alternative then, well there is always  YouTube and the iPhone has a compatible way of playing back videos even inside the application. Unfortunately to play these YouTube videos you need to use a UIWebView where the simplest version of a player would present the user with a link to play the video. Not the most elegant solution but it works, but I was not really happy with the solution.

I decided I could do better, I really wanted a player that provided complete application integration and the resulting Player is just that. The player is easy to use and has simplest API I could come up with, it’s also very easy to integrate with any application. Go on and try it out.

//
//  YouTubePlayer.h
//
//  Created by Robert on 18/12/2009.
//

#import <Foundation/Foundation.h>

@interface YouTubePlayer : NSObject <UIWebViewDelegate, UIAlertViewDelegate>
{
@private
	UIView	  *				  background;
	UIWebView *				  webView;
	UIActivityIndicatorView * activityIndicator;
}

- (void) playbackVideo:(NSString*)_videoID InView:(UIView*)_view;

@end

Example use:

// Inside a UIViewController
- (void) play
{
     // create the video player object
     if ( videoPlayer == nil )
     {
           videoPlayer = [[YouTubePlayer alloc] init];
     }

    // Request the video to be played using the video id
     [videoPlayer playbackVideo:@"MuU00Q3RhDg" InView:self.view];
}

As always the source is provided as is and use at your own risk, also feel free to alter and use as you want I don’t mind. Have Fun.

Download : YouTubePlayer.h, YouTubePlayer.m

Note: You will need to include the SystemConfiguration framework as this is used to check for the availability of a web connection.

Thanks to the following resources that make it possible to build this player:

BSC Presentation ReWork

December 2nd, 2009 No comments






Ok it’s taken some time to get to this stage but I have finally gotten around to getting the BSC Presentation up a onto YouTube, It’s still not finished as I really want to go through and annotate it but it’s a start. :) Thanks..

Line Graph

November 17th, 2009 No comments

linegraph I did some work a couple of weekends ago where I implemented a basic line graph view for the iPhone, the code is now up and available. I don’t think it’s the best implementation in the world and it sure as hell could do with some improvement, but I think that of all the code I write :) Oh well the current implementation works for me at this time, but feel free to grab the code and alter it to your own needs.

Categories: Code Tags: , , ,

BCS Presentation : A short Video

November 6th, 2009 1 comment


Above is a short video showing how easy it is to build a very simple iPhone application using xCode and Interface builder.

Categories: Life Tags: , ,

Movember

November 3rd, 2009 No comments

I am growing a moustache this year for Movember.  I have decided to put pickup my razor for one month (November) and help raise awareness and funds for men’s health – specifically prostate cancer.

What many people don’t appreciate is that one man dies every hour of prostate cancer in the UK, more than 35,000 men will be diagnosed this year and that prostate cancer is the most common cancer in men in the UK.  Facts like these have convinced me I should get involved and I am hoping that you will support me.

To donate to my Mo, you can either:

•    Click this link http://uk.movember.com/mospace/230163/ and donate online using your credit card, debit card or PayPal account
•    Write a cheque payable to ‘The Prostate Cancer Charity – Movember’, referencing my Registration Number and mailing it to: Movember – The Prostate Cancer Charity, First Floor, Cambridge House, Cambridge Grove, London, W6 0LE.

Movember is now in its third year here in the UK  and, to date, has achieved some pretty amazing results by working alongside The Prostate Cancer Charity.  Check out further details at: http://uk.movemberfoundation.com/research-and-programs.

If you are interested in following the progress of my Mo, click here http://uk.movember.com/mospace/230163/. Also, http://uk.movember.com has heaps of useful information.

Thank you

Categories: Life Tags: