Search code examples
titaniumtitanium-mobile

Titanium NSInvalidArgumentException


I'm trying to build a crossplatform (Android-ios) mobile application, using Titanium SDK. I didn't have a chance for a long time to build it for ios, I only used my Windows-android combination, to test it, and it works great on the Android system. But when i try to build it on the mac for the ios, i get this message, and the application shuts down in a second:

The application has crashed with an uncaught exception 'NSInvalidArgumentException'.

Since i can not provide any relevant code, because the exception doesn't show what's the problem with my javascript code, and I certainly didn't write any native, ios specific code, i have no idea, what to do.

From the few posts i have found here is what i have tried:

  • Restart Titanium Studio
  • Clean the project
  • Made sure to close any ResultSet, and DB objects when done with them (as suggested here: topic)
  • Test the code on both 3.0.0 and 2.x.x versions

I'm looking forward to any advice, on how you solved this problem, if you had it! Thanks in advance!

Update: The problem was the following: I called hasOwnProperty on Titanium UI elements, and on the ios version these elements don't have this function (which is weird, since every javascript objects have it, if i'm not mistaken).

If you have similar problems, i recomend reading this article, besides mr.VVoos answer, it helps a lot in avoiding the problems i had!


Solution

  • I'm developing with Titanim and iOS & Android for a long time. Usually there are many differences between iOS and Android parts of the code.

    In most cases this exceptions means that an operation is called that is not available for the called class. (In Java this would mean: Class.method() -> Class has no method called method()).

    You can try to run the app in debug mode (on iOS Simulator). There is a big advantage debuggin iOS compared to Android. Usually the iOS simulator stops if there is an exception and it shows the JavaScript code that caused the exception. Unfortunately this doesn't work all the time and it only works on simulator.

    If this does not provide any further information you can do the following: - go to your app.js and set a breakpoint in one of the first lines. - start app in debug mode. - move on this breakpoint each time until your app crashes - maybe then you are able to detect the error or provide further information.

    One last tip: Check your code if there are any platform-specific parts. (Like Android Intents and something that is not available on iOS).

    I know that this can be very ugly but we had to solve many of these nasty issues while migrating from iOS to Android.