1

我正在开发一个应用程序,允许用户使用 STTwitter 库查看公共 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 时,应用程序进入错误块并且一切正常,用户会收到一条警告,提示连接不可用。

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

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

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) 
4

2 回答 2

1
Will apple reject my app for something like this?

嗯,它可能不会,但它应该。您正在证明一个正在崩溃的应用程序并且您知道它。至于 wifihotspot,我很难相信你不能使用可达性来做到这一点,因为那段代码出现在很多地方。

这里这里这里

您可以进行另一个测试,而不是上述解决方案:

[Reachability reachabilityWithHostname: @"http://www.google.com"]
于 2014-01-15T11:48:24.143 回答
1

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

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

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

于 2014-01-22T12:10:20.487 回答