'false' 连接可用时 iOS 应用程序崩溃

标签 ios crash wifi reachability sttwitter

我正在开发一个应用程序,允许用户使用 STTwitter 库(见下面的代码)查看公共(public) Twitter 提要

    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");

 }];

当我关闭笔记本电脑上的 wifi 时,应用程序进入错误 block ,一切正常,用户会收到一条警告,提示连接不可用。

然而,由于我使用的是 wifi 热点(例如 bt openzone),它需要登录,当我重新打开 wifi 但没有登录(意味着我无法访问互联网)时,应用程序认为它可以访问互联网并尝试访问 twitter api 并崩溃。

我试过使用“Reachability”来确定天气或互联网是否可用(见下文)

Reachability *networkReachability = [Reachability reachabilityForInternetConnection];
NetworkStatus networkStatus = [networkReachability currentReachabilityStatus];
if (networkStatus == NotReachable) {
    NSLog(@"There IS NO internet connection");
} else {

    NSLog(@"There IS internet connection");

}

但是这没有用。

苹果会因为这样的事情拒绝我的应用吗?

有没有办法阻止这种情况发生?

感谢您的帮助:)

编辑

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) 

最佳答案

我确认这是 STTwitter 库中的崩溃。

我刚刚推送了一个修复:https://github.com/nst/STTwitter/commit/54efe271cfc562bad246d08362cda2f221132871

如果您遇到任何进一步的问题,请告诉我。

关于 'false' 连接可用时 iOS 应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21136475/

相关文章:

objective-c - 具有相同符号的两个框架

ios - 如何根据 UITextView 的内容调整 UITextView 和 UITableViewCell 的大小

ios - 查找两个时间戳之间的差异 - iOS

ios - 从 TestFlight 打开时应用程序崩溃,但在其他情况下工作正常

android - 主要 Activity 从 Activity 扩展时,tabactivity崩溃

Android IP 流量路由 - WiFi 上的蜂窝 IP?

android - 如何以编程方式检查手机是否支持 wifi?

ios - 将图像添加到我的 UIButton subview

android - 登录屏幕后,我的Android应用程序崩溃

github - process.env.wifi_interface有什么作用?