4
votes

I'm using Worklight 6.0.0.1 + 9-26 iFix. A few minutes after a successful call to do a Worklight Connect, our app crashes with this error which looks like it may involve a JSON parsing problem from Worklight:

*** Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFConstantString substringWithRange:]: Range {2147483647, 1} out of bounds; string length 0'
*** First throw call stack:
(
    0   CoreFoundation                      0x021615e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x01ee48b6 objc_exception_throw + 44
    2   CoreFoundation                      0x021613bb +[NSException raise:format:] + 139
    3   CoreFoundation                      0x0213a5e8 -[__NSCFString substringWithRange:] + 136
    4   MyApp                           0x00036546 +[WLUtils parseJSONString:] + 230
    5   MyApp                           0x00032447 -[WLRequest requestFinished:] + 167
    6   libobjc.A.dylib                     0x01ef681f -[NSObject performSelector:withObject:] + 70
    7   MyApp                               0x00058a1b -[ASIHTTPRequest reportFinished] + 171
    8   libobjc.A.dylib                     0x01ef681f -[NSObject performSelector:withObject:] + 70
    9   Foundation                          0x01b39c18 __NSThreadPerformPerform + 285
    10  CoreFoundation                      0x020ea8af __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    11  CoreFoundation                      0x020ea23b __CFRunLoopDoSources0 + 235
    12  CoreFoundation                      0x0210730e __CFRunLoopRun + 910
    13  CoreFoundation                      0x02106b33 CFRunLoopRunSpecific + 467
    14  CoreFoundation                      0x0210694b CFRunLoopRunInMode + 123
    15  GraphicsServices                    0x0337f9d7 GSEventRunModal + 192
    16  GraphicsServices                    0x0337f7fe GSEventRun + 104
    17  UIKit                               0x00c5794b UIApplicationMain + 1225
    18  MyApp                               0x0000b9ad main + 141
    19  libdyld.dylib                       0x02abd725 start + 0
)
libc++abi.dylib: terminating with uncaught exception of type NSException

We're doing the connect like this and getting a success response:

MyConnectListener *connectListener = [[MyConnectListener alloc] init];
[[WLClient sharedInstance] wlConnectWithDelegate:connectListener];


MyConnectListener implements WLDelegate

MyConnectListener.m:
-(void)onSuccess:(WLResponse *)response
{
    NSLog(@"Connection Success: %@", response);
}

-(void)onFailure:(WLFailResponse *)response
{
    NSLog(@"Connection failure: %@", response);
}

Any idea how to solve this?

1
I tried to reproduce your error but it worked for me. It also worked when I got a response back that wasn't JSON. Do you have a way to display the exact response your device is receiving from the server? (through the console logs or using wireshark maybe?)jnortey
In our case, we get a successful response from connect. After several minutes, the app crashes with the error above. Perhaps this is a result of the running heartbeat or some other side effect of adding the connect into the mix.Alvin Richardson
Ahh I see. And are you making any manual requests to the server other than the connect and heartbeat? Can you get the response for whatever call it is that is creating the error? Can you make the call [[WLClient sharedInstance] setHeartBeatInterval:5]; so that the heartbeat will trigger after 5 seconds so that we can confirm if it is the heartbeat or something else?jnortey
So its an iOS7 related issue, steps to reproduce it: 1. Create an xcode project and just do a connect call to the worklight server as done in the question 2. Set [[WLClient sharedInstance] setHeartBeatInterval:1]; If you test project for iOS7 you'll see the crash right away, if you test it for iOS6 you won't see the crash2cupsOfTech
I've reported to the issue to the developers. Will look into it ASAP.Nathan H

1 Answers

1
votes

This has been logged as a defect and will be fixed in a future release. The current workaround is to disable the heartbeat functionality using the following syntax:

[[WLClient sharedInstance] setHeartBeatInterval:-1];