android和iOS中打包html5
2016-06-16 21:14
417 查看
目前有一个项目想使用html5实现业务逻辑,同时发布成android和iOS 移动app,这个涉及到如何将这些html、图片、js打包进app并在webview中装载html。下面是具体细节:
一、android打包html5
将html相关的代码拷贝到assets目录下,如下图所示:
那么如何使用呢?如下所示即可访问index.html,使用WebView打开即可。
private String
url = "file:///android_asset/www/index.html";
二、iOS打包html5
将html相关的代码拷贝到一个目录(如www),然后将该目录重命名为www.bundle,并拖放到xcode工程中。如下图所示:
如何使用这个呢?如下所示代码可以访问index.html:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
NSString *bundlePath = [[ NSBundle mainBundle ]. resourcePath stringByAppendingPathComponent : @"www.bundle" ];
NSBundle *bundle = [ NSBundle bundleWithPath :bundlePath];
NSString* path = [bundle pathForResource:@"index" ofType:@"html"];
ZZQWebViewController *webView = [[ZZQWebViewController alloc]init];
webView.url = path;
webView.htmlStr = @"";
webView.title = @"";
self.window.rootViewController = webView;
[self.window makeKeyAndVisible];
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
return YES;
}
一、android打包html5
将html相关的代码拷贝到assets目录下,如下图所示:
那么如何使用呢?如下所示即可访问index.html,使用WebView打开即可。
private String
url = "file:///android_asset/www/index.html";
二、iOS打包html5
将html相关的代码拷贝到一个目录(如www),然后将该目录重命名为www.bundle,并拖放到xcode工程中。如下图所示:
如何使用这个呢?如下所示代码可以访问index.html:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
NSString *bundlePath = [[ NSBundle mainBundle ]. resourcePath stringByAppendingPathComponent : @"www.bundle" ];
NSBundle *bundle = [ NSBundle bundleWithPath :bundlePath];
NSString* path = [bundle pathForResource:@"index" ofType:@"html"];
ZZQWebViewController *webView = [[ZZQWebViewController alloc]init];
webView.url = path;
webView.htmlStr = @"";
webView.title = @"";
self.window.rootViewController = webView;
[self.window makeKeyAndVisible];
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
return YES;
}
相关文章推荐
- 判断是否textField保留两位小数(或者多位小数)
- iOS: 删除真机测试的Provisioning Profile后,在Code Singing中出现entitlements.plist文件无效,解决办法如下:
- iOS开发教程之Objc Runtime笔记
- ios宏定义的参数 编译可以通过,但是提示有错误
- iOS自动释放池_原理_如何工作
- iOS动态性(二):运行时runtime初探(强制获取并修改私有变量,强制增加及修改私有方法等)
- 字符串的比较以及排序问题
- iOS常用define宏定义
- 点击cell动态改变cell高度
- 初始化TableViewCell时获取到的宽度错误
- iOS使用Charts框架绘制—饼状图
- 图片拉伸并保护关键部分不变形
- iOS 实现第三方登录(图文)
- ios 生成ipa
- iOS开发之集成ijkplayer视频直播
- iOS开发 渐变navigationController实现
- IOS 二维码扫码
- iOS开发 - 如何使用请求头鉴权
- iOS开发中的手势触发
- IOS 传感器Core Motion相关简述