Titanium NSInvalidArgumentException - titanium

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!

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.

Related

Appcelerator Titanium and Apple Pay

I am trying to use Apple Pay in a Titanium app. So far I've gotten it to work about a third of the time I run the app, the rest of the time the app crashes. My suspicion is that not adding the apple pay entitlement to the app is causing the crash (unfortunately there is no error message in the console when the app crashes).
Has anyone had any luck getting Apple Pay to work in a Titanium app?
Well, without advertising my Ti.ApplePay module, this might be the easiest way to adopt Apple Pay with Titanium. It supports all major Titanium versions and includes all native API's that are available. Give it a try or use a custom one :-)
I got it working. Here is a gist of the code in my module: https://gist.github.com/zach-babb-moovel/bd4172454cf54a178855e76ca5dd1f48. The key was wrapping the PKPaymentRequest and subsequent PKPaymentAuthorizationViewController parts in a dispatch_async call. You'll also have to make sure all your profiles are set up correctly and that you use a custom Entitlements.plist file for your Titanium project. Check out the Entitlements.plist here: https://github.com/hansemannn/applepaydemo/blob/master/Entitlements.plist for what it should look like.

Switch to xCode5 with the new SDK will eliminate bugs?

I've just installed ios7 on my iPhone, however I have not yet downloaded xCode5, so I've been producing my archives using iOS6 SDK and using TestFlight to test them on my phone. When running my app on iOS7, I'm noticing a lot of bugs that I didn't see in iOS6 (some that are unpredictable and very difficult to fix). I've been avoiding downloading xCode7 because I'm not yet ready to make the commitment to the new UI elements, but I'm wondering if I did produce my app using the iOS7 SDK, is it possible some of these bugs could be eliminated?
This is a very broad question. iOS 7, despite its advanced beta count, is still very much a work in progress. There are bugs that should be reported to Apple that should not happen. But beyond that, there are changes in the internal API that influence how the app behaves. Apple has done its best to try and preserve SDK 6 apps as much as possible, but there is breaking API which can cause crashes. One example off the top of my head is the class cluster they are now using with ABPersonViewController. Subclassing that in iOS 6 works fine, but in iOS 7, even when compiled with SDK 6, causes a crash in most cases. These issues can be resolved even with Xcode 4.6 and SDK 6.
Compiling with SDK 7 may help you fix some issues, but it will come with a plethora of issues of its own. Depending on how complex your view hierarchy is, you may have to invest a considerable amount of effort to support the new API and functionality. You don't really have a choice, as this is the future, but you should be prepared for this, and arrange your schedule accordingly.

Objective-C playground?

Is there any sort of Mac app, Web app, or others like JSFiddle for Objective-C/Cocoa purposes?
It's not entirely the same, but look into F-Script: http://www.fscript.org/
It lets you rapid-prototype and experiment. You can also hook it into existing apps very easily. It has been invaluable for me for certain types of UI debugging.
I've also found CodeRunner to be quite handy for boilerplate app generation and one-click console running to try language snippets out. Available on the AppStore at a price.
I created playgrounds for Objective-C on top of code injection, so you can experiment with normal iOS simulator, it's open source on GitHub
Video showing them in action

Monotouch/WCF Error on iPhone Hardware

I created a WCF Client on Monotouch with the Silverlight SLSvcUtil.exe Tool similar to http://docs.xamarin.com/ios/tutorials/Working_with_Web_Services#Consuming_WCF_Services.
On the Simulator everything works fine but when i started it on an iPhone 4S i got the error :
Attempting to JIT compile method '(wrapper delegate-begin-invoke) :begin_invoke_IAsyncResult_this__TimeSpan_AsyncCallback_object (System.TimeSpan,System.AsyncCallback,object)' while running with --aot-only.
Any ideas?
I've called a few wcf services from monotouch without hitting any issues like this- so it can be done.
The jit error within monotouch normally indicates either that something has been removed by the linker, or that some virtual abstract method has been called (at least in my recent experience).
Can you check the linker settings for your real iPhone project? Does the problem go away if you set it to -nolink - see http://docs.xamarin.com/ios/advanced_topics/linker
If that does help, then the next step is to take a look within the wcf generated file - can you find and post some more code about the callback method in this case?
Such issues are rarely linker related, even less if the signature is a wrapper. However you can confirm this easily with Stuart's instructions.
IMO you are likely hitting a case where the AOT compiler could not predict the required code. That can happens when mixing generics and value-types (and you have a TimeSpan in generated signature). This will work on the simulator (where the JIT is used) but not when AOT'ing the application.
The best way to solve such issue is to open a bug report at http://bugzilla.xamarin.com and attach a test case that allow us to replicate the issue.

iPhone Simulator is slow compared to device

I've been working on a new app, and when I run it on the simulator, it's VERY slow. There's nothing fancy in the app, just UINavigationControllers and text. The slowness only occurs if I launch the app from Xcode (with or without debugging on, doesn't matter). If I run the app on my iPhone or launch it directly from the simulator by clicking it's icon from SpringBoard, the performance problems all disappear.
For what it's worth, all my other apps perform just fine when run launched from Xcode in the simulator, so it must be something specific to this app. Has anyone experienced this before?
UPDATE: There is no performance hit when the app is run through Instruments either. I'm not using any 3rd party libraries. It's all calls to the Apple SDK.
Thanks,
Arash
Have you looked at it in Instruments to see where it's spending its time? No reason to guess when you can test.
Running an app in the simulator while in active debugging will always make the app slower. Always, and in a way that is exactly what you are describing.
Basically, "Build and Go" will be slow because its running the debugger.
This is different from "Debug" vs. "Release". The debug build will run fast if you aren't actually debugging it.
Are you using NSLog() to print a large amount of information? When you launch through Xcode, that information is piped to the debugging console and, if there's a lot, will take time to update the window. When you launch directly or on the device, the data is simply stored in a file, which generates less overhead.
I once reduced a program's run time from several minutes to a few seconds simply by removing logging statements. Unfortunately, it was for a timed programming contest.
I had the exact same problem and spent about 2hrs now to solve it. In my case I think it was because I had "Enable Guard Malloc" set. If it wasn't that, my other guess is bad karma.
Simulator Debug, You should need to be ensure when your app running on simulator debug->slow animations isn't check marked