code refactor
This commit is contained in:
		
							
								
								
									
										33
									
								
								doric-iOS/Devkit/Classes/DoricDev.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								doric-iOS/Devkit/Classes/DoricDev.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,33 @@ | ||||
| /* | ||||
|  * Copyright [2019] [Doric.Pub] | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  * http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
| // | ||||
| //  DoricDev.h | ||||
| //  Doric | ||||
| // | ||||
| //  Created by jingpeng.wang on 2020/2/25. | ||||
| // | ||||
|  | ||||
| NS_ASSUME_NONNULL_BEGIN | ||||
|  | ||||
| @interface DoricDev : NSObject | ||||
| + (instancetype)instance; | ||||
|  | ||||
| - (void)connectDevKit:(NSString *)url; | ||||
|  | ||||
| - (void)disconnectDevKit; | ||||
| @end | ||||
|  | ||||
| NS_ASSUME_NONNULL_END | ||||
							
								
								
									
										61
									
								
								doric-iOS/Devkit/Classes/DoricDev.m
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								doric-iOS/Devkit/Classes/DoricDev.m
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,61 @@ | ||||
| /* | ||||
|  * Copyright [2019] [Doric.Pub] | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  * http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
| // | ||||
| //  DoricDev.m | ||||
| //  Doric | ||||
| // | ||||
| //  Created by jingpeng.wang on 2020/2/25. | ||||
| // | ||||
| 
 | ||||
| #import "DoricDev.h" | ||||
| #import "DoricWSClient.h" | ||||
| 
 | ||||
| @interface DoricDev () | ||||
| @property(nonatomic, strong) DoricWSClient *wsclient; | ||||
| @end | ||||
| 
 | ||||
| @implementation DoricDev | ||||
| 
 | ||||
| - (instancetype)init { | ||||
|     if (self = [super init]) { | ||||
|     } | ||||
|     return self; | ||||
| } | ||||
| 
 | ||||
| + (instancetype)instance { | ||||
|     static DoricDev *_instance; | ||||
|     static dispatch_once_t onceToken; | ||||
|     dispatch_once(&onceToken, ^{ | ||||
|         _instance = [[DoricDev alloc] init]; | ||||
|     }); | ||||
|     return _instance; | ||||
| } | ||||
| 
 | ||||
| - (void)connectDevKit:(NSString *)url { | ||||
|     if (self.wsclient) { | ||||
|         [self.wsclient close]; | ||||
|     } | ||||
|     self.wsclient = [[DoricWSClient alloc] initWithUrl:url]; | ||||
| } | ||||
| 
 | ||||
| - (void)disconnectDevKit { | ||||
|     if (self.wsclient) { | ||||
|         [self.wsclient close]; | ||||
|         self.wsclient = nil; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| @end | ||||
							
								
								
									
										28
									
								
								doric-iOS/Devkit/Classes/QRScanViewController.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								doric-iOS/Devkit/Classes/QRScanViewController.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,28 @@ | ||||
| /* | ||||
|  * Copyright [2019] [Doric.Pub] | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  * http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
| // | ||||
| //  QRScanViewController.h | ||||
| //  Doric | ||||
| // | ||||
| //  Created by jingpeng.wang on 2020/2/25. | ||||
| // | ||||
|  | ||||
|  | ||||
| #import <Foundation/Foundation.h> | ||||
| #import <UIKit/UIKit.h> | ||||
|  | ||||
| @interface QRScanViewController : UIViewController | ||||
| @end | ||||
| @@ -1,11 +1,29 @@ | ||||
| /* | ||||
|  * Copyright [2019] [Doric.Pub] | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  * http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
| // | ||||
| // Created by pengfei.zhou on 2019/11/21. | ||||
| // Copyright (c) 2019 pengfei.zhou. All rights reserved. | ||||
| //  QRScanViewController.m | ||||
| //  Doric | ||||
| // | ||||
| //  Created by jingpeng.wang on 2020/2/25. | ||||
| // | ||||
| 
 | ||||
| #import "QRScanViewController.h" | ||||
| #import <AVFoundation/AVFoundation.h> | ||||
| #import <DoricCore/Doric.h> | ||||
| #import <DoricDevkit/DoricDev.h> | ||||
| 
 | ||||
| @interface QRScanViewController () <AVCaptureMetadataOutputObjectsDelegate> | ||||
| @property(strong, nonatomic) AVCaptureDevice *device; | ||||
| @@ -85,7 +103,7 @@ - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects: | ||||
|         AVMetadataMachineReadableCodeObject *qrObject = [metadataObjects lastObject]; | ||||
|         NSString *result = qrObject.stringValue; | ||||
|         NSLog(@"Scan result is %@", result); | ||||
|         [[DoricDriver instance] connectDevKit:[NSString stringWithFormat:@"ws://%@:7777", result]]; | ||||
|         [[DoricDev instance] connectDevKit:[NSString stringWithFormat:@"ws://%@:7777", result]]; | ||||
|         ShowToast([NSString stringWithFormat:@"Connected to %@", result], BOTTOM); | ||||
|         [self.navigationController popViewControllerAnimated:NO]; | ||||
|     } | ||||
| @@ -11,7 +11,6 @@ | ||||
| 		A1E221FB2DCA40D85C4D9520 /* libPods-ExampleTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4F233ACD236542275AED3DE0 /* libPods-ExampleTests.a */; }; | ||||
| 		CC537F4B9F59400BA5B4FF8F /* libPods-Example.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DEE8411A69609CC9C86063CC /* libPods-Example.a */; }; | ||||
| 		D751D4B065D8D4FA6594B5EE /* DemoVC.m in Sources */ = {isa = PBXBuildFile; fileRef = D751D19E97EF4EDD7588FEBE /* DemoVC.m */; }; | ||||
| 		D751D4FCC0A2322211DE3D55 /* QRScanViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D751DA399F1ADB6D34563B5D /* QRScanViewController.m */; }; | ||||
| 		D751DDB012BAF476A252CD93 /* DemoLibrary.m in Sources */ = {isa = PBXBuildFile; fileRef = D751D2175D09F2C10691FB81 /* DemoLibrary.m */; }; | ||||
| 		E2334AF022E9D2060098A085 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = E2334AEF22E9D2060098A085 /* AppDelegate.m */; }; | ||||
| 		E2334AF322E9D2060098A085 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E2334AF222E9D2060098A085 /* ViewController.m */; }; | ||||
| @@ -51,10 +50,8 @@ | ||||
| 		8BCADA7B23CD5B64005EEF96 /* NavigationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NavigationController.m; sourceTree = "<group>"; }; | ||||
| 		B93423722F2E06DC238CDD18 /* Pods-ExampleUITests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ExampleUITests.release.xcconfig"; path = "Pods/Target Support Files/Pods-ExampleUITests/Pods-ExampleUITests.release.xcconfig"; sourceTree = "<group>"; }; | ||||
| 		B93D4DB00FD244178B7CE7C4 /* Pods-ExampleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ExampleTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-ExampleTests/Pods-ExampleTests.release.xcconfig"; sourceTree = "<group>"; }; | ||||
| 		D751D18AD6496F4A9BE1AB45 /* QRScanViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QRScanViewController.h; sourceTree = "<group>"; }; | ||||
| 		D751D19E97EF4EDD7588FEBE /* DemoVC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoVC.m; sourceTree = "<group>"; }; | ||||
| 		D751D2175D09F2C10691FB81 /* DemoLibrary.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoLibrary.m; sourceTree = "<group>"; }; | ||||
| 		D751DA399F1ADB6D34563B5D /* QRScanViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QRScanViewController.m; sourceTree = "<group>"; }; | ||||
| 		D751DB0CB3009E12990F661E /* DemoLibrary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoLibrary.h; sourceTree = "<group>"; }; | ||||
| 		D751DDEC114E037231257E64 /* DemoVC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoVC.h; sourceTree = "<group>"; }; | ||||
| 		D91241144B5A3356A3C60644 /* Pods-ExampleTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ExampleTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ExampleTests/Pods-ExampleTests.debug.xcconfig"; sourceTree = "<group>"; }; | ||||
| @@ -169,8 +166,6 @@ | ||||
| 				E2334AFD22E9D2070098A085 /* main.m */, | ||||
| 				D751D19E97EF4EDD7588FEBE /* DemoVC.m */, | ||||
| 				D751DDEC114E037231257E64 /* DemoVC.h */, | ||||
| 				D751DA399F1ADB6D34563B5D /* QRScanViewController.m */, | ||||
| 				D751D18AD6496F4A9BE1AB45 /* QRScanViewController.h */, | ||||
| 				D751D2175D09F2C10691FB81 /* DemoLibrary.m */, | ||||
| 				D751DB0CB3009E12990F661E /* DemoLibrary.h */, | ||||
| 			); | ||||
| @@ -439,7 +434,6 @@ | ||||
| 				E2334AFE22E9D2070098A085 /* main.m in Sources */, | ||||
| 				E2334AF022E9D2060098A085 /* AppDelegate.m in Sources */, | ||||
| 				D751D4B065D8D4FA6594B5EE /* DemoVC.m in Sources */, | ||||
| 				D751D4FCC0A2322211DE3D55 /* QRScanViewController.m in Sources */, | ||||
| 				D751DDB012BAF476A252CD93 /* DemoLibrary.m in Sources */, | ||||
| 				8BCADA7C23CD5B65005EEF96 /* NavigationController.m in Sources */, | ||||
| 			); | ||||
|   | ||||
| @@ -1,10 +0,0 @@ | ||||
| // | ||||
| // Created by pengfei.zhou on 2019/11/21. | ||||
| // Copyright (c) 2019 pengfei.zhou. All rights reserved. | ||||
| // | ||||
|  | ||||
| #import <Foundation/Foundation.h> | ||||
| #import <UIKit/UIKit.h> | ||||
|  | ||||
| @interface QRScanViewController : UIViewController | ||||
| @end | ||||
| @@ -7,9 +7,11 @@ | ||||
| // | ||||
| 
 | ||||
