I am developing an app that allows the user to view the public twitter feed using the the STTwitter Library (see below code)
STTwitterAPI *twitter = [STTwitterAPI twitterAPIAppOnlyWithConsumerKey:@"**consumer key**"
consumerSecret:@"**consumer secret**"];
[twitter verifyCredentialsWithSuccessBlock:^(NSString *bearerToken) {
[twitter getUserTimelineWithScreenName:@"screenName"
successBlock:^(NSArray *statuses) {
NSLog(@"-- statuses: %@", statuses);
self.statuses = statuses;
[spinner stopAnimating];
[self.tableView reloadData];
} errorBlock:^(NSError *error) {
}];
} errorBlock:^(NSError *error) {
[spinner stopAnimating];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Network Access" message:@"Please Try Later." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
NSLog(@"error: %@", [error localizedDescription]);
NSLog(@"No Network");
}];
When i turn the wifi off on my laptop, the app enters the error block and all is well, the user is presented with an alert saying that a connection is not available.
However as i am using a wifi hotspot (e.g. bt openzone), which requires a login, when i turn the wifi back on and do not log in (meaning i cannot access the internet), the app thinks it has access to the internet and attempts to access the twitter api and crashes.
I've tried using 'Reachability' to try to establish weather or not the internet is available (see below)
Reachability *networkReachability = [Reachability reachabilityForInternetConnection];
NetworkStatus networkStatus = [networkReachability currentReachabilityStatus];
if (networkStatus == NotReachable) {
NSLog(@"There IS NO internet connection");
} else {
NSLog(@"There IS internet connection");
}
However this did not work.
Will apple reject my app for something like this?
Is there a way to stop this from happening?
Thanks for any help :)
EDIT
2014-01-22 08:58:02.268 SWIP[384:a0b] Reachability Flag Status: -R -----l- networkStatusForFlags
2014-01-22 08:58:02.268 SWIP[384:a0b] ***INTERNET AVAILABLE****
2014-01-22 08:58:11.090 SWIP[384:a0b] Reachability Flag Status: -R -----l- networkStatusForFlags
2014-01-22 08:58:11.091 SWIP[384:a0b] ***INTERNET AVAILABLE****
2014-01-22 08:58:17.295 SWIP[384:a0b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSCFString 0xbc47e00> valueForUndefinedKey:]: this class is not key value coding-compliant for the key token_type.'
*** First throw call stack:
(
0 CoreFoundation 0x029205e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x026a38b6 objc_exception_throw + 44
2 CoreFoundation 0x029b06a1 -[NSException raise] + 17
3 Foundation 0x023648ca -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 282
4 Foundation 0x022d1921 _NSGetUsingKeyValueGetter + 81
5 Foundation 0x022d0f5b -[NSObject(NSKeyValueCoding) valueForKey:] + 260
6 SWIP 0x0000375f __65-[STTwitterAppOnly verifyCredentialsWithSuccessBlock:errorBlock:]_block_invoke + 191
7 SWIP 0x00005e8d __109-[STTwitterAppOnly postResource:baseURLString:parameters:useBasicAuth:progressBlock:successBlock:errorBlock:]_block_invoke156 + 173
8 SWIP 0x00037231 __121+[STHTTPRequest(STTwitter) twitterRequestWithURLString:stTwitterProgressBlock:stTwitterSuccessBlock:stTwitterErrorBlock:] _block_invoke48 + 449
9 SWIP 0x00046255 -[STHTTPRequest connectionDidFinishLoading:] + 517
10 Foundation 0x0246db59 ___NSURLConnectionDidFinishLoading_block_invoke + 40
11 Foundation 0x024043e1 __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 62
12 Foundation 0x0228ca6e -[NSURLConnectionInternalConnection invokeForDelegate:] + 119
13 Foundation 0x0228c9d6 -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 208
14 Foundation 0x0228c8e8 -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 76
15 Foundation 0x0228cc98 _NSURLConnectionDidFinishLoading + 43
16 CFNetwork 0x00c78e6f ___ZN27URLConnectionClient_Classic26_delegate_didFinishLoadingEU13block_pointerFvvE_block_invoke + 111
17 CFNetwork 0x00c76bac ___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2 + 104
18 CFNetwork 0x00cc10ef ___ZNK17CoreSchedulingSet13_performAsyncEPKcU13block_pointerFvvE_block_invoke + 25
19 CoreFoundation 0x028c1d59 CFArrayApplyFunction + 57
20 CFNetwork 0x00be05af _ZN19RunloopBlockContext7performEv + 139
21 CFNetwork 0x00cc16d2 _ZThn16_N19RunloopBlockContext24multiplexerClientPerformEv + 20
22 CFNetwork 0x00be03dd _ZN17MultiplexerSource7performEv + 299
23 CFNetwork 0x00be01f2 _ZN17MultiplexerSource8_performEPv + 76
24 CoreFoundation 0x028a983f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
25 CoreFoundation 0x028a91cb __CFRunLoopDoSources0 + 235
26 CoreFoundation 0x028c629e __CFRunLoopRun + 910
27 CoreFoundation 0x028c5ac3 CFRunLoopRunSpecific + 467
28 CoreFoundation 0x028c58db CFRunLoopRunInMode + 123
29 GraphicsServices 0x0345c9e2 GSEventRunModal + 192
30 GraphicsServices 0x0345c809 GSEventRun + 104
31 UIKit 0x01411d3b UIApplicationMain + 1225
32 SWIP 0x0000670d main + 141
33 libdyld.dylib 0x031b2725 start + 0
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
I confirm that this is a crash in the STTwitter library.
I just pushed a fix: https://github.com/nst/STTwitter/commit/54efe271cfc562bad246d08362cda2f221132871
Please let me know if you encounter any further issue.