我应该如何构建包含iOS 4功能的通用iOS应用程序,即使iPad还没有运行iOS 4? [英] How should I approach building a Universal iOS app that will include iOS 4 features, even though the iPad doesn't yet run iOS 4?

查看:105
本文介绍了我应该如何构建包含iOS 4功能的通用iOS应用程序,即使iPad还没有运行iOS 4?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为iPhone和iPad构建游戏。因此,从头开始作为通用应用程序启动此项目是有意义的。但是,iPhone和iPad目前运行两个不同版本的iOS,因为iOS 4还没有适用于iPad。我想在游戏中支持两种iOS 4功能(GameCenter和iAd)。

I'd like build a game for both the iPhone and iPad. As such, it would make sense to start this project from scratch as a universal app. However, iPhone and iPad currently run two different versions of the iOS since iOS 4 isn't available for the iPad yet. There are two iOS 4 features (GameCenter and iAd) that I would like to support in my game.


  1. 在这种情况下,将此项目创建为通用应用程序是一个坏主意吗?

  2. 如果没有,我正在构建一个支持两个不同版本的iOS的通用应用程序时应该考虑哪些想法?

  3. 打赌Apple发布会有点安全吗?据推测,iOS 4的iOS 4在秋季?

  4. 如果是这样,我是否可以开始在我的游戏iPad版本中构建这些iOS 4功能(GameCenter和iAd)?

  1. In this case, is it a bad idea to create this project as a universal app?
  2. If not, what are some thoughts I should take into consideration as I'm building a universal app that supports two different versions of the iOS?
  3. Is it somewhat safe to bet on Apple releasing the iOS 4 for the iPad in the fall as speculated?
  4. If so, is there anyway I can begin building these iOS 4 features (GameCenter and iAd) into my iPad version of my game?

非常感谢您的所有智慧!

Thanks so much in advance for all your wisdom!

编辑:我理解这个问题涉及管理风险。我知道这些风险,但是当iOS在各种iOS设备中分散时,我对与构建通用应用程序相关的任何技术设计考虑更感兴趣。

I understand this issue involves managing risks. I'm aware of the risks, but I'm more interested in any tech design considerations related to building a universal app when the iOS is fragmented among the various iOS devices.

推荐答案

如果您要构建通用应用程序,请记住以下两个源代码片段:

If you're about to build a Universal App, just remember the following two source code snippets:


  • 仅在当前设备上提供课程时使用课程

  • Using classes only if they are available on the current device

考虑以下代码:

UILocalNotification* n = [[UILocalNotification alloc] init];

构建通用应用程序时,此代码将导致运行iOS版本的任何设备出现运行时错误我不知道UILocalNotification类。

When building a Universal App, this code will lead to a runtime error on any device running an iOS version that does not know about the UILocalNotification class.

您仍然可以在代码中支持UILocalNotification,同时使用以下代码片段保持向后兼容性:

You can still support UILocalNotification in your code while maintaining backwards compatibility by using the following code snippet:

Class notificationClass = NSClassFromString(@"UILocalNotification");
if (notificationClass) {
  UILocalNotification* n = [[notificationClass alloc] init];
}

此技术允许您使用设备上某些操作系统版本不可用的类支持这些课程。

This technique allows you to use classes which are unavailable in certain OS versions on devices that do support the classes.

只有在当前设备上可用时使用方法

Using methods only if they are available on the current device

假设您要执行以下操作:

Suppose you'd like to do the following:

[[UIApplication sharedApplication] scheduleLocalNotification:n];

使用以下代码有条件地调用该方法,以防它在当前设备上可用:

Use the following piece of code to conditionally call the method in case it's available on the current device:

if ([UIApplication instancesRespondToSelector:@selector(scheduleLocalNotification:)]) {
  [[UIApplication sharedApplication] scheduleLocalNotification:n];
}


这两种技术是可能是您创建通用应用程序时唯一需要了解的事项。根据设备功能有条件地执行你的代码,你应该没问题。

These two techniques are probably the only things you need to know to create your Universal App. Conditionally execute your code depending on device capabilities and you should be fine.

话虽如此,你仍然需要考虑iPad可能会使用不同于你的用户界面。 iPhone对应。而且,遗憾的是,在iPad 4上可用之前,您将无法使用iOS 4功能测试iPad UI。但这不应该是一个问题:如果你使用 [[UIDevice currentDevice] userInterfaceIdiom] 检查你是否在iPad上运行,你可以阻止你Universal App执行没有iPad UI的代码。一旦Apple发布适用于iPad的iOS 4,您就可以实现UI,删除该检查并发布商店更新。

Having said that, you still need to consider that the iPad will probably be using a different UI than your iPhone counterpart. And, unfortunately, you won't be able to test your iPad UI with the iOS 4 features until they become available on the iPad. But this shouldn't be too much of a problem: if you use [[UIDevice currentDevice] userInterfaceIdiom] to check whether you're running on an iPad, you can prevent your Universal App from executing code that has no iPad UI yet. Once Apple releases iOS 4 for iPads, you can implement the UI, remove that check and release an update to the store.

这篇关于我应该如何构建包含iOS 4功能的通用iOS应用程序,即使iPad还没有运行iOS 4?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