Posted by: bearc0025 | February 6, 2010

Sort an Array of Custom Objects

When you have an array of custom objects (e.g., managed objects) and you don’t have a standard compare method to use or the ability to write one (i.e., will get overwritten if you recreate the class), you can use this technique to sort the objects based on a key-value (e.g., “name” below)…


NSSortDescriptor *sortDescriptor = [[[NSSortDescriptor alloc]
  initWithKey:@"name" ascending:YES] autorelease];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
NSArray *sortedArray =
  [todaysPRs sortedArrayUsingDescriptors:sortDescriptors];

Upon first glance, the UIButton class doesn’t seem to provide what you might expect in terms of customization. This often causes developers to resort to creating buttons in an image editor and then specifying that in the Background field in Interface Builder. This is a fine solution and will likely give you what you need, but with Core Animation layers there is a simpler way to achieve the look you want without having to create an image. This post will demonstrate how.

via Cocoa Is My Girlfriend » Fun With UIButtons and Core Animation Layers.

Posted by: bearc0025 | January 31, 2010

Dallas Morning News Business Section Article

I was interviewed recently for an article in the Dallas Morning News Business section about iPhone app development. The angle was more from the business/prospect side of things – no so much technical.

It was a fun interview and very cool meeting the photographer Michael Ainsworth.

You can read the article at the Dallas Morning News site. There’s no pics there though.

Dallas Morning News article (click to enlarge)

Dallas Morning News article (click to enlarge)

Posted by: bearc0025 | January 18, 2010

iPhone CoreData Automatic Light Migration

This post is pieced together from these 3 sources:

So there’s basically 3 steps to do (BEFORE you change your xcdatamodel file):

1. Set the Persistent Store options for automatic migration:

Change your persistentStoreCoordinator creation to this (replace YOURDB):

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {

  if (persistentStoreCoordinator != nil) {
    return persistentStoreCoordinator;
  }

  NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"YOURDB.sqlite"]];

  // handle db upgrade
  NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
  [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
  [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];

  NSError *error = nil;
  persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]];
  if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) {
    // Handle error
  }

  return persistentStoreCoordinator;
}

2. Version your Data Model and Edit the new file

  1. Select your xcdatamodel file
  2. Design->Data Model->Add Model Version (expand your xcdatamodeld item)
  3. Select the “2″ (or later) file, Design->Data Model->Set Current Version (edit this version)

3. Specify the momd resource

Change your managedObjectModel implementation to this (replace YOURRESOURCENAME)…

- (NSManagedObjectModel *)managedObjectModel {

  if (managedObjectModel != nil) {
    return managedObjectModel;
  }

  NSString *path = [[NSBundle mainBundle] pathForResource:@"YOURRESOURCENAME" ofType:@"momd"];
  NSURL *momURL = [NSURL fileURLWithPath:path];
  managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:momURL];

  return managedObjectModel;
}

Build and run!

Posted by: bearc0025 | January 16, 2010

Getting iPhone App Promo Codes for iTunes

Here’s the steps to getting promotional codes for your iPhone app:

  1. Log into iTunes Connect
  2. Select “Request Promotional Codes”
  3. Select the app by name from the drop-down list and enter the number of codes you want (see image below)
  4. Click “Continue” and agree to the conditions.

You can then download the codes on the next page. Also, the codes will be emailed to you in a pdf file.

App Selection for Promo Codes (click to enlarge)

App Selection for Promo Codes (click to enlarge)

Posted by: bearc0025 | January 13, 2010

PixelPressIcons » Icons: Free iPhone Toolbar Icons

PixelPressIcons » Icons: Free iPhone Toolbar Icons.

Some really good icons for free and more for sale.

Posted by: bearc0025 | January 7, 2010

Detecting taps and events on UIWebView

Detecting taps and events on UIWebView – The right way

I recently have had to figure out how to interact w/ the UIWebView in ways I didn’t think possible.

I’ve figured out how to highlight text in various colors, search text, insert local images, intercept link loads, get the user-selected text, get/set the scroll position, etc. Most of it was done at least in part w/ javascript.

However, this wd all be much easier if, like other views, it cd be subclassed and the touches intercepted. Not so much.

Well, here’s one alternative – I haven’t tried it, but I wanted to post it here for future reference and in congratulations of the developer…

Detecting taps and events on UIWebView – The right way « The Spoken Word.

Posted by: bearc0025 | January 5, 2010

MapKit Crash getting User Location

I started getting this crash – only on ad hoc builds – not sim, not debug device builds (from Xcode Organizer)…

Exception Type:  EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x00000000
Crashed Thread:  0

