iOS - App crashes on return from $.get json call

191 views
Skip to first unread message

AaronOnTilt

unread,
Feb 12, 2012, 1:08:46 AM2/12/12
to phonegap
Hi, I'm trying to do some simple login authentication and having
several problems :-(

First, I know doing $.get here is not the best way, but I'm using RoR
and I get an InvalidAuthenticityToken error when trying to use
$.post. Being unable to figure that out, I decided to try $.get

Ajax successfully hits my server, authenticates, and then it sends
back the json and the iOS app crashes. The simulator stays open.

I'm using xcode 3.2.6, phonegap 1.4.1, osx 10.6. I'm started using
jquery 1.6.4 but have also tried 1.7.1 and it's the same issue.
--------
function login()
{
var user = $("#username").val();
var pass = $("#password").val();

if(user != '' && pass != '')
{
$.get("http://localhost:3000/mobile_login",
{"mobile":"true","user_session[login]":user,
"user_session[password]":pass,"user_session[remember_me]":"0",
"commit":"Login"},
function(res) {
navigator.notification.alert(res);
return false;
},
"json").error(function(req, status, error)
{ navigator.notification.alert("error status = " + status + " error =
" + error ); });
}
}
-------

If I change the type from json to text, it works perfectly and alerts
me with this: {"login_result":"success"}

If I change back to json, it crashes the app.

Thoughts? ideas?

AaronOnTilt

unread,
Feb 12, 2012, 1:22:42 AM2/12/12
to phonegap
I should have posted the console. Here it is:

2012-02-12 00:20:43.764 MyApp-ios[2527:207] Device initialization:
DeviceInfo = {"name":"iPhone Simulator","uuid":"05F2D740-8E77-5107-
B4CD-10AD355756AB","platform":"iPhone
Simulator","gap":"1.4.1","version":"4.3","connection":
{"type":"wifi"}};
2012-02-12 00:20:48.998 MyApp-ios[2527:207] *** Terminating app due to
uncaught exception 'NSRangeException', reason: '*** -[JKArray
objectAtIndex:]: index (1) beyond bounds (1)'
*** Call stack at first throw:
(
0 CoreFoundation 0x01a115a9
__exceptionPreprocess + 185
1 libobjc.A.dylib 0x01b65313
objc_exception_throw + 44
2 CoreFoundation 0x019c9ef8 +[NSException
raise:format:arguments:] + 136
3 CoreFoundation 0x019c9e6a +[NSException
raise:format:] + 58
4 MyApp-ios 0x00030185 -[JKArray
objectAtIndex:] + 197
5 MyApp-ios 0x00012eff -[PGNotification
alert:withDict:] + 143
6 MyApp-ios 0x00046e10 -[PGViewController
execute:] + 560
7 MyApp-ios 0x00003e8f -[AppDelegate execute:]
+ 95
8 MyApp-ios 0x00046a61 -[PGViewController
executeQueuedCommands] + 545
9 MyApp-ios 0x00046b88 -[PGViewController
flushCommandQueue] + 120
10 MyApp-ios 0x00045354 -[PGViewController
webView:shouldStartLoadWithRequest:navigationType:] + 164
11 MyApp-ios 0x000041eb -[AppDelegate
webView:shouldStartLoadWithRequest:navigationType:] + 123
12 UIKit 0x00246a92 -[UIWebView
webView:decidePolicyForNavigationAction:request:frame:decisionListener:]
+ 291
13 CoreFoundation 0x01981c7d __invoking___ + 29
14 CoreFoundation 0x01981b51 -[NSInvocation
invoke] + 145
15 CoreFoundation 0x019af858 -[NSInvocation
invokeWithTarget:] + 72
16 WebKit 0x023d7c76 -
[_WebSafeForwarder forwardInvocation:] + 182
17 CoreFoundation 0x01982a04 ___forwarding___ +
1124
18 CoreFoundation 0x01982522
_CF_forwarding_prep_0 + 50
19 CoreFoundation 0x01981c7d __invoking___ + 29
20 CoreFoundation 0x01981b51 -[NSInvocation
invoke] + 145
21 WebCore 0x02ecb150
_ZL20HandleDelegateSourcePv + 64
22 CoreFoundation 0x019f28ff
__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
23 CoreFoundation 0x0195088b
__CFRunLoopDoSources0 + 571
24 CoreFoundation 0x0194fd86 __CFRunLoopRun +
470
25 CoreFoundation 0x0194f840
CFRunLoopRunSpecific + 208
26 CoreFoundation 0x0194f761 CFRunLoopRunInMode
+ 97
27 GraphicsServices 0x01c491c4 GSEventRunModal +
217
28 GraphicsServices 0x01c49289 GSEventRun + 115
29 UIKit 0x000bdc93 UIApplicationMain
+ 1160
30 MyApp-ios 0x00002f3f main + 127
31 MyApp-ios 0x00002eb5 start + 53
)
terminate called after throwing an instance of 'NSException'

Kerri Shotts

unread,
Feb 12, 2012, 6:06:42 PM2/12/12
to phon...@googlegroups.com
A few questions:
 - does the app crash on a physical iDevice? (The simulator, great though it is, is /not/ a substitute for a real device. Sometimes they act differently.)
 - Have you whitelisted your remote site? (I assume so, since you get a valid response when using "text")
 - what happens if you just use alert() instead of navigator.notification.alert? 

AaronOnTilt

unread,
Feb 20, 2012, 4:37:33 AM2/20/12
to phonegap
Just wanted to update this thread that the problem seems to have gone
away after upgrading to Lion and xcode 4.2.1
Reply all
Reply to author
Forward
0 new messages