Răsfoiți Sursa

修复网络联通性检测失效的问题。
修复底层网络请求和下载接口在网络不可用时返回为空的错误。
修复登录时网络不可用,提示错误的问题。
修复首页请求网络不可用,提示错误的问题。
修复查询时网络不可用,提示错误的问题。

Ray Zhang 6 ani în urmă
părinte
comite
825b5938f8

+ 1 - 1
Apex Mobile/Apex Mobile/Base.lproj/Localizable.strings

@@ -5,7 +5,7 @@
   Created by Ray on 14-5-14.
   Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
 */
-"net_not_available"="Network not available, please check.";
+"net_not_available"="Network connection is not available, please check.";
 "net_error"="Network error, can not access server.";
 "auth_error"="Can not login, user or password may not correct.";
 "ver_low"="Current App version is too low, please update.";

+ 7 - 0
Apex Mobile/Apex Mobile/RANetwork.m

@@ -1888,6 +1888,13 @@
         UIApplication * app = [UIApplication sharedApplication];
         AppDelegate *appDelegate = (AppDelegate *)[app delegate];
         int result = [[jsobj valueForKey:@"result"] intValue];
+        if(result==RESULT_NET_NOTAVAILABLE)
+        {
+            DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
+            [appDelegate Logout];
+            return RESULT_NET_NOTAVAILABLE;
+        }
+        
         if(result!=AP_USER_AUTH)
         {
             DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);

+ 92 - 86
Apex Mobile/Apex Mobile/Result/Presenter/ApexResultPresenter.m

@@ -57,15 +57,19 @@ static const NSInteger detal = 20;
 
 #pragma mark - Data
 
-- (void)loadDataFailed {
+- (void)loadDataFailed:(NSString*)msg {
     
+    if(msg.length==0)
+    {
+        msg=@"Sorry, can not connect to the server, please try again later.";
+    }
     __weak typeof(self) weakSelf = self;
     dispatch_async(dispatch_get_main_queue(), ^{
         if (weakSelf) {
             __strong typeof(weakSelf) strongSelf = weakSelf;
             if (strongSelf.delegate) {
                 [strongSelf.delegate onStopLoading];
-                [strongSelf.delegate onFailed:@"Sorry, can not connect to the server, please try again later."];
+                [strongSelf.delegate onFailed:msg];
             }
         }
     });
@@ -183,95 +187,97 @@ static const NSInteger detal = 20;
                 [strongSelf loadDataSuccessWithTitle:title itemsArray:modelsArr itemCount:items.count];
                 
             } else {
-                [strongSelf loadDataFailed];
+                
+                NSString *msg = [json objectForKey:@"err_msg"];
+                [strongSelf loadDataFailed:msg];
             }
         
     }];
     
     return;
