iOS:HBuilder导出ios项目并打包,本地打包运行

这里只介绍HBuilder导出iOS App 项目的简单过程

首先打开HBuilder 点击菜单中的发行-生成本地打包app资源

然后,新建一个Xcode工程,新建一个bundle文件,将导出来的App资源放到bundle文件内,具体方法是打开包内容,右键显示包内容,将App资源拖到bundle里面。

然后在Xcode工程里写一个View来启动显示H5的内容。

//
//  ViewController.m
//  tour
//
//  Created by apple on 17/8/22.
//  Copyright © 2017年 zhichaoniao. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (nonatomic, strong, readwrite) UIWebView *webView;
@end

@implementation ViewController
- (UIWebView *)webView {
    if (!_webView) {
        _webView = [[UIWebView alloc]initWithFrame:self.view.bounds];
        _webView.mediaPlaybackRequiresUserAction = NO;
        _webView.scalesPageToFit = YES;
        _webView.scrollView.scrollEnabled = NO;
    }
    return _webView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.webView];
    // Do any additional setup after loading the view, typically from a nib.
    NSString * bundlePath = [[ NSBundle mainBundle] pathForResource:@"360" ofType :@"bundle"];
    NSString *filePath = [bundlePath stringByAppendingPathComponent :@"index.html"];
    NSString *htmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
    [self.webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:filePath]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

上面的代码里pathForResource是bundle的名字,后面的ofType是bundle的拓展名,stringByAppendingPathComponent是H5的启动页面。

You May Also Like

About the Author: 大腿Plus

发表评论