Просмотр исходного кода

1.修改Login和根视图的切换方式。
2.完善Login相关细节。
3.实现Network的登录登出。

Pen Li 9 лет назад
Родитель
Сommit
e66162cb03

+ 1 - 1
RA Image/RA Image.xcodeproj/project.pbxproj

@@ -277,12 +277,12 @@
 		71DCDC361EAF234E00BA045A /* RA Image */ = {
 			isa = PBXGroup;
 			children = (
-				71114AE21EB2DEE800D2200C /* cam scan */,
 				71114AB71EB1C68B00D2200C /* const.h */,
 				71114AB81EB1C6B700D2200C /* config.h */,
 				71114AA71EB1C51200D2200C /* util */,
 				42E1B10D1EB1E91D00EEF27C /* Network */,
 				71DCDC4E1EAF34F800BA045A /* modes */,
+				71114AE21EB2DEE800D2200C /* cam scan */,
 				42E1B0F71EB1C8BB00EEF27C /* Login */,
 				42E1B10E1EB1E93E00EEF27C /* Root */,
 				71DCDC3A1EAF234E00BA045A /* AppDelegate.h */,

BIN
RA Image/RA Image.xcodeproj/project.xcworkspace/xcuserdata/macmini1.xcuserdatad/UserInterfaceState.xcuserstate


+ 7 - 0
RA Image/RA Image.xcodeproj/xcuserdata/macmini1.xcuserdatad/xcschemes/RA Image.xcscheme

@@ -61,6 +61,13 @@
             ReferencedContainer = "container:RA Image.xcodeproj">
          </BuildableReference>
       </BuildableProductRunnable>
+      <EnvironmentVariables>
+         <EnvironmentVariable
+            key = "OS_ACTIVITY_MODE"
+            value = "disable"
+            isEnabled = "YES">
+         </EnvironmentVariable>
+      </EnvironmentVariables>
       <AdditionalOptions>
       </AdditionalOptions>
    </LaunchAction>

+ 2 - 0
RA Image/RA Image/AppDelegate.h

@@ -22,5 +22,7 @@
 
 - (void)showLoginVC;
 
+- (void)logout;
+
 @end
 

+ 9 - 0
RA Image/RA Image/AppDelegate.m

@@ -29,6 +29,15 @@
     }
 }
 
+- (void)logout {
+    self.user = nil;
+    self.password = nil;
+    self.address = nil;
+    self.bLogin = false;
+    
+    [self showLoginVC];
+}
+
 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
     // Override point for customization after application launch.
     

+ 10 - 0
RA Image/RA Image/Assets.xcassets/AppIcon.appiconset/Contents.json