-    
-    dispatch_async(dispatch_get_global_queue(0, 0), ^{
-        
-        NSMutableDictionary *params = [weakSelf.params mutableCopy];
-        [params setObject:[NSNumber numberWithInteger:offset] forKey:@"offset"];
-        [params setObject:[NSNumber numberWithInteger:detal] forKey:@"limit"];
-        [params setObject:displayFields forKey:@"columns"];
-        
-        NSDictionary *json = [RANetwork fetchResultParameters:params];
-        if (weakSelf) {
-            __strong typeof(weakSelf) strongSelf = weakSelf;
-            
-            int result = [[json objectForKey:@"result"] intValue];
-            if (result == RESULT_TRUE) {
-                
-                NSMutableArray *modelsArr = [NSMutableArray array];
-                if (option == ApexResultFetchDataTypeLoadMore && strongSelf.dataArray != nil && strongSelf.dataArray.count > 0) {
-                    [modelsArr addObjectsFromArray:strongSelf.dataArray];
-                }
-                
-                NSArray *items = [json objectForKey:@"items"];
-                for (NSDictionary *item in items) {
-                    
-                    NSInteger type = [[item objectForKey:@"type"] integerValue];
-                    
-                    switch (type) {
-                        case ApexResultTypeBooking: {
-                            ApexResultBookingModel *model = [ApexResultBookingModel new];
-                            [model setValuesForKeysWithDictionary:item];
-                            [modelsArr addObject:model];
-                        }
-                            break;
-                        case ApexResultTypeBLInfo: {
-                            ApexResultBLInfoModel *model = [ApexResultBLInfoModel new];
-                            [model setValuesForKeysWithDictionary:item];
-                            [modelsArr addObject:model];
-                        }
-                            break;
-                        case ApexResultTypeContainer: {
-                            ApexResultContainerModel *model = [ApexResultContainerModel new];
-                            [model setValuesForKeysWithDictionary:item];
-                            [modelsArr addObject:model];
-                        }
-                            break;
-                        case ApexResultTypeDocument: {
-                            ApexResultDocumentModel *model = [ApexResultDocumentModel new];
-                            [model setValuesForKeysWithDictionary:item];
-                            [modelsArr addObject:model];
-                        }
-                            break;
-                        default:
-                            break;
-                    }
-                    
-                } // for
-                strongSelf.offset = modelsArr.count;
-                
-                NSString *title = [json objectForKey:@"title"];
-                strongSelf.rowActions = [json objectForKey:@"row_actions"];
-                strongSelf.actions = [json objectForKey:@"actions"];
-                
-                // menu
-                NSArray *menuArr = [json objectForKey:@"menu"];
-                if (menuArr) {
-                    NSMutableArray *tmpArr = [NSMutableArray array];
-                    for (NSDictionary *item in menuArr) {
-                        
-                        ApexResultMenuItem *menuItem = [ApexResultMenuItem new];
-                        [menuItem setValuesForKeysWithDictionary:item];
-                        [tmpArr addObject:menuItem];
-                    }
-                    strongSelf.menuItems = [tmpArr copy];
-                }
-                
-                // refresh UI
-                [strongSelf loadDataSuccessWithTitle:title itemsArray:modelsArr itemCount:items.count];
-                
-            } else {
-                [strongSelf loadDataFailed];
-            }
-        }
-        
-    });
+//
+//    dispatch_async(dispatch_get_global_queue(0, 0), ^{
+//
+//        NSMutableDictionary *params = [weakSelf.params mutableCopy];
+//        [params setObject:[NSNumber numberWithInteger:offset] forKey:@"offset"];
+//        [params setObject:[NSNumber numberWithInteger:detal] forKey:@"limit"];
+//        [params setObject:displayFields forKey:@"columns"];
+//
+//        NSDictionary *json = [RANetwork fetchResultParameters:params];
+//        if (weakSelf) {
+//            __strong typeof(weakSelf) strongSelf = weakSelf;
+//
+//            int result = [[json objectForKey:@"result"] intValue];
+//            if (result == RESULT_TRUE) {
+//
+//                NSMutableArray *modelsArr = [NSMutableArray array];
+//                if (option == ApexResultFetchDataTypeLoadMore && strongSelf.dataArray != nil && strongSelf.dataArray.count > 0) {
+//                    [modelsArr addObjectsFromArray:strongSelf.dataArray];
+//                }
+//
+//                NSArray *items = [json objectForKey:@"items"];
+//                for (NSDictionary *item in items) {
+//
+//                    NSInteger type = [[item objectForKey:@"type"] integerValue];
+//
+//                    switch (type) {
+//                        case ApexResultTypeBooking: {
+//                            ApexResultBookingModel *model = [ApexResultBookingModel new];
+//                            [model setValuesForKeysWithDictionary:item];
+//                            [modelsArr addObject:model];
+//                        }
+//                            break;
+//                        case ApexResultTypeBLInfo: {
+//                            ApexResultBLInfoModel *model = [ApexResultBLInfoModel new];
+//                            [model setValuesForKeysWithDictionary:item];
+//                            [modelsArr addObject:model];
+//                        }
+//                            break;
+//                        case ApexResultTypeContainer: {
+//                            ApexResultContainerModel *model = [ApexResultContainerModel new];
+//                            [model setValuesForKeysWithDictionary:item];
+//                            [modelsArr addObject:model];
+//                        }
+//                            break;
+//                        case ApexResultTypeDocument: {
+//                            ApexResultDocumentModel *model = [ApexResultDocumentModel new];
+//                            [model setValuesForKeysWithDictionary:item];
+//                            [modelsArr addObject:model];
+//                        }
+//                            break;
+//                        default:
+//                            break;
+//                    }
+//
+//                } // for
+//                strongSelf.offset = modelsArr.count;
+//
+//                NSString *title = [json objectForKey:@"title"];
+//                strongSelf.rowActions = [json objectForKey:@"row_actions"];
+//                strongSelf.actions = [json objectForKey:@"actions"];
+//
+//                // menu
+//                NSArray *menuArr = [json objectForKey:@"menu"];
+//                if (menuArr) {
+//                    NSMutableArray *tmpArr = [NSMutableArray array];
+//                    for (NSDictionary *item in menuArr) {
+//
+//                        ApexResultMenuItem *menuItem = [ApexResultMenuItem new];
+//                        [menuItem setValuesForKeysWithDictionary:item];
+//                        [tmpArr addObject:menuItem];
+//                    }
+//                    strongSelf.menuItems = [tmpArr copy];
+//                }
+//
+//                // refresh UI
+//                [strongSelf loadDataSuccessWithTitle:title itemsArray:modelsArr itemCount:items.count];
+//
+//            } else {
+//                [strongSelf loadDataFailed];
+//            }
+//        }
+//
+//    });
 }
 
 - (void)loadData {

+ 1 - 1
Apex Mobile/Apex Mobile/config.h

@@ -13,7 +13,7 @@
 # ifdef DEBUG
 #define DEBUG_DB
 
-#define test_server
+//#define test_server
 //#define old_server
 
 # endif

+ 14 - 5
common/NetworkUtils.m

@@ -32,8 +32,9 @@
 +(bool) IsNetworkAvailable
 {
     
-    if (([Reachability reachabilityForInternetConnection].currentReachabilityStatus == NotReachable) &&
-        ([Reachability reachabilityForLocalWiFi].currentReachabilityStatus == NotReachable))
+    if (([Reachability reachabilityForInternetConnection].currentReachabilityStatus == NotReachable)
+       /* &&
+        ([Reachability reachabilityForLocalWiFi].currentReachabilityStatus == NotReachable)*/)
         return false;
     return true;
 }
@@ -582,7 +583,7 @@ repeat:
         {
             dispatch_async(dispatch_get_main_queue(), ^{
                 if(result)
-                    result([[RAConvertor string2dict:[NSString stringWithFormat:@"{'result':%d}",RESULT_NET_NOTAVAILABLE]] mutableCopy]);
+                    result([[RAConvertor string2dict:[NSString stringWithFormat:@"{\"result\":%d}",RESULT_NET_NOTAVAILABLE]] mutableCopy]);
             });
     //        return detailContent;
             return nil;
@@ -935,7 +936,7 @@ repeat:
         {
             dispatch_async(dispatch_get_main_queue(), ^{
                 if(result)
-                    result([[RAConvertor string2dict:[NSString stringWithFormat:@"{'result':%d}",RESULT_NET_NOTAVAILABLE]] mutableCopy]);
+                    result([[RAConvertor string2dict:[NSString stringWithFormat:@"{\"result\":%d}",RESULT_NET_NOTAVAILABLE]] mutableCopy]);
             });
     //        return detailContent;
             return ;
@@ -1693,7 +1694,15 @@ repeat:
 // Param:(NSDictionary *)param from:(NSString *)url    completionHandler:(resultHandler)result
 /* dataHandler:(dataHandler)returndata*/
 {
-    
+        if(![NetworkUtils IsNetworkAvailable])
+        {
+            dispatch_async(dispatch_get_main_queue(), ^{
+                if(result)
+                    result([[RAConvertor string2dict:[NSString stringWithFormat:@"{\"result\":%d}",RESULT_NET_NOTAVAILABLE]] mutableCopy]);
+            });
+    //        return detailContent;
+            return ;
+        }
     params = [self prepare_addtional_params:params];
 
     NSURLSession *urlSession = [self standSession];