Quellcode durchsuchen

Modify common function structure

Ray Zhang vor 5 Jahren
Ursprung
Commit
4e2663ce41

+ 3 - 1
common/NetworkUtils.m

@@ -827,6 +827,8 @@ repeat:
                         }
                         else
                         {
+                            NSString *str = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
+                            DebugLog(@"request_interface result:%@", str);
                             NSMutableDictionary* dict =[[RAConvertor data2dict:responseData] mutableCopy];
                             if([dict[@"result"] intValue]==RESULT_USERAUTH_ERROR)
                             {
@@ -841,7 +843,7 @@ repeat:
 //                            {
 ////                                RESULT_ERROR
 //                            }
-                            DebugLog(@"request_interface result:%@", [RAConvertor dict2string:dict]);
+
                             dispatch_async(dispatch_get_main_queue(), ^{
                                 if(result)
                                     return result(dict);

+ 4 - 1
common/RAUtils.h

@@ -115,6 +115,9 @@ NS_ASSUME_NONNULL_BEGIN
 + (NSString *_Nullable)deviceID;
 
 + (void)ra_showAlertTitle:(NSString *_Nullable)title message:(NSString *_Nullable)msg withViewController:(UIViewController *_Nonnull)vc;
-
++ (BOOL) validateEmail:(NSString *)email;
++ (BOOL)checkPassword:(NSString *) password;
++ (UIViewController *)getCurrentVCFrom:(UIViewController *)rootVC;
++ (UIViewController *)getCurrentVC;
 @end
 NS_ASSUME_NONNULL_END

+ 56 - 0
common/RAUtils.m

@@ -1061,6 +1061,62 @@ done:
     return expectedSize;
 }
 
+
+
++ (BOOL) validateEmail:(NSString *)email
+{
+    NSString *regex1 = @"\\A[a-z0-9]+([-._][a-z0-9]+)*@([a-z0-9]+(-[a-z0-9]+)*\\.)+[a-z]{2,4}\\z";
+    NSString *regex2 = @"^(?=.{1,64}@.{4,64}$)(?=.{6,100}$).*";
+    NSPredicate *test1 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex1];
+    NSPredicate *test2 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex2];
+    return [test1 evaluateWithObject:email] && [test2 evaluateWithObject:email];
+}
++ (BOOL)checkPassword:(NSString *) password
+{
+    NSString *pattern = @"^(?![0-9]+$)(?![a-zA-Z]+$)[a-zA-Z0-9]{6,18}";
+    NSString *pattern1 = @"^(?=.*)(?=.*[a-z])(?=.*[~!@#$%^&*:;,.=?$\x22]).{8,16}$";
+    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
+    NSPredicate *pred1 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern1];
+    BOOL isMatch = [pred evaluateWithObject:password];//||[pred evaluateWithObject:password];
+    return isMatch;
+    
+}
++ (UIViewController *)getCurrentVC
+{
+    UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
+    
+    UIViewController *currentVC = [self getCurrentVCFrom:rootViewController];
+    
+    return currentVC;
+}
++ (UIViewController *)getCurrentVCFrom:(UIViewController *)rootVC
+{
+    UIViewController *currentVC;
+    
+    if ([rootVC presentedViewController]) {
+        // 视图是被presented出来的
+        
+        rootVC = [rootVC presentedViewController];
+    }
+
+    if ([rootVC isKindOfClass:[UITabBarController class]]) {
+        // 根视图为UITabBarController
+        
+        currentVC = [self getCurrentVCFrom:[(UITabBarController *)rootVC selectedViewController]];
+        
+    } else if ([rootVC isKindOfClass:[UINavigationController class]]){
+        // 根视图为UINavigationController
+        
+        currentVC = [self getCurrentVCFrom:[(UINavigationController *)rootVC visibleViewController]];
+        
+    } else {
+        // 根视图为非导航类
+        
+        currentVC = rootVC;
+    }
+    
+    return currentVC;
+}
 @end
 
 

+ 1 - 8
common/Tab Based Framework/RootViewController.h

@@ -9,14 +9,7 @@
 #import <UIKit/UIKit.h>
 #import "AppDelegate.h"
 #import "const.h"
-//#import "LoginViewController.h"
-//#import "ApexMobileSecondViewController.h"
-//#import "ToolsPanelViewController.h"
-//#import "HomeViewController.h"
-//#import "ToolslistViewController.h"
-//#import "SearchlistViewController.h"
-//#import "MylistViewController.h"
-//#import "OrderHistoryViewController.h"
+
 
 
 @interface RootViewController : UITabBarController

+ 5 - 1
common/common_const.h

@@ -32,6 +32,7 @@
 #define UIColorFromRGBAlpha(rgbValue,alp) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:(alp)]
 
 // 接口json 的result值
+#define RESULT_LOGIN_ON_OTHER_DEVICE -1
 #define RESULT_NO_RESPONSE -1024
 #define RESULT_NET_ERROR             -3
 #define RESULT_NET_NOTAVAILABLE          -4
@@ -39,8 +40,11 @@
 #define RESULT_LOCALFILE_ERROR             -7
 #define RESULT_USERAUTH_ERROR             -9
 #define RESULT_VER_LOW                   -15
-#define RESULT_FALSE 0
+//#define RESULT_FALSE 0
+
+#define RESULT_FALSE 1
 #define RESULT_TRUE         2
+#define RESULT_FAILED_WITH_MESSAGE         9
 #define RESULT_TIMEOUT                   99