rename dir
This commit is contained in:
17
doric-iOS/Example/Example/AppDelegate.h
Normal file
17
doric-iOS/Example/Example/AppDelegate.h
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// AppDelegate.h
|
||||
// Example
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/7/25.
|
||||
// Copyright © 2019 pengfei.zhou. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface AppDelegate : UIResponder <UIApplicationDelegate>
|
||||
|
||||
@property (strong, nonatomic) UIWindow *window;
|
||||
|
||||
|
||||
@end
|
||||
|
61
doric-iOS/Example/Example/AppDelegate.m
Normal file
61
doric-iOS/Example/Example/AppDelegate.m
Normal file
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// AppDelegate.m
|
||||
// Example
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/7/25.
|
||||
// Copyright © 2019 pengfei.zhou. All rights reserved.
|
||||
//
|
||||
|
||||
#import "AppDelegate.h"
|
||||
#import "ViewController.h"
|
||||
|
||||
@interface AppDelegate ()
|
||||
@property(nonatomic, strong) UIViewController *rootVC;
|
||||
@property(nonatomic, strong) UINavigationController *navigationController;
|
||||
@end
|
||||
|
||||
@implementation AppDelegate
|
||||
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||
// Override point for customization after application launch.
|
||||
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
||||
self.rootVC = [[ViewController alloc] init];
|
||||
|
||||
self.window.rootViewController = self.rootVC;
|
||||
self.navigationController = [[UINavigationController
|
||||
alloc] initWithRootViewController:self.rootVC];
|
||||
[self.window addSubview:self.navigationController.view];
|
||||
[self.window makeKeyAndVisible];
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
- (void)applicationWillResignActive:(UIApplication *)application {
|
||||
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
|
||||
}
|
||||
|
||||
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
||||
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
||||
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
|
||||
}
|
||||
|
||||
|
||||
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
||||
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
|
||||
}
|
||||
|
||||
|
||||
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
||||
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||
}
|
||||
|
||||
|
||||
- (void)applicationWillTerminate:(UIApplication *)application {
|
||||
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
|
||||
}
|
||||
|
||||
|
||||
@end
|
@@ -0,0 +1,98 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "20x20",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "20x20",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "29x29",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "29x29",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "40x40",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "40x40",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "60x60",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "60x60",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
"idiom" : "ipad",
|
||||
"size" : "20x20",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "ipad",
|
||||
"size" : "20x20",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "ipad",
|
||||
"size" : "29x29",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "ipad",
|
||||
"size" : "29x29",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "ipad",
|
||||
"size" : "40x40",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "ipad",
|
||||
"size" : "40x40",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "ipad",
|
||||
"size" : "76x76",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "ipad",
|
||||
"size" : "76x76",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "ipad",
|
||||
"size" : "83.5x83.5",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "ios-marketing",
|
||||
"size" : "1024x1024",
|
||||
"scale" : "1x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
6
doric-iOS/Example/Example/Assets.xcassets/Contents.json
Normal file
6
doric-iOS/Example/Example/Assets.xcassets/Contents.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
25
doric-iOS/Example/Example/Base.lproj/LaunchScreen.storyboard
Normal file
25
doric-iOS/Example/Example/Base.lproj/LaunchScreen.storyboard
Normal file
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
|
||||
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--View Controller-->
|
||||
<scene sceneID="EHf-IW-A2E">
|
||||
<objects>
|
||||
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
|
||||
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
|
||||
</view>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="53" y="375"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
</document>
|
24
doric-iOS/Example/Example/Base.lproj/Main.storyboard
Normal file
24
doric-iOS/Example/Example/Base.lproj/Main.storyboard
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
|
||||
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--View Controller-->
|
||||
<scene sceneID="tne-QT-ifu">
|
||||
<objects>
|
||||
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="" sceneMemberID="viewController">
|
||||
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
|
||||
</view>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
</scene>
|
||||
</scenes>
|
||||
</document>
|
10
doric-iOS/Example/Example/DemoLibrary.h
Normal file
10
doric-iOS/Example/Example/DemoLibrary.h
Normal file
@@ -0,0 +1,10 @@
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/12/11.
|
||||
// Copyright (c) 2019 pengfei.zhou. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <DoricCore/Doric.h>
|
||||
|
||||
@interface DemoLibrary : DoricLibrary
|
||||
@end
|
24
doric-iOS/Example/Example/DemoLibrary.m
Normal file
24
doric-iOS/Example/Example/DemoLibrary.m
Normal file
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/12/11.
|
||||
// Copyright (c) 2019 pengfei.zhou. All rights reserved.
|
||||
//
|
||||
|
||||
#import "DemoLibrary.h"
|
||||
|
||||
@interface DoricDemoPlugin : DoricNativePlugin
|
||||
|
||||
@end
|
||||
|
||||
@implementation DoricDemoPlugin
|
||||
- (void)test {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
ShowToast(@"Test called", CENTER);
|
||||
});
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation DemoLibrary
|
||||
- (void)load:(DoricRegistry *)registry {
|
||||
[registry registerNativePlugin:[DoricDemoPlugin class] withName:@"demo"];
|
||||
}
|
||||
@end
|
12
doric-iOS/Example/Example/DemoVC.h
Normal file
12
doric-iOS/Example/Example/DemoVC.h
Normal file
@@ -0,0 +1,12 @@
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/11/19.
|
||||
// Copyright (c) 2019 pengfei.zhou. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
|
||||
@interface DemoVC : UIViewController
|
||||
- (instancetype)initWithPath:(NSString *)filePath;
|
||||
@end
|
39
doric-iOS/Example/Example/DemoVC.m
Normal file
39
doric-iOS/Example/Example/DemoVC.m
Normal file
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/11/19.
|
||||
// Copyright (c) 2019 pengfei.zhou. All rights reserved.
|
||||
//
|
||||
|
||||
#import "DemoVC.h"
|
||||
#import <DoricCore/Doric.h>
|
||||
|
||||
@interface DemoVC ()
|
||||
@property(nonatomic, copy) NSString *filePath;
|
||||
@end
|
||||
|
||||
@implementation DemoVC
|
||||
- (instancetype)initWithPath:(NSString *)filePath {
|
||||
if (self = [self init]) {
|
||||
_filePath = filePath;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)viewDidLoad {
|
||||
self.title = self.filePath;
|
||||
self.view.backgroundColor = [UIColor whiteColor];
|
||||
NSString *path = [[NSBundle mainBundle] bundlePath];
|
||||
NSString *demoPath = [path stringByAppendingPathComponent:@"demo"];
|
||||
NSString *fullPath = [demoPath stringByAppendingPathComponent:self.filePath];
|
||||
NSString *jsContent = [NSString stringWithContentsOfFile:fullPath encoding:NSUTF8StringEncoding error:nil];
|
||||
DoricPanel *panel = [DoricPanel new];
|
||||
[panel.view also:^(UIView *it) {
|
||||
it.width = self.view.width;
|
||||
it.height = self.view.height - 88;
|
||||
it.top = 88;
|
||||
[self.view addSubview:it];
|
||||
}];
|
||||
[self addChildViewController:panel];
|
||||
[panel config:jsContent alias:self.filePath extra:nil];
|
||||
}
|
||||
|
||||
@end
|
54
doric-iOS/Example/Example/Info.plist
Normal file
54
doric-iOS/Example/Example/Info.plist
Normal file
@@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>NSCameraUsageDescription</key>
|
||||
<string>Scan QR Code</string>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
<key>UIMainStoryboardFile</key>
|
||||
<string>Main</string>
|
||||
<key>UIRequiredDeviceCapabilities</key>
|
||||
<array>
|
||||
<string>armv7</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>NSAppTransportSecurity</key>
|
||||
<dict>
|
||||
<key>NSAllowsArbitraryLoads</key>
|
||||
<true/>
|
||||
</dict>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
<string></string>
|
||||
<key>UISupportedInterfaceOrientations~ipad</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationPortraitUpsideDown</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
10
doric-iOS/Example/Example/QRScanViewController.h
Normal file
10
doric-iOS/Example/Example/QRScanViewController.h
Normal file
@@ -0,0 +1,10 @@
|
||||
//
|
||||
// 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
|
93
doric-iOS/Example/Example/QRScanViewController.m
Normal file
93
doric-iOS/Example/Example/QRScanViewController.m
Normal file
@@ -0,0 +1,93 @@
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/11/21.
|
||||
// Copyright (c) 2019 pengfei.zhou. All rights reserved.
|
||||
//
|
||||
|
||||
#import "QRScanViewController.h"
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
#import <DoricCore/Doric.h>
|
||||
|
||||
@interface QRScanViewController () <AVCaptureMetadataOutputObjectsDelegate>
|
||||
@property(strong, nonatomic) AVCaptureDevice *device;
|
||||
@property(strong, nonatomic) AVCaptureDeviceInput *input;
|
||||
@property(strong, nonatomic) AVCaptureMetadataOutput *output;
|
||||
@property(strong, nonatomic) AVCaptureSession *session;
|
||||
@property(strong, nonatomic) AVCaptureVideoPreviewLayer *previewLayer;
|
||||
@property(strong, nonatomic) UIPinchGestureRecognizer *pinchGes;
|
||||
@property(assign, nonatomic) CGFloat scanRegion_W;
|
||||
@property(assign, nonatomic) CGFloat initScale;
|
||||
@end
|
||||
|
||||
@implementation QRScanViewController
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
self.title = @"扫一扫";
|
||||
[self configBasicDevice];
|
||||
[self configPinchGes];
|
||||
[self.session startRunning];
|
||||
}
|
||||
|
||||
- (void)configBasicDevice {
|
||||
self.device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
|
||||
self.input = [[AVCaptureDeviceInput alloc] initWithDevice:self.device error:nil];
|
||||
self.output = [[AVCaptureMetadataOutput alloc] init];
|
||||
[self.output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
|
||||
self.session = [[AVCaptureSession alloc] init];
|
||||
[self.session setSessionPreset:AVCaptureSessionPresetHigh];
|
||||
if ([self.session canAddInput:self.input]) {
|
||||
[self.session addInput:self.input];
|
||||
}
|
||||
if ([self.session canAddOutput:self.output]) {
|
||||
[self.session addOutput:self.output];
|
||||
}
|
||||
[self.output setMetadataObjectTypes:@[AVMetadataObjectTypeQRCode]];
|
||||
[self.output setRectOfInterest:CGRectMake(0, 0, 1, 1)];
|
||||
self.previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.session];
|
||||
self.previewLayer.frame = CGRectMake(0, 0, self.view.width, self.view.height);
|
||||
self.previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
|
||||
[self.view.layer addSublayer:self.previewLayer];
|
||||
}
|
||||
|
||||
- (void)configPinchGes {
|
||||
self.pinchGes = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchDetected:)];
|
||||
[self.view addGestureRecognizer:self.pinchGes];
|
||||
}
|
||||
|
||||
- (void)pinchDetected:(UIPinchGestureRecognizer *)recogniser {
|
||||
if (!_device) {
|
||||
return;
|
||||
}
|
||||
if (recogniser.state == UIGestureRecognizerStateBegan) {
|
||||
_initScale = _device.videoZoomFactor;
|
||||
}
|
||||
NSError *error = nil;
|
||||
[_device lockForConfiguration:&error];
|
||||
if (!error) {
|
||||
CGFloat zoomFactor;
|
||||
CGFloat scale = recogniser.scale;
|
||||
if (scale < 1.0f) {
|
||||
zoomFactor = self.initScale - pow(self.device.activeFormat.videoMaxZoomFactor, 1.0f - recogniser.scale);
|
||||
} else {
|
||||
zoomFactor = self.initScale + pow(self.device.activeFormat.videoMaxZoomFactor, (recogniser.scale - 1.0f) / 2.0f);
|
||||
}
|
||||
zoomFactor = MIN(15.0f, zoomFactor);
|
||||
zoomFactor = MAX(1.0f, zoomFactor);
|
||||
_device.videoZoomFactor = zoomFactor;
|
||||
[_device unlockForConfiguration];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - AVCaptureMetadataOutputObjectsDelegate
|
||||
|
||||
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection {
|
||||
[self.session stopRunning];
|
||||
if ([metadataObjects count] >= 1) {
|
||||
AVMetadataMachineReadableCodeObject *qrObject = [metadataObjects lastObject];
|
||||
NSString *result = qrObject.stringValue;
|
||||
NSLog(@"Scan result is %@", result);
|
||||
[[DoricDriver instance] connectDevKit:[NSString stringWithFormat:@"ws://%@:7777", result]];
|
||||
ShowToast([NSString stringWithFormat:@"Connected to %@", result], BOTTOM);
|
||||
[self.navigationController popViewControllerAnimated:NO];
|
||||
}
|
||||
}
|
||||
@end
|
15
doric-iOS/Example/Example/ViewController.h
Normal file
15
doric-iOS/Example/Example/ViewController.h
Normal file
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// ViewController.h
|
||||
// Example
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/7/25.
|
||||
// Copyright © 2019 pengfei.zhou. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface ViewController : UIViewController
|
||||
|
||||
|
||||
@end
|
||||
|
92
doric-iOS/Example/Example/ViewController.m
Normal file
92
doric-iOS/Example/Example/ViewController.m
Normal file
@@ -0,0 +1,92 @@
|
||||
//
|
||||
// ViewController.m
|
||||
// Example
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/7/25.
|
||||
// Copyright © 2019 pengfei.zhou. All rights reserved.
|
||||
//
|
||||
|
||||
#import "ViewController.h"
|
||||
#import <DoricCore/Doric.h>
|
||||
#import "DemoVC.h"
|
||||
#import "QRScanViewController.h"
|
||||
#import "DemoLibrary.h"
|
||||
|
||||
@interface ViewController () <UITableViewDelegate, UITableViewDataSource>
|
||||
@property(nonatomic, copy) NSArray <NSString *> *demoFilePaths;
|
||||
@end
|
||||
|
||||
@implementation ViewController
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
self.title = @"Doric Demo";
|
||||
NSString *path = [[NSBundle mainBundle] bundlePath];
|
||||
NSString *demoPath = [path stringByAppendingPathComponent:@"demo"];
|
||||
NSFileManager *mgr = [NSFileManager defaultManager];
|
||||
self.demoFilePaths = [[mgr subpathsAtPath:demoPath] filter:^BOOL(NSString *obj) {
|
||||
return ![obj containsString:@".map"];
|
||||
}];
|
||||
NSMutableArray <NSString *> *tmp = [self.demoFilePaths mutableCopy];
|
||||
NSStringCompareOptions comparisonOptions = NSCaseInsensitiveSearch | NSNumericSearch | NSWidthInsensitiveSearch | NSForcedOrderingSearch;
|
||||
[tmp sortUsingComparator:^NSComparisonResult(NSString *obj1, NSString *obj2) {
|
||||
NSRange range = NSMakeRange(0, obj1.length);
|
||||
return [obj1 compare:obj2 options:comparisonOptions range:range];
|
||||
}];
|
||||
[tmp insertObject:@"Dev Kit" atIndex:0];
|
||||
self.demoFilePaths = tmp;
|
||||
[self.view addSubview:[[UITableView new] also:^(UITableView *it) {
|
||||
it.width = self.view.width;
|
||||
it.height = self.view.height;
|
||||
it.left = it.top = 0;
|
||||
it.dataSource = self;
|
||||
it.delegate = self;
|
||||
}]];
|
||||
[DoricRegistry register:[DemoLibrary new]];
|
||||
}
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
||||
return self.demoFilePaths.count;
|
||||
}
|
||||
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
NSString *path = self.demoFilePaths[(NSUInteger) indexPath.row];
|
||||
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
|
||||
if (cell == nil) {
|
||||
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellID"];
|
||||
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
||||
}
|
||||
cell.textLabel.text = path;
|
||||
return cell;
|
||||
}
|
||||
|
||||
- (BOOL)isSimulator {
|
||||
return TARGET_OS_SIMULATOR == 1;
|
||||
}
|
||||
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
if (indexPath.row == 0) {
|
||||
if (self.isSimulator) {
|
||||
NSString *result = @"127.0.0.1";
|
||||
[[DoricDriver instance] connectDevKit:[NSString stringWithFormat:@"ws://%@:7777", result]];
|
||||
ShowToast([NSString stringWithFormat:@"Connected to %@", result], BOTTOM);
|
||||
} else {
|
||||
[self.navigationController pushViewController:[QRScanViewController new] animated:NO];
|
||||
}
|
||||
return;
|
||||
}
|
||||
NSString *file = self.demoFilePaths[(NSUInteger) indexPath.row];
|
||||
if ([file containsString:@"NavigatorDemo"]) {
|
||||
DoricViewController *doricViewController = [[DoricViewController alloc]
|
||||
initWithScheme:[NSString stringWithFormat:@"assets://demo/%@", file]
|
||||
alias:self.demoFilePaths[(NSUInteger) indexPath.row]
|
||||
extra:nil
|
||||
];
|
||||
[self.navigationController pushViewController:doricViewController animated:NO];
|
||||
} else {
|
||||
DemoVC *demoVC = [[DemoVC alloc] initWithPath:file];
|
||||
[self.navigationController pushViewController:demoVC animated:NO];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
1
doric-iOS/Example/Example/demo/.gitignore
vendored
Normal file
1
doric-iOS/Example/Example/demo/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.js
|
16
doric-iOS/Example/Example/main.m
Normal file
16
doric-iOS/Example/Example/main.m
Normal file
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// main.m
|
||||
// Example
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/7/25.
|
||||
// Copyright © 2019 pengfei.zhou. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "AppDelegate.h"
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
@autoreleasepool {
|
||||
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user