@@ -1,5 +1,15 @@
 {
   "images" : [
+    {
+      "idiom" : "iphone",
+      "size" : "20x20",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "iphone",
+      "size" : "20x20",
+      "scale" : "3x"
+    },
     {
       "idiom" : "iphone",
       "size" : "29x29",

+ 4 - 0
RA Image/RA Image/Info.plist

@@ -34,5 +34,9 @@
 		<string>UIInterfaceOrientationLandscapeLeft</string>
 		<string>UIInterfaceOrientationLandscapeRight</string>
 	</array>
+	<key>NSCameraUsageDescription</key>
+	<string>Need Use Camera</string>
+	<key>NSPhotoLibraryUsageDescription</key>
+	<string>Need Use Photo Library</string>
 </dict>
 </plist>

+ 9 - 0
RA Image/RA Image/LoginSettingViewController.m

@@ -7,6 +7,7 @@
 //
 
 #import "LoginSettingViewController.h"
+#import "ScannerViewController.h"
 
 static NSString *kScanAddress = @"ScanAddress";
 
@@ -52,6 +53,7 @@ static NSString *kScanAddress = @"ScanAddress";
 #pragma mark - Button Click
 
 - (void)doneItemClick:(UIBarButtonItem *)sender {
+    self.checkedAddress = nil;
     if (self.externalCheckBtn.selected) self.checkedAddress = self.externalTextField.text;
     if (self.internalCheckBtn.selected) self.checkedAddress = self.internalTextField.text;
     if (self.checkedAddress && self.returnValue) {
@@ -61,6 +63,13 @@ static NSString *kScanAddress = @"ScanAddress";
 }
 
 - (void)scanItemClick:(UIBarButtonItem *)sender {
+    
+    ScannerViewController *scannerVC = [[UIStoryboard storyboardWithName:@"cam_scan" bundle:nil] instantiateViewControllerWithIdentifier:@"ScannerViewController"];
+    scannerVC.returnCode = ^(NSString *code) {
+        NSLog(@"code %@",code);
+    };
+    [self presentViewController:scannerVC animated:YES completion:nil];
+    
     // 扫描成功保存扫描值
     if (true) {
         NSString *internalAddr = @"http://192.168.0.155/wm_postgresql/handset_login.php";

+ 20 - 10
RA Image/RA Image/LoginViewController.m

@@ -53,12 +53,14 @@ static NSString *kLoginUserInfo = @"UserInfo";
 
 - (void)initUserData {
     NSString *userData = [self userDefaultsValue:kLoginUserInfo];
-    NSArray *arr = [userData componentsSeparatedByString:@"&"];
-    [arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
-        if (idx == 0) self.address = obj;
-        if (idx == 1) self.user = obj;
-        if (idx == 2) self.pwd = obj;
-    }];
+    if (userData) {
+        NSArray *arr = [userData componentsSeparatedByString:@"&"];
+        [arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
+            if (idx == 0) self.address = obj;
+            if (idx == 1) self.user = obj;
+            if (idx == 2) self.pwd = obj;
+        }];
+    }
 }
 
 - (void)prepareUserData {
@@ -139,7 +141,7 @@ static NSString *kLoginUserInfo = @"UserInfo";
 #pragma mark - Delegate
 
 - (void)switchButton:(UISwitch *)switchBtn valueChange:(BOOL)value {
-    if (!value) [self setUserDefaultsValue:nil forKey:kLoginUserInfo];
+    
     [self setUserDefaultsValue:@(value) forKey:kRememberLogin];
 }
 
@@ -172,9 +174,17 @@ static NSString *kLoginUserInfo = @"UserInfo";
             dispatch_async(dispatch_get_main_queue(), ^{
                 [alert dismissWithClickedButtonIndex:0 animated:YES];
                 int result = [[loginDic objectForKey:@"result"] intValue];
-                if (result == 1 && [strongself userDefaultsValue:kRememberLogin]) {
-                    [strongself setUserDefaultsValue:[NSString stringWithFormat:@"%@&%@&%@",strongself.address,strongself.user,strongself.pwd] forKey:kLoginUserInfo];
+                BOOL rememberLogin = [[strongself userDefaultsValue:kRememberLogin] boolValue];
+                if (result == 1) {
+                    if (!rememberLogin) {
+                        [self setUserDefaultsValue:nil forKey:kLoginUserInfo];
+                    } else {
+                         [strongself setUserDefaultsValue:[NSString stringWithFormat:@"%@&%@&%@",strongself.address,strongself.user,strongself.pwd] forKey:kLoginUserInfo];
+                    }
                     appDelegate.bLogin = YES;
+                    appDelegate.user = strongself.user;
+                    appDelegate.password = strongself.pwd;
+                    
                     [appDelegate showNormalRootVC];
                 } else {
                     NSString *msg = [loginDic objectForKey:@"err_msg"];
@@ -191,7 +201,7 @@ static NSString *kLoginUserInfo = @"UserInfo";
     LoginSettingViewController *loginSettingVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginSettingViewController"];
     __weak typeof(self) weakself = self;
     loginSettingVC.returnValue = ^(NSString *address) {
-        if (weakself) {
+        if (weakself && address.length) {
             __strong typeof(weakself) strongself = weakself;
             strongself.address = address;
             [strongself.loginTable reloadData];

+ 3 - 1
RA Image/RA Image/RAINetwork.m

@@ -119,8 +119,10 @@
 + (NSDictionary *)logout {
     NSMutableDictionary *params = @{
                                     }.mutableCopy;
+    AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
+    NSString *urlStr = [appDelegate.address stringByAppendingString:@"/index.php?_operate=logout"];
     
-    NSData *data = [self get_json:nil parameters:params file:nil];
+    NSData *data = [self get_json:urlStr parameters:params file:nil];
     NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
     return resultDic;
 }

+ 25 - 3
RA Image/RA Image/RootViewController.m

@@ -19,9 +19,7 @@
     [super viewDidLoad];
     // Do any additional setup after loading the view, typically from a nib.
     
-    self.view.backgroundColor = [UIColor redColor];
-    
-
+    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Logout" style:UIBarButtonItemStylePlain target:self action:@selector(logoutItemClick:)];
 }
 
 - (void)viewWillAppear:(BOOL)animated {
@@ -36,5 +34,29 @@
     // Dispose of any resources that can be recreated.
 }
 
+- (void)logoutItemClick:(UIBarButtonItem *)sender {
+    UIAlertView *alert = [RAUtils waiting_alert:@"Please wait..." title:@"Logout"];
+    __weak typeof(self) weakself = self;
+    dispatch_async(dispatch_get_main_queue(), ^{
+        
+        NSDictionary *logoutDic = [RAINetwork logout];
+        int result = [[logoutDic objectForKey:@"result"] intValue];
+        dispatch_async(dispatch_get_main_queue(), ^{
+            [alert dismissWithClickedButtonIndex:0 animated:YES];
+            AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
+            if (result == RESULT_TRUE) {
+                [appDelegate logout];
+            } else {
+               __strong typeof(weakself) strongself = weakself;
+                NSString *msg = [logoutDic objectForKey:@"err_msg"];
+                [RAUtils message_alert:msg title:@"Warning" controller:strongself];
+            }
+        });
+
+        
+    });
+
+}
+
 
 @end