专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > 移动开发

phonegap运行www包遇到的有关问题

发布时间:2010-05-29 23:58:02 文章来源:www.iduyao.cn 采编人员:星星草
phonegap运行www包遇到的问题

最近公司一直要求学习phonegap打包项目   我也是第一次开始接触   用了几下  感觉还不错吧   主要是HTML5+JS的代码

在此期间  我遇到了很多的问题

问题1、老大给了我个www包叫我用iPhone手机运行一下 看一下效果   老大可能也不大懂iOS(老大是搞安卓的)   说用webView加载  于是我就写了这么些代码

//加载本地的HTML
    webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,self.view.bounds.size.width,self.view.bounds.size.height)];
    NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"login" ofType:@"html"];
    NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
    NSString *path = [[NSBundle mainBundle] bundlePath];
    NSURL *baseURL = [NSURL fileURLWithPath:path];
    
    [webView loadHTMLString:htmlString baseURL:baseURL];
    // 把baseURL知道bundle的Url,就能调用bundle里的其他文件了,图片音乐什么的
    [self.view addSubview:webView];


这样做了一下  界面好像是可以显示出来  可是遇到了许多问题  于是我就另辟蹊径   

在网上找了各种资料   发现  原来用phonegap运行www包得时候  Xcode是不用写一句代码的  其中

config.xml是全局的配置文件  把要显示的界面写在<content src="login/login.html" />  这里面  我这里是登陆界面

<?xml version="1.0" encoding="UTF-8"?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one
 or more contributor license agreements.  See the NOTICE file
 distributed with this work for additional information
 regarding copyright ownership.  The ASF licenses this file
 to you 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.
-->
<widget xmlns     = "http://www.w3.org/ns/widgets"
        id        = "io.cordova.helloCordova"
        version   = "2.0.0">
    <name>Hello Cordova</name>

    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>

    <author href="http://cordova.io" email="dev@cordova.apache.org">
        Apache Cordova Team
    </author>

    <access origin="*"/>

    <!-- <content src="http://mysite.com/myapp.html" /> for external pages -->
    <content src="login/login.html" />

    <!-- Preferences for iOS -->
    <preference name="AllowInlineMediaPlayback" value="false" />
    <preference name="AutoHideSplashScreen" value="true" />
    <preference name="BackupWebStorage" value="cloud" />


这样一些  运行时会出现三个弹框(因为www包是老大发给我的,他是搞安卓的)  一次点击取消也可得到想要的效果   任务也可以完成   可是点击三次取消按钮  谁会不觉得烦呢

附上图片   图片1:



图片2:



图片3:



对于这个问题老大也说不出来   我也是百思不得其解   后来在栈溢出上找到一点线索  我试了半天  终于成功了

栈溢出上面说把安卓的什么东西带了进来  说的比较模糊  我仔细看了下工程  发现工程中有两个这样的文件



于是我把包里面的一个文件移出到了桌面   再次运行程序  发现没有任何问题   大功告成了

运行效果图如下

1、



2、



3、





友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: