json-framework error in iPhone static library - iphone

I have an iPhone app that uses the json-framework. I moved some of the code, including the json-framework source, from the main project to a static library. When I did this, the json-framework stopped getting compiled into the binary (double checked with class dump). This causes a nasty error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString JSONValue]: unrecognized selector sent to instance 0x43897f0'
Everything else in the static library continues to function properly.

Apparently, categories and static libraries don't work unless you sprinkle the magic dust on the linker flag. According to a Technical Q&A, you have to add the -ObjC linker flag to the main project (not the library, as stated in the Q&A).

Related

NSInvalidArgumentException', reason: '[__NSCFString JSONObject]' with PhoneGap Camera

I have been working with PhoneGap to access the camera, which works locally when built to the iPhone, but when I upload to TestFlight, the same method fails and gives me the following:
'NSInvalidArgumentException', reason: '[__NSCFString JSONObject]'
The arguments that are being passed are as follows:
[["Camera1856949628","Camera","takePicture",[25,0,1,100,100,1,0,false,false,false,null,0]]]
From what I gather its failing in CDVJSON.m when converting an NSString to JSONObject which in turn is an NSArray.
Any suggestions on what might be causing this?
Because your code don't use the JSONObject until runtime. So CDVJSON.m didn't linked in the app.
Fixed the issue by adding "Other Linker Flags: -all_load" in your project. As suggested by this answer: https://stackoverflow.com/a/17581430/2570865

EkSource class is not supporting in ios 4.3.3

i am using EkSource class from Eventkit framework for creating custum calender but , when i am running application in ios 4.3.3. i am getting following error :-
2012-04-03 14:49:36.522 TimeFix[791:707] -[EKEventStore sources]:
unrecognized selector sent to instance 0x252a00 2012-04-03
14:49:36.590 TimeFix[791:707] *
Terminating app due to uncaught
exception 'NSInvalidArgumentException', reason: '-[EKEventStore
sources]: unrecognized selector sent to instance 0x252a00'
but when i am using ios 5.0 ipod for run application, is working fine with custom calender.
so please suggest me what is the is problem with ios 4.3.3.
Your error shows that you might have used something like this
[EKEventStore sources]
Am I right? If yes,
then apple doc says
sources
Returns an unordered array of source objects.
(NSArray *)sources
Return Value An unordered array of EKSource objects.
Availability Available in iOS 5.0 and later. Declared In
EKEventStore.h
So it is available in iOS 5.0 & later.

Three20 crash when using PhotoSource

In my app I send a request to get images from flickr. I have went
through my app step-by-step with a breakpoint and found the app
crashes at this line in TTURLRequest.m:
} else {
return [self.urlPath md5Hash];
}
I get this error in the debugger:
*** Terminating app due to uncaught exception
'NSInvalidArgumentException', reason:
'-[NSCFString md5Hash]: unrecognized
selector sent to instance 0x74409e0'
Does anybody know what is causing this?
Thanks
check your "other linker flag" settings. This could happen if you have not set your "other linker flags" properly. It has to be -ObjC and -all_load. any mistake in uppercase or lowercase will also cause this problem

Why are device and simulator builds different?

I'm referencing two static libraries. I build them in debug-simulator mode and all works well with my app. I then create debug-iphone builds and push my app to the device. It breaks with this error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString sizeWithCGFont:pointSize:constrainedToSize:]: unrecognized selector sent to instance 0x24320'
Then the SIGABRT error shows.
Why would this work fine on the simulator and only manifest on the device?
-- EDIT --
Finally figured out a work around, at least for running on the device but now not the simulator. The method that is throwing the exception is a class I'm using for fonts. It is part of staticLibA, for example, which is the library that was having issues. I included staticLibA as a reference in the target app and also the .m file of the problem class. I already had a reference to its header file, which is a category in NSString. Is that why it didn't work until I included the .m file?
If I try to run it in the simulator, I get a duplicate object error in the build output folder for the above class.
I couldn't tell you why your issue is only presenting itself on the device at the moment - perhaps you need to clean both builds and try recompiling them?
In any case, the exception message shown is completely valid. There is no (public) method named -[NSString sizeWithCGFont:pointSize:constrainedToSize:]. Are you trying to call one of the sizeWithFont: methods on NSString anywhere?
Edit: Looks like the sizeWithCGFont:pointSize:constrainedToSize: is from cocos-2d, which I'm guessing would be one of your static libraries. The major significant different between simulator and device builds is the build architecture - the simulator's architecture is the architecture of your own machine (i386), while device builds are for armv6 or armv7. Are you sure your static libraries are built for the right architectures?
Simulator builds are compiled for the Intel platform since your computer is on the x86 (or x86_64) architecture.
The device builds compile to the arm6 (or arm7) architecture.
You can't use a library that's been compiled for one on the other. The assembly code from each isn't compatible.
I have had this problem show up when I was releasing an object incorrectly. So I would have a pointer to a unallocated object. So when I called a function on the object, it would say that I was calling the function on a NSCFString object. Probably because the memory was reused for a NSString object. I fixed it by finding my extra release and removing it.

iPhone: Using static library in an application crashes the device but not the iphone simulator

I have a library I made, and now I want to utilize it in an application. I've believe I've properly linked to the library. Here are all the things I've done:
Set the header search path
Set other linker flags to "-ObjC"
Added the static library xcode project
Made sure the lib.a was listed as a framework target
Added the library as a direct dependency
Like I said in the title, I've successfully run the app with the static library in the simulator. Once I try testing the app using the device, it crashes the second it has to use a function from the library:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSDate firstOfCurrentMonth]: unrecognized selector sent to class 0x3841bb44'
2009-10-10 12:45:31.159 Basement[2372:207] Stack:
This is due to a bug in the current SDK linker. See this post for more information on the problem and possible workarounds. (also see this post.)
Update:
Another thing you can try is to remove the static library and include the library's source files directly in the application's project. I was facing a similar static library linking issue and that's what I ended up falling back on to get it to run successfully. If that works (however gross a workaround it may be) then it's definitely a linker issue.
I ran into this problem recently. I was unable to get the -all_load to work, when I noticed that another category I had DID work. I was lazy for this category and included it in with another file.
I eventually created a dummy class (no methods, instance variables) and included the implementation of my categories in the .m file for that dummy class. After doing this my categories started working even after I removed the -all_load flag.
This was on iPhone OS 3.1.3.
This certainly is not the RIGHT way to fix it, but it seemed to work.
Full sample code is on my blog for my (trivial) categories.