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

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

Related

"unrecognized selector" crash on IOS 7 simulator

I am testing my music application compatibility on IOS7 by running it on Xcode 5 iPhone simulator(IOS7) but it crashes on retrieving all the music items using following code.
MPMediaQuery *allSongs = [[MPMediaQuery alloc] init];
NSArray *itemsFromGenericQuery = [allSongs items]; // Here application crashes
Crash log :
[__NSCFNumber libraryCompletionHandler]: unrecognized selector sent to instance 0xdd66840
This is snapshot for the threads running at the time of crash:
I am suspecting that there is some bug in Xcode5..!
EDIT : I could run the same application using Xcode 4.6.3 on simulator/device without any issue/crash.
[__NSCFNumber libraryCompletionHandler]: unrecognized selector sent to instance 0xdd66840
This error says that an object of type NSNumber was passed the message -libraryCompletionHandler. NSNumber doesn't have a -libraryCompletionHandler method, hence the crash. Obviously, something bad is going on.
Usually this is an indication of a bad cast, or a zombie. In this case, I would suspect a zombie object.
Congratz, you may have found a defect in the iOS 7 Simulator. Woo Hoo!
I am suspecting that there is some bug in Xcode5..!
There are clearly some bugs in the developer preview versions of Xcode 5, but it sounds like it's your app that's crashing rather than Xcode or the simulator itself. That would lead one to believe that the problem is more likely to be either in your app, or possibly in the operating system.
[__NSCFNumber libraryCompletionHandler]: unrecognized selector sent to instance 0xdd66840
Bad pointers are a common cause of unrecognized selector errors, especially when they involve classes that don't seem to be involved in the code that's crashing. Turn on NSZombieEnabled and set a breakpoint on all exceptions to track down the problem.
Maybe it's the project settings
Try to add -ObjC

Unrecognized selector sent to UIRefreshControl

I am getting this Error :
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MasterViewController setRefreshControl:]: unrecognized selector sent to instance 0x2681e0'
How to resolve this issue because in simulator my app is running but on device with the same code my app is not running.
I hope your simulator is iOS6 Simulator and the device in which you tried to run may have a lower OS version ..right?
.
From UIRefreshControl Class Reference,
Availability : Available in iOS 6.0 and later.
Refresh control is new to iOS6. So if you want to support iOS5, the best thing to do is check if the refresh control class exists (you can use NSClassFromString ), and if it doesn't exists either not use it or use an alternative.

json-framework error in iPhone static library

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).

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.