您的位置:首页 > 移动开发 > IOS开发

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: