Get iTunes Artwork for Current Song with ScriptingBridge - objective-c

I have been trying to figure out how to get the iTunes artwork for the currently playing song with scripting bridge. I have gotten to a point where it works for some songs, but for others, I get a SIGABRT. I'm not sure what the issue could be, so any help would be greatly appreciated. Here is what I have so far:
iTunesApplication * iTunes = [SBApplication applicationWithBundleIdentifier:#"com.apple.iTunes"];
NSImage *songArtwork;
iTunesTrack *current = [iTunes currentTrack];
iTunesArtwork *artwork = (iTunesArtwork *)[[[current artworks] get] lastObject];
if(artwork != nil)
songArtwork = [artwork data];
else
songArtwork = [NSImage imageNamed:#"Image.tiff"];
NSMenuItem *artworkMenuItem = [[NSMenuItem alloc] initWithTitle:#"" action:NULL keyEquivalent:#""];
[songArtwork setSize:NSMakeSize(128, 128)];
[artworkMenuItem setImage:songArtwork];
[Menu insertItem:artworkMenuItem atIndex:0];
I for some songs it works, and displays the artwork nicely in the menu item, but for others I get a SIGABRT on the line:
[songArtwork setSize:NSMakeSize(128, 128)];
The output of the console is as follows:
2011-08-12 23:13:20.094 SongViewer[2146:707] -[NSAppleEventDescriptor setSize:]: unrecognized selector sent to instance 0x102827f70
2011-08-12 23:13:20.095 SongViewer[2146:707] An uncaught exception was raised
2011-08-12 23:13:20.096 SongViewer[2146:707] -[NSAppleEventDescriptor setSize:]: unrecognized selector sent to instance 0x102827f70
2011-08-12 23:13:20.097 SongViewer[2146:707] (
0 CoreFoundation 0x00007fff86f11986 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff8b04cd5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff86f9d5ae -[NSObject doesNotRecognizeSelector:] + 190
3 CoreFoundation 0x00007fff86efe803 ___forwarding___ + 371
4 CoreFoundation 0x00007fff86efe618 _CF_forwarding_prep_0 + 232
5 SongViewer 0x0000000100002a83 -[IPMenulet awakeFromNib] + 4483
6 CoreFoundation 0x00007fff86f089e1 -[NSObject performSelector:] + 49
7 CoreFoundation 0x00007fff86f08962 -[NSSet makeObjectsPerformSelector:] + 274
8 AppKit 0x00007fff8d9d9c27 -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 1245
9 AppKit 0x00007fff8d9d01b9 loadNib + 322
10 AppKit 0x00007fff8d9cf6b6 +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:] + 217
11 AppKit 0x00007fff8d9cf5d1 +[NSBundle(NSNibLoading) loadNibFile:externalNameTable:withZone:] + 141
12 AppKit 0x00007fff8d9cf514 +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 364
13 AppKit 0x00007fff8dc42355 NSApplicationMain + 398
14 SongViewer 0x0000000100001882 main + 34
15 SongViewer 0x0000000100001854 start + 52
)
2011-08-12 23:13:20.098 SongViewer[2146:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSAppleEventDescriptor setSize:]: unrecognized selector sent to instance 0x102827f70'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff86f11986 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff8b04cd5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff86f9d5ae -[NSObject doesNotRecognizeSelector:] + 190
3 CoreFoundation 0x00007fff86efe803 ___forwarding___ + 371
4 CoreFoundation 0x00007fff86efe618 _CF_forwarding_prep_0 + 232
5 SongViewer 0x0000000100002a83 -[IPMenulet awakeFromNib] + 4483
6 CoreFoundation 0x00007fff86f089e1 -[NSObject performSelector:] + 49
7 CoreFoundation 0x00007fff86f08962 -[NSSet makeObjectsPerformSelector:] + 274
8 AppKit 0x00007fff8d9d9c27 -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 1245
9 AppKit 0x00007fff8d9d01b9 loadNib + 322
10 AppKit 0x00007fff8d9cf6b6 +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:] + 217
11 AppKit 0x00007fff8d9cf5d1 +[NSBundle(NSNibLoading) loadNibFile:externalNameTable:withZone:] + 141
12 AppKit 0x00007fff8d9cf514 +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 364
13 AppKit 0x00007fff8dc42355 NSApplicationMain + 398
14 SongViewer 0x0000000100001882 main + 34
15 SongViewer 0x0000000100001854 start + 52
)
terminate called throwing an exception(gdb)
If anyone has any idea what could be wrong, please let me know!!