Thread 0 Crashed:
0   libobjc.A.dylib               	0x00003ec0 objc_msgSend + 24
1   MapKit                        	0x00032960 -[MKMapView(UserPositioningInternal) locationManagerUpdatedLocation:] + 1032
2   CoreFoundation                	0x0005da0e -[NSObject performSelector:withObject:] + 18
3   CoreFoundation                	0x00062a04 -[NSArray makeObjectsPerformSelector:withObject:] + 368
4   MapKit                        	0x000028e8 -[MKLocationManager _reportLocationStatus:] + 52
5   MapKit                        	0x00004e74 -[MKLocationManager _reportLocationSuccess] + 48
6   MapKit                        	0x000049c0 -[MKLocationManager locationManager:didUpdateToLocation:fromLocation:usingSupportInfo:] + 936
7   CoreLocation                  	0x00009af4 -[CLLocationManager onClientEventLocation:] + 1132
8   CoreLocation                  	0x00008020 -[CLLocationManager onClientEvent:supportInfo:] + 140
9   CoreLocation                  	0x000081ac OnClientEventInternal + 24
10  CoreLocation                  	0x00005e48 CLClientHandleDaemonData(__CFMessagePort*, long, __CFData const*, void*) + 1080
11  CoreFoundation                	0x00030380 __CFMessagePortPerform + 112
12  CoreFoundation                	0x00057524 CFRunLoopRunSpecific + 2296
13  CoreFoundation                	0x00056c18 CFRunLoopRunInMode + 44
14  GraphicsServices              	0x0000436c GSEventRunModal + 188

The problem seemed to be the MKMapView getting deallocated w/o remove the delegate.

I added a call to set the delegate to nil in my dealloc method and things worked.

I wonder why a) this isn’t a problem for other classes and/or b) does the IB backend handle setting other classes delegate’s to nil?

Posted by: bearc0025 | January 5, 2010

Display a local/bundle image in UIWebView

I have local XML files I’m displaying in a UIWebView but I need to add images into the text to display. The images are local to the app so they’re in the bundle.

	NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
	NSURL *bundlePathURL = [NSURL fileURLWithPath:bundlePath];
	[super loadHTMLString:contents baseURL:bundlePathURL];

Then you can reference the images directly in your HTML like…

<img src="image.png"/>
Posted by: bearc0025 | December 30, 2009

Accessing Info.plist within your iPhone App

I needed to access the app name w/in my app. I figured I cd get it from the Info.plist display name or executable. Yep.

See all the values w/ this (print out below)…

	NSLog(@"%@", [[NSBundle mainBundle] infoDictionary]);

Or get a single value w/ this…

	NSString *exeName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];

You can get the dictionary key names from the plist file in Xcode. Just set the view to show the raw key names…

Set Raw Key Names in Xcode (click to enlarge)

Set Raw Key Names in Xcode (click to enlarge)

The raw key names…

Raw Key Names (click to enlarge)

Raw Key Names (click to enlarge)

Print out the dictionary…

2009-12-30 10:52:09.948 MyApp [32400:207] {
    CFBundleDevelopmentRegion = English;
    CFBundleDisplayName = MyApp;
    CFBundleExecutable = MyApp;
    CFBundleExecutablePath = "/Users/bear/Library/Application Support/iPhone Simulator/User/Applications/722BFAB7-9A59-4282-A0EF-BD5675B44FE8/MyApp.app/MyApp";
    CFBundleIdentifier = "com.yourcompany.MyApp";
    CFBundleInfoDictionaryVersion = "6.0";
    CFBundleInfoPlistURL = Info.plist -- file://localhost/Users/bear/Library/Application%20Support/iPhone%20Simulator/User/Applications/722BFAB7-9A59-4282-A0EF-BD5675B44FE8/MyApp.app/;
    CFBundleName = MyApp;
    CFBundlePackageType = APPL;
    CFBundleSignature = "????";
    CFBundleSupportedPlatforms =     (
        iPhoneSimulator
    );
    CFBundleVersion = "1.0";
    DTPlatformName = iphonesimulator;
    DTSDKName = "iphonesimulator3.1.2";
    LSRequiresIPhoneOS = 1;
    NSBundleInitialPath = "/Users/bear/Library/Application Support/iPhone Simulator/User/Applications/722BFAB7-9A59-4282-A0EF-BD5675B44FE8/MyApp.app";
    NSBundleResolvedPath = "/Users/bear/Library/Application Support/iPhone Simulator/User/Applications/722BFAB7-9A59-4282-A0EF-BD5675B44FE8/MyApp.app";
    NSMainNibFile = MainWindow;
}

Older Posts »

Categories