iOS:optimize API
This commit is contained in:
parent
7f1b1256ce
commit
a2f2e74380
@ -25,11 +25,16 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
@interface DoricDev : NSObject
|
@interface DoricDev : NSObject
|
||||||
+ (instancetype)instance;
|
+ (instancetype)instance;
|
||||||
|
|
||||||
|
- (void)openDevMode;
|
||||||
|
|
||||||
|
- (void)closeDevMode;
|
||||||
|
|
||||||
|
- (BOOL)isInDevMode;
|
||||||
|
|
||||||
- (void)connectDevKit:(NSString *)url;
|
- (void)connectDevKit:(NSString *)url;
|
||||||
|
|
||||||
- (void)sendDevCommand:(NSString *)command;
|
- (void)sendDevCommand:(NSString *)command;
|
||||||
|
|
||||||
- (void)disconnectDevKit;
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
NS_ASSUME_NONNULL_END
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#import "DoricDev.h"
|
#import "DoricDev.h"
|
||||||
#import "DoricWSClient.h"
|
#import "DoricWSClient.h"
|
||||||
#import "DoricDebugDriver.h"
|
#import "DoricDebugDriver.h"
|
||||||
|
#import "DoricDevViewController.h"
|
||||||
|
|
||||||
@interface DoricDev ()
|
@interface DoricDev ()
|
||||||
@property(nonatomic, strong) DoricWSClient *wsclient;
|
@property(nonatomic, strong) DoricWSClient *wsclient;
|
||||||
@ -58,6 +59,30 @@ + (instancetype)instance {
|
|||||||
return _instance;
|
return _instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)openDevMode {
|
||||||
|
DoricDevViewController *devViewController = [DoricDevViewController new];
|
||||||
|
|
||||||
|
UIViewController *viewController = [UIApplication sharedApplication].delegate.window.rootViewController;
|
||||||
|
UINavigationController *navigationController;
|
||||||
|
if ([viewController isKindOfClass:[UINavigationController class]]) {
|
||||||
|
navigationController = (UINavigationController *) viewController;
|
||||||
|
} else {
|
||||||
|
navigationController = viewController.navigationController;
|
||||||
|
}
|
||||||
|
[navigationController pushViewController:devViewController animated:NO];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)closeDevMode {
|
||||||
|
if (self.wsclient) {
|
||||||
|
[self.wsclient close];
|
||||||
|
self.wsclient = nil;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)isInDevMode {
|
||||||
|
return self.wsclient != nil;
|
||||||
|
}
|
||||||
|
|
||||||
- (void)connectDevKit:(NSString *)url {
|
- (void)connectDevKit:(NSString *)url {
|
||||||
if (self.wsclient) {
|
if (self.wsclient) {
|
||||||
[self.wsclient close];
|
[self.wsclient close];
|
||||||
@ -69,13 +94,6 @@ - (void)sendDevCommand:(NSString *)command {
|
|||||||
[self.wsclient send:command];
|
[self.wsclient send:command];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)disconnectDevKit {
|
|
||||||
if (self.wsclient) {
|
|
||||||
[self.wsclient close];
|
|
||||||
self.wsclient = nil;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)onOpenEvent {
|
- (void)onOpenEvent {
|
||||||
ShowToast(@"dev kit connected", BOTTOM);
|
ShowToast(@"dev kit connected", BOTTOM);
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,9 @@ - (void)viewDidLoad {
|
|||||||
it.dataSource = self;
|
it.dataSource = self;
|
||||||
it.delegate = self;
|
it.delegate = self;
|
||||||
}]];
|
}]];
|
||||||
|
if ([[DoricDev instance] isInDevMode]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (self.isSimulator) {
|
if (self.isSimulator) {
|
||||||
NSString *result = @"127.0.0.1";
|
NSString *result = @"127.0.0.1";
|
||||||
[DoricJSRemoteExecutor configIp:result];
|
[DoricJSRemoteExecutor configIp:result];
|
||||||
|
@ -62,14 +62,14 @@ - (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message {
|
|||||||
if ([cmd compare:@"SWITCH_TO_DEBUG"] == NSOrderedSame) {
|
if ([cmd compare:@"SWITCH_TO_DEBUG"] == NSOrderedSame) {
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:@"EnterDebugEvent" object:nil];
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"EnterDebugEvent" object:nil];
|
||||||
} else if ([cmd compare:@"RELOAD"] == NSOrderedSame) {
|
} else if ([cmd compare:@"RELOAD"] == NSOrderedSame) {
|
||||||
// NSString *source = [[dic valueForKey:@"source"] mutableCopy];
|
NSString *source = [[dic valueForKey:@"source"] mutableCopy];
|
||||||
// NSString *script = [dic valueForKey:@"script"];
|
NSString *script = [dic valueForKey:@"script"];
|
||||||
// for (NSValue *value in [[DoricContextManager instance] aliveContexts]) {
|
for (NSValue *value in [[DoricContextManager instance] aliveContexts]) {
|
||||||
// DoricContext *context = value.nonretainedObjectValue;
|
DoricContext *context = value.nonretainedObjectValue;
|
||||||
// if ([source containsString:context.source]) {
|
if ([source containsString:context.source]) {
|
||||||
// [context reload:script];
|
[context reload:script];
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,13 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
//
|
||||||
|
// Doric.m
|
||||||
|
// Doric
|
||||||
|
//
|
||||||
|
// Created by pengfei.zhou on 2020/2/28.
|
||||||
|
//
|
||||||
|
|
||||||
#import "DoricContext.h"
|
#import "DoricContext.h"
|
||||||
#import "DoricLayouts.h"
|
#import "DoricLayouts.h"
|
||||||
#import "DoricExtensions.h"
|
#import "DoricExtensions.h"
|
||||||
@ -29,3 +36,17 @@
|
|||||||
#import "DoricLibrary.h"
|
#import "DoricLibrary.h"
|
||||||
#import "DoricNativePlugin.h"
|
#import "DoricNativePlugin.h"
|
||||||
#import "DoricMonitorProtocol.h"
|
#import "DoricMonitorProtocol.h"
|
||||||
|
|
||||||
|
@interface Doric : NSObject
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register DoricLibrary For Extended ViewNode And Native Plugins
|
||||||
|
* */
|
||||||
|
+ (void)registerLibrary:(DoricLibrary *)library;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add DoricJSLoader For Loading JS Bundles
|
||||||
|
* */
|
||||||
|
+ (void)addJSLoader:(id <DoricLoaderProtocol>)loader;
|
||||||
|
|
||||||
|
@end
|
33
doric-iOS/Pod/Classes/Doric.m
Normal file
33
doric-iOS/Pod/Classes/Doric.m
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.
|
||||||
|
*/
|
||||||
|
//
|
||||||
|
// Doric.m
|
||||||
|
// Doric
|
||||||
|
//
|
||||||
|
// Created by pengfei.zhou on 2020/2/28.
|
||||||
|
//
|
||||||
|
#import "Doric.h"
|
||||||
|
|
||||||
|
@implementation Doric
|
||||||
|
|
||||||
|
+ (void)registerLibrary:(DoricLibrary *)library {
|
||||||
|
[DoricRegistry register:library];
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (void)addJSLoader:(id <DoricLoaderProtocol>)loader {
|
||||||
|
[[DoricJSLoaderManager instance] addJSLoader:loader];
|
||||||
|
}
|
||||||
|
@end
|
Reference in New Issue
Block a user