简体   繁体   English

phonegap ipad / iphone,在这两款设备上都有一个应用程序

[英]phonegap ipad/iphone, have a single app on both devices

So I've been doing phonegap development for a while and have made a couple apps in the app store. 所以我一直在做phonegap开发一段时间,并在应用程序商店中制作了几个应用程序。 I have made iphone and ipad apps and make them completely separate. 我已经制作了iphone和ipad应用程序并将它们完全分开。 I know apple allows for the submission of a single app that can be formatted for both devices, my question is how is this done with phonegap? 我知道苹果允许提交可以为两种设备格式化的单个应用程序,我的问题是如何通过phonegap完成这项工作? I know I can edit the project settings and select ipad/iphone for the target device. 我知道我可以编辑项目设置并为目标设备选择ipad / iphone。 But what do I do in my code to get it to work correctly? 但是我在代码中如何才能使其正常工作?

Since it's html, I control sizing in html (and jquery). 因为它是html,我控制html(和jquery)中的大小调整。 For example in my iphone app, I might have: 例如,在我的iPhone应用程序中,我可能有:

<img src="asdf.jpg" width="480">

And then that same ipad app would be: 那个相同的ipad应用程序将是:

<img src="asdf.jpg" width="1024">

It would be really awesome if I can just have two html files in my www folder, say, index.html and index-ipad.html, and then they share common img, css, and js folders. 如果我可以在我的www文件夹中有两个html文件,比如index.html和index-ipad.html,然后它们共享常见的img,css和js文件夹,那真的很棒。 Is this possible? 这可能吗?

I've checked the docs on phonegap extensively and couldn't find anything. 我已经广泛检查了关于phonegap的文档,但找不到任何内容。 Can somebody point me to a tutorial to do this? 有人能指点我做一个教程吗? I really hate having multiple apps in the app store for the same content. 我真的很讨厌在应用程序商店中为同一内容添加多个应用程序。

EDIT PER COMMENT BELOW 编辑以下评论

Maybe I wouldn't use the width attribute in html, maybe I would do this: 也许我不会在html中使用width属性,也许我会这样做:

<img src="asdf_ipad.jpg">

and: 和:

<img src="asdf_iphone.jpg">

where the two images have been sized for the two devices. 两个图像的大小已经设置为两个设备。 In any event, I can handle the html/js/css, I just need to know how to implement a "switch" such that the ipad renders different from the iphone. 无论如何,我可以处理html / js / css,我只需要知道如何实现一个“开关”,使ipad呈现与iphone不同。

You can specify what file PhoneGap opens initially. 您可以指定PhoneGap最初打开的文件。 Have a look at application:didFinishLaunchingWithOptions from AppDelegate.m 看一下应用程序:来自AppDelegate.m的didFinishLaunchingWithOptions

Do something like this to open a different index page for iPad: 做这样的事情为iPad打开不同的索引页面:

if ([[[UIDevice currentDevice] model] containsString:@"iPad"]) {
    ...
    self.viewController = [[[MainViewController alloc] init] autorelease];
    self.viewController.wwwFolderName = @"www-ipad";
    self.viewController.startPage = @"index.html";
    ...
}

why not use CSS media queries to identify your target device and update the images as appropriate? 为什么不使用CSS媒体查询来识别您的目标设备并适当更新图像? JqueryMobile for example does this to provide high-resolution icons to Retina devices... 例如,JqueryMobile这样做可以为Retina设备提供高分辨率图标......

Here's an article on how to use those to apply different stylesheets to iPhone vs iPad. 这是一篇关于如何使用这些应用程序将不同样式表应用于iPhone与iPad的文章。

Hope this helps! 希望这可以帮助!

One option: 一种选择:

<img src="asdf.png" class="asdf"/>

.ipad .asdf {
  width: 1024px;
}
.iphone .asdf {
  width: 480px;
}

$(function() {
  var deviceType = (device.platform=='iPhone' && screen.width==768) ? 'ipad' : 'iphone';
  $('body').addClass(deviceType);
});

Note the deviceType logic is pretty simple (ie iPad locked in portrait), you will need to expand the logic to handle orientations and potentially add even further logic to detect Retina devices and in the future higher resolution iPads. 请注意, deviceType逻辑非常简单(即iPad以纵向锁定),您需要扩展逻辑以处理方向,并可能添加更多逻辑来检测Retina设备以及未来更高分辨率的iPad。

Well, I found a solution, I just use javascript to forward the page to my other html page like this: 好吧,我找到了一个解决方案,我只是使用javascript将页面转发到我的其他html页面,如下所示:

if(screen.width==768)
    window.location='index-ipad.html';

So I just have that code in my index.html file, and then, of course, I have a different index-ipad.html file. 所以我只在index.html文件中有这个代码,然后,当然,我有一个不同的index-ipad.html文件。 This gives me the freedom to do whatever I want and not limit me to just minor style changes. 这让我可以自由地做任何我想做的事情,而不是仅限于轻微的风格变化。 Note, this didn't work inside the jquery onload stuff $(function() {}); 注意,这在jquery onload stuff $(function(){})中没有用; go figure. 去搞清楚。

I would have preferred to solve this with a "server side" approach, meaning the objective c layer that this resides upon. 我宁愿用“服务器端”方法来解决这个问题,这意味着它所依赖的目标c层。 But, unfortunately, my skills in objective c aren't quite up to par. 但是,不幸的是,我在目标c中的技能还不尽如人意。 If anybody can give me that solution, I would greatly appreciate it! 如果有人能给我这个解决方案,我将不胜感激!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM