Sfoglia il codice sorgente

Merge branch 'master' of ssh://61.40.220.21:/cable/git-repo/mobile/ios

TaeHyun 8 anni fa
parent
commit
29f89f38a8

+ 0 - 2
OneCable.xcodeproj/project.pbxproj

@@ -498,7 +498,6 @@
 		A5F267D81E544A530096276E /* NSNetService+Util.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSNetService+Util.h"; sourceTree = "<group>"; };
 		A5F267D91E544A530096276E /* NSNetService+Util.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSNetService+Util.m"; sourceTree = "<group>"; };
 		ADE7CA33EFEB615D1B6CB053 /* Pods-OneCable.adhoc.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OneCable.adhoc.xcconfig"; path = "Pods/Target Support Files/Pods-OneCable/Pods-OneCable.adhoc.xcconfig"; sourceTree = "<group>"; };
-		E28CB0B91E70083D004DC3FC /* MoreButtonDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MoreButtonDelegate.h; sourceTree = "<group>"; };
 		E2AA822B1E6FD652009B8077 /* MorePopOverViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MorePopOverViewController.h; sourceTree = "<group>"; };
 		E2AA822C1E6FD652009B8077 /* MorePopOverViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MorePopOverViewController.m; sourceTree = "<group>"; };
 		FE2DCDFBF6442768EBBE8107 /* Pods-OneCable.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OneCable.debug.xcconfig"; path = "Pods/Target Support Files/Pods-OneCable/Pods-OneCable.debug.xcconfig"; sourceTree = "<group>"; };
@@ -695,7 +694,6 @@
 				A13BCEEE1C3B491300C76527 /* PopTableView.xib */,
 				A15D2CFA1C58598F0018D555 /* KNLayoutConstraint.h */,
 				A15D2CFB1C58598F0018D555 /* KNLayoutConstraint.m */,
-				E28CB0B91E70083D004DC3FC /* MoreButtonDelegate.h */,
 			);
 			path = CommonUI;
 			sourceTree = "<group>";

+ 4 - 0
OneCable/Classes/Common.h

@@ -89,6 +89,10 @@
 #define XCODE_COLORS_RESET_BG   XCODE_COLORS_ESCAPE @"bg;" // Clear any background color
 #define XCODE_COLORS_RESET      XCODE_COLORS_ESCAPE @";"   // Clear any foreground or background color
 
+#define CASE(str)                       if ([__s__ isEqualToString:(str)])
+#define SWITCH(s)                       for (NSString *__s__ = (s); ; )
+#define DEFAULT
+
 #ifdef DEBUG_MODE
 
 static const int ddLogLevel = DDLogLevelDebug;

+ 0 - 16
OneCable/Classes/CommonUI/MoreButtonDelegate.h

@@ -1,16 +0,0 @@
-//
-//  MoreButtonDelegate.h
-//  OneCable
-//
-//  Created by nComz on 2017. 3. 8..
-//  Copyright © 2017년 ntels. All rights reserved.
-//
-
-#import <UIKit/UIKit.h>
-
-@protocol MoreButtonDelegate <NSObject>
-
-@optional
-
--(void)returnMoreId:(id)moreButtonId;
-@end

+ 1 - 1
OneCable/Classes/CommonUI/MorePopOverViewController.h

@@ -20,7 +20,7 @@
 @class WYPopoverController;
 @interface MorePopOverViewController : JDViewController<MoreButtonDelegate>
 
-@property (weak,nonatomic) id<MoreButtonDelegate> moreDelegate;
+@property (weak,nonatomic) id<MoreButtonDelegate> delegate;
 
 
 @property (weak, nonatomic) IBOutlet UIStackView *viewPopup;

+ 2 - 2
OneCable/Classes/CommonUI/MorePopOverViewController.m