| #import <DoricCore/Doric.h> | ||||
| #import <DoricDevkit/QRScanViewController.h> | ||||
| #import <DoricDevkit/DoricDev.h> | ||||
| 
 | ||||
| #import "ViewController.h" | ||||
| #import "QRScanViewController.h" | ||||
| 
 | ||||
| #import "DemoLibrary.h" | ||||
| 
 | ||||
| @interface ViewController () <UITableViewDelegate, UITableViewDataSource> | ||||
| @@ -68,7 +70,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath | ||||
|     if (indexPath.row == 0) { | ||||
|         if (self.isSimulator) { | ||||
|             NSString *result = @"127.0.0.1"; | ||||
|             [[DoricDriver instance] connectDevKit:[NSString stringWithFormat:@"ws://%@:7777", result]]; | ||||
|             [[DoricDev instance] connectDevKit:[NSString stringWithFormat:@"ws://%@:7777", result]]; | ||||
|             ShowToast([NSString stringWithFormat:@"Connected to %@", result], BOTTOM); | ||||
|         } else { | ||||
|             [self.navigationController pushViewController:[QRScanViewController new] animated:NO]; | ||||
|   | ||||
| @@ -49,10 +49,6 @@ NS_ASSUME_NONNULL_BEGIN | ||||
|  | ||||
| - (DoricAsyncResult *)invokeContextEntity:(NSString *)contextId method:(NSString *)method argumentsArray:(NSArray *)args; | ||||
|  | ||||
| - (void)connectDevKit:(NSString *)url; | ||||
|  | ||||
| - (void)disconnectDevKit; | ||||
|  | ||||
| - (void)ensureSyncInMainQueue:(dispatch_block_t)block; | ||||
|  | ||||
| - (NSString *)aliasWithContextId:(NSString *)contextId; | ||||
|   | ||||
| @@ -23,12 +23,10 @@ | ||||
| #import "DoricDriver.h" | ||||
| #import "DoricJSEngine.h" | ||||
| #import "DoricConstant.h" | ||||
| #import "DoricWSClient.h" | ||||
| #import "DoricContextManager.h" | ||||
| 
 | ||||
| @interface DoricDriver () | ||||
| @property(nonatomic, strong) DoricJSEngine *jsExecutor; | ||||
| @property(nonatomic, strong) DoricWSClient *wsclient; | ||||
| @end | ||||
| 
 | ||||
| @implementation DoricDriver | ||||
| @@ -178,20 +176,6 @@ - (DoricAsyncResult *)destroyContext:(NSString *)contextId { | ||||
|     return ret; | ||||
| } | ||||
| 
 | ||||
| - (void)connectDevKit:(NSString *)url { | ||||
|     if (self.wsclient) { | ||||
|         [self.wsclient close]; | ||||
|     } | ||||
|     self.wsclient = [[DoricWSClient alloc] initWithUrl:url]; | ||||
| } | ||||
| 
 | ||||
| - (void)disconnectDevKit { | ||||
|     if (self.wsclient) { | ||||
|         [self.wsclient close]; | ||||
|         self.wsclient = nil; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| - (void)ensureSyncInMainQueue:(dispatch_block_t)block { | ||||
|     if (strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), dispatch_queue_get_label(dispatch_get_main_queue())) == 0) { | ||||
|         block(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user