即使 iPad 尚未运行 iOS 4,我应该如何构建包含 iOS 4 功能的通用 iOS 应用程序?

发布于 2024-09-11 20:27:32 字数 493 浏览 5 评论 0原文

我想为 iPhone 和 iPad 制作一款游戏。因此,从头开始这个项目作为通用应用程序是有意义的。然而,iPhone 和 iPad 目前运行两个不同版本的 iOS,因为 iOS 4 尚未适用于 iPad。我希望在我的游戏中支持两个 iOS 4 功能(GameCenter 和 iAd)。

  1. 在这种情况下,将此项目创建为通用应用程序是不是一个坏主意?
  2. 如果没有,当我构建一个支持两个不同版本的 iOS 的通用应用程序时,我应该考虑哪些想法?
  3. 押注苹果将如猜测的那样在秋季发布适用于 iPad 的 iOS 4 是否安全?
  4. 如果是这样,我是否可以开始将这些 iOS 4 功能(GameCenter 和 iAd)构建到我的 iPad 游戏版本中?

预先非常感谢您的智慧!

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

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. 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!

EDIT: 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

北恋 2024-09-18 20:27:32

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

  • 仅当类在当前设备上可用时才使用它们

    考虑这段代码:

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

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

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

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

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

  • 仅使用当前设备上可用的方法

    假设您想要执行以下操作:

    [[UIApplication共享应用]scheduleLocalNotification:n];
    

    使用以下代码有条件地调用该方法(如果该方法在当前设备上可用):

    if ([UIApplication实例RespondToSelector:@selector(scheduleLocalNotification:)]) {
      [[UIApplication共享应用]scheduleLocalNotification:n];
    }
    

:创建通用应用程序可能只需要了解两种技术。根据设备功能有条件地执行您的代码,应该没问题。

话虽如此,您仍然需要考虑 iPad 可能会使用与 iPhone 版本不同的 UI。而且,不幸的是,在 iOS 4 功能在 iPad 上可用之前,您将无法使用 iOS 4 功能测试您的 iPad UI。但这应该不是什么太大的问题:如果您使用 [[UIDevice currentDevice] userInterfaceIdiom] 来检查您是否在 iPad 上运行,您可以阻止您的通用应用程序执行以下代码:还没有 iPad UI。 Apple 发布适用于 iPad 的 iOS 4 后,您可以实施 UI、删除该检查并向商店发布更新。

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

    Consider this piece of code:

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

    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.

    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.

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.

时常饿 2024-09-18 20:27:32

您主要需要做两件事:

  1. 弱链接 3.2 SDK 中不存在的任何框架。
  2. 为 iOS 4 中的任何新 API 编写运行时测试。

首先,右键单击您的目标并选择“获取信息”。这些框架列在检查器中(在“常规”选项卡下),旁边有一个下拉框,允许您选择“弱”链接。这可以确保应用程序在框架不存在时仍然可以运行。

要执行第二个操作,您可以执行类似以下操作来测试 iOS 4 中新的基于块的动画:

if ([UIView respondsToSelector:@selector(animateWithDuration:animations:)]) {
    // Your awesome animation code here
} else {
    // Your almost-as-awesome, non-block-based animation code here.
}

通过使用内省方法(例如 -respondsToSelector:),您可以避免调用当前- 运行的操作系统不支持。

另请注意,如果您想支持 iPhone OS 3.0,则同样的规则也适用。

最后,也可以(尽管不建议)这样做:

#ifdef __IPHONE_4_0
    // Your iOS 4.0-compatible code here
#elif defined(__IPHONE_3_2)
    // Your iPhone OS 3.2-compatible code here
#elif defined(__IPHONE_3_0)
    // Your iPhone OS 3.0-compatible code here
#endif

为什么这不建议?简单:仅编译最高编号的 iOS 版本的代码。 iPhone 应用程序不会针对单独的 iOS 版本单独编译,因此要使其真正发挥作用,您必须发布该应用程序的多个版本。

You mainly need to do two things:

  1. Weak-link any frameworks that aren’t present in the 3.2 SDK.
  2. Write runtime tests for any APIs that are new to iOS 4.

To do the first, right-click on your target and select “Get Info.” The frameworks are listed in the inspector (under the “General” tab) with a drop-down box next to them that’ll allow you to select “Weak” linking. This ensures that the app will still run if the framework is not present.

To do the second, you could do something like the following to test for the new block-based animation in iOS 4:

if ([UIView respondsToSelector:@selector(animateWithDuration:animations:)]) {
    // Your awesome animation code here
} else {
    // Your almost-as-awesome, non-block-based animation code here.
}

By using introspective methods such as -respondsToSelector:, you can avoid calling something that the currently-running OS doesn’t support.

Note also that if you wanted to support iPhone OS 3.0, these same rules would apply.

Finally, it's also possible—though not advisable—to do this like so:

#ifdef __IPHONE_4_0
    // Your iOS 4.0-compatible code here
#elif defined(__IPHONE_3_2)
    // Your iPhone OS 3.2-compatible code here
#elif defined(__IPHONE_3_0)
    // Your iPhone OS 3.0-compatible code here
#endif

Why is this not advisable? Simple: only the code for the highest-numbered iOS version will be compiled. iPhone apps aren’t compiled separately for separate iOS versions, so to get this to actually work, you would have to release multiple versions of the app.

秋风の叶未落 2024-09-18 20:27:32

这是一个与管理风险有关的问题。风险包括:

  1. 苹果未发布预期
    “统一4.1”操作系统
    您需要的时间范围
  2. 操作系统会按时发布给您
    需要,但 GameCenter 之一或两者
    或不包含 iAds
  3. GameCenter 和/或包含 iAds,
    但它们与确切的 API 不匹配
    您所期望的
  4. API 正是您所期望的,但是
    他们是越野车,因为这是第一个
    iPad 上的版本
  5. 等...

只有您可以确定您对每种风险的适应程度、您认为每种风险的可能性有多大、是否可以减轻每种风险以及这些问题的成本是多少道路。

This is a question that is all about managing risk. Risks include:

  1. Apple doesn't release the expected
    "unified 4.1" OS within the
    timeframe you need
  2. The OS is released on time for your
    needs, but one or both of GameCenter
    or iAds aren't included
  3. GameCenter and/or iAds are included,
    but they don't match the exact API
    you were expecting
  4. The APIs are what you expected, but
    they are buggy since it is the first
    version on the iPad
  5. etc...

Only you can determine what level of each risk you're comfortable with, how likely you think each risk is, if you can mitigate each risk, and what the costs would be for any of these problems along the way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文