@@ -68,8 +68,8 @@
 
 
 - (IBAction)btnAction:(id)sender {
-    if([self.moreDelegate respondsToSelector:@selector(moreBtnAction:)]){
-        [self.moreDelegate moreBtnAction:sender];
+    if([self.delegate respondsToSelector:@selector(moreBtnAction:)]){
+        [self.delegate moreBtnAction:sender];
     }
 }
 

+ 1 - 1
OneCable/Classes/Definitions.h

@@ -48,7 +48,7 @@ static NSString *kSocketServer = @"ws://61.40.220.23:7792";      //운영
 #define API_ROOT_PATH       @"/ocs/v1"
 
 //1 - 공통
-#define API_GET_APP_VERSION     @"/mobile_app/version"
+#define API_POST_APP_VERSION     @"/mobile_app/version"
 //#define API_GET_CODE_LIST   @"/getCodeList"
 
 #define API_GET_MOBILE                  @"/mobile_device/%@"

+ 7 - 3
OneCable/Classes/Handler/SocketServiceHandler.h

@@ -7,12 +7,16 @@
 //
 
 #import <Foundation/Foundation.h>
+#import <SocketRocket/SRWebSocket.h>
 
 @protocol SocketServiceDelegate <NSObject>
 
 @optional
 - (void) socketConnectComplete;
-- (void) didReceiveMessage:(id)message;
+- (void) socketDidReceiveMessage:(id)message;
+- (void) didFailWithError:(NSError *)error;
+- (void) socketDidReceivePong:(NSData *)pongPayload;
+- (void) socketDidCloseWithCode:(NSInteger)code;
 
 @end
 
@@ -31,9 +35,9 @@
 
 - (void) sendData:(NSDictionary *)data;
 
-- (void) initWithDelegate:(id<SocketServiceDelegate>) delegate;
-
+- (void) initDelegate:(id<SocketServiceDelegate>) delegate;
 
+- (SRReadyState) getSocketStatus;
 
 
 @end

+ 82 - 38
OneCable/Classes/Handler/SocketServiceHandler.m

@@ -7,13 +7,19 @@
 //
 
 #import "SocketServiceHandler.h"
-#import <SocketRocket/SRWebSocket.h>
+
 #import "Definitions.h"
 
+#import "JDJSONModel.h"
+
+#define MAX_RETRY_CONNECT_COUNT 1
+
 @interface SocketServiceHandler() <SRWebSocketDelegate>
 {
     SRWebSocket *_socket;
     NSMutableArray<NSDictionary *> *_messages;
+    
+    int _retryCount;
 }
 @end
 
@@ -49,11 +55,17 @@
     return self;
 }
 
-- (void) initWithDelegate:(id<SocketServiceDelegate>) delegate
+- (void) initDelegate:(id<SocketServiceDelegate>) delegate
 {
     [self setDelegate:delegate];
 }
 
+
+- (SRReadyState) getSocketStatus
+{
+    return _socket.readyState;
+}
+
 - (void) socketOpen
 {
     NSLog(@"socketOpen");
@@ -94,17 +106,19 @@
         [_socket close];
         _socket = nil;
     }