Ok so I figured it out. The solution is to use the NSData raw data provided by the API rather than the NSImage. So I used:
NSImage *songArtwork = [[NSImage alloc] initWithData:[artwork rawData]];
rather than
songArtwork = [artwork data];

I have to fetch batch of track artworks from iTunes and use ‘rawData’ too.
But this way is inefficient.
I found a better way (actually it decreases ‘fetch’ time about 2 times, it’s very significant when fetching artworks for many tracks using ‘valueForKey:’ according to «Improving the Performance of Scripting Bridge Code»).
So I decided to understand what’s wrong with iTunesArtwork ‘data’ property.
We expect to get an NSImage object (according to iTunes.h ), but real object is kind of ‘NSAppleEventDescriptor’. And it’s easy to guess, that this object contains an image for us. So we can just use ‘data’ property to get image data. And this is really faster than getting ‘rawData’ from iTunesArtwork.
But sometimes iTunes return NSImage object instead NSAppleEventDescriptor. This is an strange behavior, but it's still faster then using rawData.

Related

Call to UIWebView crashing my app in iOS

I have a WebView in my storyboard. I created an outlet property to that webview in my view controller file. Then in my code in I'm calling it like this:
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"news1" ofType:#"html" inDirectory:#"/HTML"]];
[self.webView loadRequest:[NSURLRequest requestWithURL:url]];
}
The problem is my app is crashing when I run this and I don't really know why. I get this error, but I need help deciphering what the issue is.
2014-05-20 20:18:10.214 MyApp[1789:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
*** First throw call stack:
(
0 CoreFoundation 0x01f7b1e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x019fe8e5 objc_exception_throw + 44
2 CoreFoundation 0x01f7afbb +[NSException raise:format:] + 139
3 Foundation 0x0161a92b -[NSURL(NSURL) initFileURLWithPath:] + 123
4 Foundation 0x0161a7fd +[NSURL(NSURL) fileURLWithPath:] + 67
5 MyApp 0x00011c3d -[LVGTutorialVC viewDidLoad] + 205
6 UIKit 0x007dd33d -[UIViewController loadViewIfRequired] + 696
7 UIKit 0x00803345 -[UINavigationController _layoutViewController:] + 39
8 UIKit 0x0080385b -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 235
9 UIKit 0x00803953 -[UINavigationController _startTransition:fromViewController:toViewController:] + 78
10 UIKit 0x008048cc -[UINavigationController _startDeferredTransitionIfNeeded:] + 645
11 UIKit 0x008054e9 -[UINavigationController __viewWillLayoutSubviews] + 57
12 UIKit 0x009460d1 -[UILayoutContainerView layoutSubviews] + 213
13 UIKit 0x0072d964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
14 libobjc.A.dylib 0x01a1082b -[NSObject performSelector:withObject:] + 70
15 QuartzCore 0x01de245a -[CALayer layoutSublayers] + 148
16 QuartzCore 0x01dd6244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
17 QuartzCore 0x01dd60b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
18 QuartzCore 0x01d3c7fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
19 QuartzCore 0x01d3db85 _ZN2CA11Transaction6commitEv + 393
20 QuartzCore 0x01d3e258 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
21 CoreFoundation 0x01f4336e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
22 CoreFoundation 0x01f432bf __CFRunLoopDoObservers + 399
23 CoreFoundation 0x01f21254 __CFRunLoopRun + 1076
24 CoreFoundation 0x01f209d3 CFRunLoopRunSpecific + 467
25 CoreFoundation 0x01f207eb CFRunLoopRunInMode + 123
26 GraphicsServices 0x03eab5ee GSEventRunModal + 192
27 GraphicsServices 0x03eab42b GSEventRun + 104
28 UIKit 0x006bef9b UIApplicationMain + 1225
29 MyApp 0x0002158d main + 141
30 libdyld.dylib 0x0262c701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
The HTML file isn't in your bundle or isn't at the path specified. Check the case of the file and folder name. If you build/run in the simulator, you can look through the bundle inside of ~/Library/Application Support/iPhone Simulator/7.1/Applications.
Don't use loadRequest if you want to load html locally. use this
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:#"sample" ofType:#"html"];
NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
[webView loadHTMLString:htmlString baseURL:nil];

Getting error after execute NSMutableArray

Here is the code. I tried to create a object which includes the name, size and image(get from the resource) and then I add that object into NSMutableArray in order to show those object in NSTableView. However, after I run the code, I did get the correct counts of object in NSMutableArray and correct information in each object(name,size,image), but it still gives me error. Could you guys help me. I am a new Mac developer. Thanks !!
Here is the code:
#implementation AppDelegate{
NSMutableArray* _tableContents;
}
-(void)awakeFromNib{
NSString* imagePath = #"USB.png";
NSString* mountPath = #"/Volumes";
_tableContents = [[NSMutableArray alloc]init];
for(mountPath in [[NSWorkspace sharedWorkspace]mountedLocalVolumePaths])
{
if(0==[mountPath rangeOfString:#"/Volumes/"].location)
{
NSString* USBpath = [[[NSWorkspace sharedWorkspace]mountedLocalVolumePaths]objectAtIndex:count];
//get the name of USB drive
NSString* nameOfUSB = [USBpath substringFromIndex:9];
//get the size of USB drive
NSNumber *volumeSize;
NSURL *mountPathPicked = [NSURL fileURLWithPath:mountPath];
if([mountPathPicked getResourceValue:&volumeSize forKey:NSURLVolumeTotalCapacityKey error:nil])
{
NSDictionary *obj = #{#"name":nameOfUSB,
#"image":[NSImage imageNamed:imagePath],
#"size":volumeSize
};
//after I call the following line, it will give me error !!
[_tableContents addObject:obj];
}
}
count ++;
}
}
//I also use the following two methods in order to show the name, and image in NSTableView
-(NSInteger)numberOfRowsInTableView:(NSTableView *)tableView{
return [_tableCountents count];
}
-(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row{
NSDictionary *flag = _tableContents[row];
NSString *identifier = [tableColumn identifier];//call different col we need identifier
if([identifier isEqualToString:#"MainCell"])
{
NSTableCellView *cellView = [tableView makeViewWithIdentifier:#"MainCell" owner:self];//give back specific cell named mainCell
[cellView.textField setStringValue:flag[#"name"]];
[cellView.imageView setImage:flag[#"image"]];
return cellView;
}
return nil;
}
There is no connection problems in GUI. And here is the error message:
2013-04-25 01:16:41.321 NAMEOFPROJECT[8243:303] An uncaught exception was raised
2013-04-25 01:16:41.322 NAMEOFPROJECT[8243:303] *** -[__NSArrayI objectAtIndex:]: index 7 beyond bounds [0 .. 3]
2013-04-25 01:16:41.329 NAMEOFPROJECT[8243:303] (
0 CoreFoundation 0x00007fff9147cb06 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff900c03f0 objc_exception_throw + 43
2 CoreFoundation 0x00007fff9142fb53 -[__NSArrayI objectAtIndex:] + 163
3 CDTOANYDRIVE 0x00000001000011d6 -[AppDelegate DetectingUSBDrives] + 710
4 CDTOANYDRIVE 0x0000000100000efb -[AppDelegate awakeFromNib] + 43
5 AppKit 0x00007fff899631a8 -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 1234
6 AppKit 0x00007fff89b79976 -[NSNib _instantiateNibWithExternalNameTable:] + 610
7 AppKit 0x00007fff89b7a41a -[NSNib instantiateNibWithExternalNameTable:] + 17
8 AppKit 0x00007fff89b262b4 -[NSTableRowData _unarchiveViewWithIdentifier:owner:] + 520
9 CDTOANYDRIVE 0x000000010000174b -[AppDelegate tableView:viewForTableColumn:row:] + 219
10 AppKit 0x00007fff89b279a2 -[NSTableRowData _addViewToRowView:atColumn:row:] + 324
11 AppKit 0x00007fff89b2766f -[NSTableRowData _addViewsToRowView:atRow:] + 151
12 AppKit 0x00007fff89b25c05 -[NSTableRowData _addRowViewForVisibleRow:withPriorView:] + 415
13 AppKit 0x00007fff89b2598a -[NSTableRowData _addRowViewForVisibleRow:withPriorRowIndex:inDictionary:withRowAnimation:] + 272
14 AppKit 0x00007fff89b24c59 -[NSTableRowData _unsafeUpdateVisibleRowEntries] + 740
15 AppKit 0x00007fff89b247f1 -[NSTableRowData updateVisibleRowViews] + 119
16 AppKit 0x00007fff89afc5d7 -[NSTableView layout] + 165
17 AppKit 0x00007fff89aafe95 -[NSView _layoutSubtreeHeedingRecursionGuard:] + 112
18 CoreFoundation 0x00007fff914754a6 __NSArrayEnumerate + 582
19 AppKit 0x00007fff89aafff6 -[NSView _layoutSubtreeHeedingRecursionGuard:] + 465
20 CoreFoundation 0x00007fff914754a6 __NSArrayEnumerate + 582
21 AppKit 0x00007fff89aafff6 -[NSView _layoutSubtreeHeedingRecursionGuard:] + 465
22 CoreFoundation 0x00007fff914754a6 __NSArrayEnumerate + 582
23 AppKit 0x00007fff89aafff6 -[NSView _layoutSubtreeHeedingRecursionGuard:] + 465
24 CoreFoundation 0x00007fff914754a6 __NSArrayEnumerate + 582
25 AppKit 0x00007fff89aafff6 -[NSView _layoutSubtreeHeedingRecursionGuard:] + 465
26 AppKit 0x00007fff89aafd2e -[NSView layoutSubtreeIfNeeded] + 615
27 AppKit 0x00007fff89aab4dc -[NSWindow(NSConstraintBasedLayout) layoutIfNeeded] + 201
28 AppKit 0x00007fff899d96a8 -[NSView _layoutAtWindowLevelIfNeeded] + 99
29 AppKit 0x00007fff899d8fe6 -[NSView _sendViewWillDrawInRect:clipRootView:] + 87
30 AppKit 0x00007fff899a59b1 -[NSView displayIfNeeded] + 1044
31 AppKit 0x00007fff89a62a48 -[NSWindow _reallyDoOrderWindow:relativeTo:findKey:forCounter:force:isModal:] + 1377
32 AppKit 0x00007fff89a62068 -[NSWindow _doOrderWindow:relativeTo:findKey:forCounter:force:isModal:] + 940
33 AppKit 0x00007fff89a61c4f -[NSWindow orderWindow:relativeTo:] + 159
34 AppKit 0x00007fff89963266 -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 1424
35 AppKit 0x00007fff8994214d loadNib + 317
36 AppKit 0x00007fff89941679 +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:] + 219
37 AppKit 0x00007fff899414ae -[NSBundle(NSNibLoading) loadNibNamed:owner:topLevelObjects:] + 200
38 AppKit 0x00007fff8994128e +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 360
39 AppKit 0x00007fff8993da2f NSApplicationMain + 398
40 CDTOANYDRIVE 0x0000000100000e82 main + 34
41 libdyld.dylib 0x00007fff9385a7e1 start + 0
42 ??? 0x0000000000000003 0x0 + 3
)
And the above error shows twice !!
I have tried your code in a mini-app and It works fine. There are few things that I might highlight:
Your exception occurs in the method DetectingUSBDrives, for which we don't have any code. I'm assuming that you have pasted the code in the awakeFromNib method.
You are using count as an index. Is this varibale initialized at zero?
The fact that the error appears twice suggests that your cell views hold a reference to your app delegate, which means that awakeFromNib is called once for each view creation. This can create many problem since you are initializing _tableOfContents there. You might want to move all that code to the init method instead.

UILabel [__NSCFString set]: unrecognized selector sent to instance crash

I am having a weird crash related to a UILabel but the crash reporting service I am using doesn't give me much help to locate it. I can't know which Controller and which UILabel is causing it. The only help I have is the following:
-[__NSCFString set]: unrecognized selector sent to instance 0x1e0958d0
0 CoreFoundation __exceptionPreprocess + 162
1 libobjc.A.dylib objc_exception_throw + 30
2 CoreFoundation -[NSObject(NSObject) doesNotRecognizeSelector:] + 170
3 CoreFoundation ___forwarding___ + 392
4 CoreFoundation _CF_forwarding_prep_0 + 24
5 UIKit -[UILabel _legacy_drawTextInRect:baselineCalculationOnly:] + 2632
6 UIKit -[UILabel _drawTextInRect:baselineCalculationOnly:] + 166
7 UIKit -[UILabel drawTextInRect:] + 450
8 UIKit -[UILabel drawRect:] + 72
9 UIKit -[UIView(CALayerDelegate) drawLayer:inContext:] + 364
10 QuartzCore -[CALayer drawInContext:] + 112
11 QuartzCore CABackingStoreUpdate_ + 1808
12 QuartzCore CA::Layer::display_() + 980
13 QuartzCore CA::Layer::display_if_needed(CA::Transaction*) + 202
14 QuartzCore CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 24
15 QuartzCore CA::Context::commit_transaction(CA::Transaction*) + 238
16 QuartzCore CA::Transaction::commit() + 316
17 QuartzCore CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 60
18 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 20
19 CoreFoundation __CFRunLoopDoObservers + 276
20 CoreFoundation __CFRunLoopRun + 742
21 CoreFoundation CFRunLoopRunSpecific + 356
22 CoreFoundation CFRunLoopRunInMode + 104
23 GraphicsServices GSEventRunModal + 74
24 UIKit UIApplicationMain + 1120
25 App main.m line 14
26 App start + 40
Is there anything I can find my way through this? Thanx in advance!
Even though it's an old question, for anyone that encounters a similar issue:
If you're using attributedText in your UILabel, check the attribute value types you're setting. For example:
NSString* s = #"str";
NSMutableAttributedString* as = [[NSMutableAttributedString alloc] initWithString:s];
[as addAttribute:NSForegroundColorAttributeName value:someObjectThatsNotAUIColor range:NSMakeRange(0, s.length)];
will cause the UILabel [__NSCFString set]: unrecognized selector sent to instance crash.
You could try to put this in a .h :
#interface NSString (extended)
- (void)set;
#end
And this in a .m :
#implementation NSString (extended)
- (void)set
{
NSLog(#"[NSString set] ??? impossible !!!");
}
#end
Then set a breakpoint on this method.
Search your project for " set]" then you'll probably already find it, as this is a very untypical method name. If that doesn't help, use NSLog to print out all your labels adresses to your console to find out which label is causing this. Like
for (UIView *sub in self.subviews)
if ([sub kindOfClass:[UILabel class]]) NSLog(#"%p", sub);
(code untested, correct spelling if necessary)

JSON error on iPhone app

i am getting error when i try to run an app on my simulator.
I have copied the JSON(JSON Framework) project in my app but my simulator crashes when it compiles the below lines,(I am using iOS 4.2)
- (void)viewDidLoad {
[super viewDidLoad];
NSString *jsonString = [NSString stringWithString:#"{\"foo\": \"bar\"}"];
NSDictionary *dictionary = [jsonString JSONValue];
NSLog(#"Dictionary value for \"foo\" is \"%#\"", [dictionary objectForKey:#"foo"]);
}
ERROR:
2011-03-02 13:33:37.304 test[10918:207] -[NSCFString JSONValue]: unrecognized selector sent to instance 0x3034
2011-03-02 13:33:37.308 test[10918:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString JSONValue]: unrecognized selector sent to instance 0x3034'
*** Call stack at first throw:
(
0 CoreFoundation 0x00da7be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00efc5c2 objc_exception_throw + 47
2 CoreFoundation 0x00da96fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d19366 ___forwarding___ + 966
4 CoreFoundation 0x00d18f22 _CF_forwarding_prep_0 + 50
5 test 0x000025d7 -[testViewController viewDidLoad] + 119
6 UIKit 0x0035e65e -[UIViewController view] + 179
7 test 0x0000237e -[testAppDelegate application:didFinishLaunchingWithOptions:] + 79
8 UIKit 0x002b11fa -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163
9 UIKit 0x002b355e -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 439
10 UIKit 0x002bddb2 -[UIApplication handleEvent:withNewEvent:] + 1533
11 UIKit 0x002b6202 -[UIApplication sendEvent:] + 71
12 UIKit 0x002bb732 _UIApplicationHandleEvent + 7576
13 GraphicsServices 0x016dda36 PurpleEventCallback + 1550
14 CoreFoundation 0x00d89064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
15 CoreFoundation 0x00ce96f7 __CFRunLoopDoSource1 + 215
16 CoreFoundation 0x00ce6983 __CFRunLoopRun + 979
17 CoreFoundation 0x00ce6240 CFRunLoopRunSpecific + 208
18 CoreFoundation 0x00ce6161 CFRunLoopRunInMode + 97
19 UIKit 0x002b2fa8 -[UIApplication _run] + 636
20 UIKit 0x002bf42e UIApplicationMain + 1160
21 test 0x0000230c main + 102
22 test 0x0000229d start + 53
)
terminate called after throwing an instance of 'NSException'
Program received signal: “SIGABRT”.
(gdb)
Try adding -ObjC -all_load to the OTHER_LINKER_FLAGS setting. If that is not an option, you could try to use the SBJsonParser or SBJsonWriter objects directly rather than the category methods.
Make sure that SBJSON files are being compiled!
Target->Build phases->Compile files <- check if the *.m files of SBJSON are there!
Adding -ObjC -all_load to app target->build settings ->Linking ->Other Linker Flags -> Debug worked in XCode 4.
Earlier it was crashing

can someone please explain why this keeps crashing on iOS 4.2?

The code worked in iOS 3.2 and in 4.2 it keeps crashing.
Here's the line that it crashes on.
NSArray* address = [NSArray arrayWithArray:[[[access.filteredResults objectAtIndex:[indexPath row]] addressArray] objectAtIndex:0]];
2010-11-04 12:20:03.060 ContactMapper[2211:207] -[__NSCFDictionary getObjects:range:]: unrecognized selector sent to instance 0x5648e30
2010-11-04 12:20:03.062 ContactMapper[2211:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary getObjects:range:]: unrecognized selector sent to instance 0x5648e30'
*** Call stack at first throw:
(
0 CoreFoundation 0x0117abe9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x012cf5c2 objc_exception_throw + 47
2 CoreFoundation 0x0117c6fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x010ec366 ___forwarding___ + 966
4 CoreFoundation 0x010ebf22 _CF_forwarding_prep_0 + 50
5 CoreFoundation 0x01176605 -[NSArray initWithArray:range:copyItems:] + 245
6 CoreFoundation 0x010e1367 +[NSArray arrayWithArray:] + 119
7 ContactMapper 0x00003a8d -[RootViewController tableView:cellForRowAtIndexPath:] + 1333
8 UIKit 0x0033a7fa -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 634
9 UIKit 0x0033077f -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 75
10 UIKit 0x00345450 -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1561
11 UIKit 0x0033d538 -[UITableView layoutSubviews] + 242
12 QuartzCore 0x01fc2451 -[CALayer layoutSublayers] + 181
13 QuartzCore 0x01fc217c CALayerLayoutIfNeeded + 220
14 UIKit 0x005c7702 -[UISplitViewController willRotateToInterfaceOrientation:duration:] + 1134
15 UIKit 0x00373df2 -[UIViewController window:willRotateToInterfaceOrientation:duration:] + 962
16 UIKit 0x002edee5 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 1783
17 UIKit 0x002e8538 -[UIWindow _setRotatableViewOrientation:duration:force:] + 89
18 UIKit 0x002eb643 -[UIWindow _updateInterfaceOrientationFromDeviceOrientation:] + 164
19 Foundation 0x000306c1 _nsnote_callback + 145
20 CoreFoundation 0x01152f99 __CFXNotificationPost_old + 745
21 CoreFoundation 0x010d233a _CFXNotificationPostNotification + 186
22 Foundation 0x00026266 -[NSNotificationCenter postNotificationName:object:userInfo:] + 134
23 UIKit 0x00477d0a -[UIDevice setOrientation:animated:] + 228
24 UIKit 0x002c9637 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 656
25 UIKit 0x002d3db2 -[UIApplication handleEvent:withNewEvent:] + 1533
26 UIKit 0x002cc202 -[UIApplication sendEvent:] + 71
27 UIKit 0x002d1732 _UIApplicationHandleEvent + 7576
28 GraphicsServices 0x01ab0a36 PurpleEventCallback + 1550
29 CoreFoundation 0x0115c064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
30 CoreFoundation 0x010bc6f7 __CFRunLoopDoSource1 + 215
31 CoreFoundation 0x010b9983 __CFRunLoopRun + 979
32 CoreFoundation 0x010b9240 CFRunLoopRunSpecific + 208
33 CoreFoundation 0x010b9161 CFRunLoopRunInMode + 97
34 UIKit 0x002c8fa8 -[UIApplication _run] + 636
35 UIKit 0x002d542e UIApplicationMain + 1160
36 ContactMapper 0x00002638 main + 102
37 ContactMapper 0x000025c9 start + 53
)
terminate called after throwing an instance of 'NSException'
At first glance, this line is your problem:
[NSArray initWithArray:range:copyItems:]
at first glance, it might be that you need indexPath.row not [indexPath row].
Because iOS 4.2 is still under NDA, we cannot talk about 4.2-specific code.
We can however, talk about 4.1 and previous.
First, you're going to go to the 4.2 diffs page after you sign into the iOS Dev Center. This will tell you what's changed in that release. Since these pages only show release to release, look at the 3.2-4.0 diffs, 4.0-4.1 and 4.1-4.2 diffs. You are looking for a change in the API for UITableView or NSArray that obviously cannot be talked about here.
Second, you're going to download the WWDC '10 session on crash reports. It's a little tedious but the hour spent learning about how to read a crash report is WELL worth it.
Hope this helps!
The error you're getting tells you that the selector getObjects:range: is being sent to an __NSCFDictionary. So clearly the following:
[[[access.filteredResults objectAtIndex:[indexPath row]] addressArray] objectAtIndex:0]
... used to return an NSArray, but is now returning an NSDictionary.
I don't know what access is so I have no idea what else to say other than you can change the line you cited as the source of the error to:
NSDictionary* address = [NSDictionary dictionaryWithDictionary:[[[access.filteredResults objectAtIndex:[indexPath row]] addressArray] objectAtIndex:0]];
Once you've done that, whatever code follows that uses address clearly needs to also change to deal with the fact that you're no longer accessing an array.
You need the new iOS CookBook code