Aug 27 2010

Disable deprecated warnings with GCC

Recently I wrote some conditional code to call various methods depending on the version of iOS running on the device. A problem I came across was that because I still called some deprecated methods I was getting warnings during my build. As I treat all warnings as errors I had to find a solution which would compile. #pragma was the answer.

You can use the following line to disable warnings for depreciated calls:

#pragma GCC diagnostic ignored "-Wdeprecated-declarations"

And use this to re-enable it:

#pragma GCC diagnostic warning "-Wdeprecated-declarations"

Here’s how I used it:

#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
- (id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier
{
  if([super respondsToSelector:@selector(initWithStyle:reuseIdentifier:)])
  {
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
      [self setupCell];
    }
  }
  else
  {
    if(self = [super initWithFrame:CGRectZero reuseIdentifier:reuseIdentifier])
    {
      [self setupCell];
    }
  }
  return self;
}
#pragma GCC diagnostic warning "-Wdeprecated-declarations"

Mar 13 2010

F1 Insider in the Paid App charts!

F1 Insider, one of my apps (currently published by Greenius Mobile), is in the top 50 UK paid apps! We’re also sat in #2 in the UK sports charts.

Other territories are starting to catch up too. A great way to start the season!

I also have a major update in the works, which should bring some nice new features, and help make F1 Insider the #1 independent F1 app.

Thanks to everyone for their support!

Check the app out here: http://www.f1insider.co.uk/download/


Mar 11 2010

UIImage resizing

UIImage is a great class, but it has a lot of limitations.

Image resizing is one of them (the lack of). If your looking for a way to re-size UIImages, save your self the agony of copy/pasting the numerous code examples you’ll find through stackoverflow or whatever. I was shocked by the amount of people posting buggy code, for what is actually a relatively simple problem.

I do find it funny that people describe CoreGraphics or Quartz as low level APIs. For a primarily Objective-C coder maybe, but for anyone who has experience with C, it shouldn’t pose much of a burden. Sure CoreGraphics IS lower level than UIImage, but I’d still describe it as a fairly “high level” API, especially when you compare it to OpenGL.

Anyhow, if your looking to re-size UIImages easily, without having to use CoreGraphics or Quartz, I would strongly recommend checking out Trevor’s article over here:

http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/

He has written some UIImage categories which will save a lot of time, and more importantly they are well written (and work).


Mar 10 2010

Approval times improved

Since the new year Apple appears to be making massive improvements to their overall approval times. An update for F1 Insider was approved in about 48 – 72 hours, which we had previously planned for 1 – 2 weeks!

Very good job, I hope it continues.

Now we just need to get some consistency in the approval/rejection guidelines :)


Jan 12 2010

The application does not have a valid signature

Had a frustrating issue this weekend with one of my Xcode projects. I’ve been working with this project for months, without problems, and then suddenly the application won’t install onto the Simulator, and when ran onto the device, I’m greeted with the error: “The application does not have a valid signature.”

Note this is not the same as the more common invalid provisioning profile error. I of course, googled my problem with the error message, but to my surprise found very little of anyone else with the same problem.

After a slow process of elimination, I finally tracked down the problem.

In my application, the directory structure of the resource files is very important. Added folders with the default option in Xcode, adds them as a group, and in the resulting application, all the files are copied into the top directory. This creates problems with you have files which share the same name, in different directories.

The solution to this is of course use reference folders (the second option you can select when added files to the project).

This is all fine and dandy, but what caused my Xcode project to go haywire, was the fact that my reference folder was called “resources”. The solution, was simply to rename the folder to “resource” (or anything else in fact), and after a clean, it works.

Very very strange error, but thankfully with an easy fix, once you know how!


Dec 2 2009

Customisable UIPageControl

PageControl Examples

PageControl Examples


The UIPageControl has no way of changing the colors of the dots. Kind of annoying right? Well I knocked up a simple solution to customising the look of the UIPageControl.

This class allows you to replace the dots with your own UIImages, with the following 2 properties:

@property (nonatomic, readwrite, retain) UIImage* imageNormal;
@property (nonatomic, readwrite, retain) UIImage* imageCurrent;

It works by replacing the UIImage on the UIImageView containing the original dot.

One word of warning, if Apple change the way the UIPageControl works, this code will most likely break (especially if they change the dots so they are no longer UIImageViews!). However I’d say the only reason this would happen, is if they add their own functionality in to customise the look of it, so it’s probably OK.

Here’s the full code, in all it’s glory. Feel free to use how you see fit (I’m releasing this with no restrictions). It’s not very complicated, but I figured it might be useful to someone!

#import <UIKit/UIKit.h>
 
@interface OMPageControl : UIPageControl {
  UIImage* mImageNormal;
  UIImage* mImageCurrent;
}
 
@property (nonatomic, readwrite, retain) UIImage* imageNormal;
@property (nonatomic, readwrite, retain) UIImage* imageCurrent;
 
@end
#import "OMPageControl.h"
 
@interface OMPageControl (Private)
- (void) updateDots;
@end
 
 
@implementation OMPageControl
 
@synthesize imageNormal = mImageNormal;
@synthesize imageCurrent = mImageCurrent;
 
- (void) dealloc
{
  [mImageNormal release], mImageNormal = nil;
  [mImageCurrent release], mImageCurrent = nil;
 
	[super dealloc];
}
 
 
/** override to update dots */
- (void) setCurrentPage:(NSInteger)currentPage
{
  [super setCurrentPage:currentPage];
 
  // update dot views
  [self updateDots];
}
 
/** override to update dots */
- (void) updateCurrentPageDisplay
{
  [super updateCurrentPageDisplay];
 
  // update dot views
  [self updateDots];
}
 
/** Override setImageNormal */
- (void) setImageNormal:(UIImage*)image
{
  [mImageNormal release];
  mImageNormal = [image retain];
 
  // update dot views
  [self updateDots];
}
 
/** Override setImageCurrent */
- (void) setImageCurrent:(UIImage*)image
{
  [mImageCurrent release];
  mImageCurrent = [image retain];
 
  // update dot views
  [self updateDots];
}
 
/** Override to fix when dots are directly clicked */
- (void) endTrackingWithTouch:(UITouch*)touch withEvent:(UIEvent*)event 
{
  [super endTrackingWithTouch:touch withEvent:event];
 
  [self updateDots];
}
 
#pragma mark - (Private)
 
- (void) updateDots
{
  if(mImageCurrent || mImageNormal)
  {
    // Get subviews
    NSArray* dotViews = self.subviews;
    for(int i = 0; i < dotViews.count; ++i)
    {
      UIImageView* dot = [dotViews objectAtIndex:i];
      // Set image
      dot.image = (i == self.currentPage) ? mImageCurrent : mImageNormal;
    }
  }
}
 
@end