iPhone PhoneGap: exception is raised when calling network.isReachable with the reachableOptions argument

Skip to first unread message

Dennis Z Jiang

Jan 9, 2011, 6:11:11 PM1/9/11
to phonegap
I get an exception if I call the network.isReachable() function with
the optional argument 'reachableOptions'. Below is what the call looks

navigator.network.isReachable("", reachableCallback,
{ isIpAddress: true });

The PhoneGap code that causes the exception is in the existsValue()
method in Categories.m, highlighted below with the "==>" mark. It
appears to me that a bool value is being casted to a string, causing
the exception. However, I am new to objective-C and I don't understand
the code or the exception message well enough to be 100% sure that is
the case. Any thoughts?

- (bool) existsValue:(NSString*)expectedValue forKey:(NSString*)key
id val = [self valueForKey:key];
bool exists = false;
if (val != nil) {
==> exists = [(NSString*)val compare:expectedValue
options:NSCaseInsensitiveSearch] == 0;

return exists;

2011-01-09 17:51:13.897 gwtmobile-phonegap-iphone[326:207] ***
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[NSCFBoolean
compare:options:]: unrecognized selector sent to instance 0x1904ef8'
*** Call stack at first throw:
0 CoreFoundation 0x01896be9
__exceptionPreprocess + 185
1 libobjc.A.dylib 0x019eb5c2
objc_exception_throw + 47
2 CoreFoundation 0x018986fb -
[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x01808366 ___forwarding___ +
4 CoreFoundation 0x01807f22
_CF_forwarding_prep_0 + 50
5 gwtmobile-phonegap-iphone 0x0000338e -
[NSMutableDictionary(NSDictionary_Extension) existsValue:forKey:] +
6 gwtmobile-phonegap-iphone 0x0000e900 -[Network
isReachable:withDict:] + 222
7 gwtmobile-phonegap-iphone 0x00012fac -[PhoneGapDelegate
execute:] + 379
8 gwtmobile-phonegap-iphone 0x00002311 -
[gwtmobile_phonegap_iphoneAppDelegate execute:] + 60
9 gwtmobile-phonegap-iphone 0x00012dc1 -[PhoneGapDelegate
webView:shouldStartLoadWithRequest:navigationType:] + 233
10 gwtmobile-phonegap-iphone 0x000022cf -
webView:shouldStartLoadWithRequest:navigationType:] + 74
11 UIKit 0x00485792 -[UIWebView
+ 291
12 CoreFoundation 0x0180767d __invoking___ + 29
13 CoreFoundation 0x01807551 -[NSInvocation
invoke] + 145
14 CoreFoundation 0x01835258 -[NSInvocation
invokeWithTarget:] + 72
15 WebKit 0x023e1366 -
[_WebSafeForwarder forwardInvocation:] + 182
16 CoreFoundation 0x01808404 ___forwarding___ +
17 CoreFoundation 0x01807f22
_CF_forwarding_prep_0 + 50
18 CoreFoundation 0x0180767d __invoking___ + 29
19 CoreFoundation 0x01807551 -[NSInvocation
invoke] + 145
20 WebCore 0x025edc30
_ZL20HandleDelegateSourcePv + 64
21 CoreFoundation 0x0187801f
22 CoreFoundation 0x017d628b
__CFRunLoopDoSources0 + 571
23 CoreFoundation 0x017d5786 __CFRunLoopRun +
24 CoreFoundation 0x017d5240
CFRunLoopRunSpecific + 208
25 CoreFoundation 0x017d5161 CFRunLoopRunInMode
+ 97
26 GraphicsServices 0x01f9e268 GSEventRunModal +
27 GraphicsServices 0x01f9e32d GSEventRun + 115
28 UIKit 0x0030142e UIApplicationMain
+ 1160
29 gwtmobile-phonegap-iphone 0x000020d6 main + 104
30 gwtmobile-phonegap-iphone 0x00002065 start + 53


Jan 10, 2011, 1:59:03 PM1/10/11
to phonegap
Hi Dennis. If you recently upgraded to PhoneGap 0.9.3, the solution
might be to uninstall and reinstall PhoneGap. Billy Cravens suggested
that as a solution to the network problem that I was having.

In my case, everything had been working until I upgraded. To be sure,
you could start with a virgin PhoneGap app, copy the network code from
the documentation, and see whether the virgin app crashes. If so, as
it was in my case, reinstalling might do the trick.

Dennis Z Jiang

Jan 12, 2011, 10:47:05 PM1/12/11
to phonegap
Alan, mine is a fresh 0.9.3 install. But thanks for the suggestion

I looked at this exception further. The code that actually causes the
exception is in the Network.isReachable method, where it checks if the
isIpAddress option is set to true. See code below. The if statement
seems to check if the value is a string "true" instead of a boolean
true. Again I am not a objective-c programmer, so I could have
interpreted the code incorrectly. (I am a c/c++ programmer, but no way
a c/c++ programmer can understand objective-c syntax without some
serious learning.)

==> if ([options existsValue:@"true" forKey:@"isIpAddress"]) {
[[Reachability sharedReachability] setAddress:hostName];
} else {
[[Reachability sharedReachability] setHostName:hostName];

I looked around the code and found another place where a boolean
option is checked, but differently. Below is code found in Camera.m

bool allowEdit = [[options valueForKey:@"allowEdit"] boolValue];

I think this is the right way to check bool value in objectivc-c.

Dennis Z Jiang

Jan 16, 2011, 11:24:57 AM1/16/11
to phonegap
Following how bool is handled in Camera.m, I changed the code in
Network.isReachable as below. That fixed the exception. Now it is
clear to me that this is a bug in Network.isReachable.

bool isIpAddress = [[options valueForKey:@"isIpAddress"] boolValue];
if (isIpAddress) {
// if ([options existsValue:@"true" forKey:@"isIpAddress"]) {

Daniel Kurka

Mar 14, 2011, 6:43:57 AM3/14/11
to phonegap
did someone put in a bug report for this issue?

Dennis Z Jiang

Mar 14, 2011, 11:59:45 AM3/14/11
to phonegap
I believe this has been fixed. It may not have made it in time for the
0.9.4 release though. The latest code in github should have it.
Reply all
Reply to author
0 new messages