+    else
+    {
+        if (_socket != nil)
+        {
+            _socket = nil;
+        }
+    }
+    _isConnected = NO;
 }
 
 - (void) sendData:(NSDictionary *)data
 {
-//    if(!_isConnected)
-//    {
-//        [_messages addObject:data];
-//        [self socketOpen];
-//    }
-    
-    
+
     if(_socket.readyState == SR_OPEN)
     {
         NSError *error;
@@ -139,16 +153,24 @@
 
 -(void) reConnect
 {
-    [self close];
-    _socket = nil;
-    [self socketOpen];
+    if(_retryCount < MAX_RETRY_CONNECT_COUNT)
+    {
+        _retryCount++;
+        [self close];
+        _socket = nil;
+        [self socketOpen];
+    }
+    else
+    {
+        [self close];
+    }
 }
 
 #pragma mark - SRWebSocketDelegate
 - (void)webSocketDidOpen:(SRWebSocket *)webSocket
 {
     NSLog(@"SOCKET didOpen");
-    
+    _retryCount = 0;
     // Open이 되지 않은 상태에서 전송시도한 메세지들을 발송한다.
     for (NSDictionary *data in _messages)
     {
@@ -165,9 +187,7 @@
 {
     NSLog(@"SOCKET didReceiveMessage : %@", message);
     
-    if (self.delegate && [self.delegate respondsToSelector:@selector(didReceiveMessage:)]) {
-        [self.delegate didReceiveMessage:message];
-    }
+    
     
     NSString *errString = @"";
     
@@ -175,30 +195,54 @@
         errString = @"message empty";
     else
     {
-        if( [message isKindOfClass:[NSString class]] )
-        {
-            NSError* error = nil;
-            NSDictionary *jsonObj = [NSJSONSerialization JSONObjectWithData:[message dataUsingEncoding:NSUTF8StringEncoding]
-                                                                    options:NSJSONReadingMutableContainers
-                                                                      error:&error];
-            
-            if (error != nil) {
-                NSLog(@"NSJSONSerialization JSONObject error: %@", [error localizedDescription]);
-                return;
-            }
-            
-            NSInteger msgType = [jsonObj[@"type"] integerValue];
+        NSError* error = nil;
+//        NSString *JSONString = [[NSString alloc] initWithData:[message dataUsingEncoding:NSUTF8StringEncoding] encoding:NSUTF8StringEncoding];
+        NSDictionary *jsonObj = [NSJSONSerialization JSONObjectWithData:[message dataUsingEncoding:NSUTF8StringEncoding]
+                                                     options:NSJSONReadingAllowFragments
+                                                       error:&error];
+        
+        id JSONModel = nil;
+
+//        if ([jsonObj isKindOfClass:[NSArray class]])
+//        {
+//            NSDictionary *JSONDic = @{@"list": jsonObj};
+//            
+//        }
+//        else
+//        {
+//            JSONModel = [[SocketModel alloc] initWithString:JSONString error:&error];
+//        }
+        JSONModel = [[SocketModel alloc] initWithDictionary:jsonObj error:&error];
+        
+        if (self.delegate && [self.delegate respondsToSelector:@selector(socketDidReceiveMessage:)]) {
             
-            if ( msgType == 0 ) {
-                
-            }
-
-            else
-            {
-                NSLog(@"msgType : %i",(int)msgType);
-                
-            }
+            [self.delegate socketDidReceiveMessage:JSONModel];
         }
+        
+//        if( [message isKindOfClass:[NSString class]] )
+//        {
+//            NSError* error = nil;
+//            NSDictionary *jsonObj = [NSJSONSerialization JSONObjectWithData:[message dataUsingEncoding:NSUTF8StringEncoding]
+//                                                                    options:NSJSONReadingMutableContainers
+//                                                                      error:&error];
+//            
+//            if (error != nil) {
+//                NSLog(@"NSJSONSerialization JSONObject error: %@", [error localizedDescription]);
+//                return;
+//            }
+//            
+//            NSInteger msgType = [jsonObj[@"type"] integerValue];
+//            
+//            if ( msgType == 0 ) {
+//                
+//            }
+//
+//            else
+//            {
+//                NSLog(@"msgType : %i",(int)msgType);
+//                
+//            }
+//        }
     }
 }
 

+ 9 - 0
OneCable/Classes/Model/JDJSONModel.h

@@ -62,3 +62,12 @@
 @property (copy, nonatomic) NSString *ownerYn;
 
 @end
+
+
+@interface SocketModel : JDJSONModel
+
+@property (copy, nonatomic) NSString *messageType;
+@property (copy, nonatomic) NSString *resultMsg;
+
+
+@end

+ 6 - 1
OneCable/Classes/Model/JDJSONModel.m

@@ -62,4 +62,9 @@
 
 @implementation QRAuthModel
 
-@end
+@end
+
+
+@implementation SocketModel
+
+@end

+ 4 - 0
OneCable/Classes/ViewControllers/JDViewController.h

@@ -36,6 +36,10 @@
 - (void)dismissOptionPopOver:(void (^)(void))completion;
 
 
+- (void)sendDataToSocket:(NSDictionary *)data;
+- (BOOL)isSocketConnected;
+- (SRReadyState)getSocketStatus;
+
 //table view
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
 

+ 18 - 1
OneCable/Classes/ViewControllers/JDViewController.m

@@ -83,7 +83,7 @@
         _MoreVc = (MorePopOverViewController *)[CommonUtil
                                                 instantiateViewControllerWithIdentifier:@"MorePopOverViewController"
                                                 storyboardName:@"Common"];
-        _MoreVc.moreDelegate = self;
+        _MoreVc.delegate = self;
 
         _poc = [[WYPopoverController alloc] initWithContentViewController:_MoreVc];
         
@@ -198,6 +198,23 @@
     }];
 }
 
+
+- (void)sendDataToSocket:(NSDictionary *)data
+{
+    [[SocketServiceHandler sharedManager] initDelegate:self];
+    [[SocketServiceHandler sharedManager] sendData:data];
+}
+
+- (BOOL)isSocketConnected
+{
+    return [[SocketServiceHandler sharedManager] isSocketConnected];
+}
+
+- (SRReadyState)getSocketStatus
+{
+    return [[SocketServiceHandler sharedManager] getSocketStatus];
+}
+
 #pragma mark - Main Logic
 
 

+ 3 - 4
OneCable/Classes/ViewControllers/MainScreens/IntroViewController.m

@@ -104,12 +104,11 @@
     //parameters
     NSDictionary *parameter = @{@"os_type": MOBILE_DEVICE_TYPE,
                                 @"store_code": APPSTORE_TYPE,
-                                @"app_version": [CommonUtil applicationShortVersion],
-                                @"service_id": MOBILE_SERVICE_ID};
+                                @"app_version": [CommonUtil applicationShortVersion]};
     
-    NSString *path = [NSString stringWithFormat:API_GET_APP_VERSION];
+    NSString *path = [NSString stringWithFormat:API_POST_APP_VERSION];
     
-    [[RequestHandler handler] sendAsyncGetRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
+    [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
         if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
             return;
         }

+ 25 - 1
OneCable/Classes/ViewControllers/MainScreens/LoginViewController.m

@@ -119,7 +119,7 @@
                             @"device_token": [JDFacade facade].APNSToken ? [JDFacade facade].APNSToken : ksEmptyString,
                             @"message_type": @"auth"};
     
-    [[SocketServiceHandler sharedManager] sendData:param];
+    [self sendDataToSocket:param];
     
 //    [[RequestHandler handler] sendAsyncPostRequestAPIPath:API_POST_SIGN_IN parameters:param modelClass:[LoginModel class] completion:^(id responseObject) {
 //        if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
@@ -386,6 +386,30 @@
     return YES;
 }
 
+#pragma mark - SocketService
+- (void) socketDidReceiveMessage:(id)message
+{
+//    NSLog(@"이쪽으로 들어옴?!!!");
+    LoginModel *loginInfo = (LoginModel *)message;
+    NSLog(@"Socket Info :%@", loginInfo);
+//    SWITCH(info.messageType)
+//    {
+//        CASE (@"auth")
+//        {
+//            // TODO : 로그인 처리
+//            LoginModel *loginInfo = (LoginModel *)message;
+//            if (loginInfo) {//API 성공 ,함
+//                [self actionForLoginSucceed:loginInfo];
+//                
+//            }
+//            break;
+//        }
+//        DEFAULT
+//        {
+//            break;
+//        }
+//    }
+}
 
 #pragma mark - MemoryWarning
 - (void)didReceiveMemoryWarning

+ 2 - 2
OneCable/Classes/ViewControllers/ThingsScreens/ThingsViewController.m

@@ -343,7 +343,7 @@
         }
         [_collectionView reloadData];
                                                
-        [self requestPollingDevicesStatusInBackground];
+//        [self requestPollingDevicesStatusInBackground];
                                                
         //refresh controller
         if (self.refreshController && self.refreshController.refreshState == JYRefreshStateLoading) {
@@ -371,7 +371,7 @@
 - (void)updateTitle {
     
     _lblTitle.text = [NSString stringWithFormat:@"장치 전체 %zd", _deviceList.count];
-    
+    NSLog(@"HomeHubID : %@", [JDFacade facade].loginUser.homehubDeviceId);
     if (![JDFacade facade].loginUser.hasHomeHub) {//홈허브 아이디가 없는 경우,
         
         [_mainView bringSubviewToFront:_addHubContainerView];