【问题标题】:iOS concurrency / version distributioniOS并发/版本分布
【发布时间】:2012-01-22 21:59:10
【问题描述】:

我有一个问题,但可能可以通过几个相关问题之一来回答。

我正在 iOS 上开发一个简单的纸牌游戏,它需要我在主 UI 线程中同时运行一些 AI 和游戏逻辑。我希望我的应用程序与尽可能多的设备兼容,但我知道没有必要针对实际市场份额很小的平台。我可能会避免使用 Grand Central Dispatch,因为它需要 iOS 4.0 或更高版本。 OSX 开发者库将 NSOperation 列为自 OSX 10.5 起可用,并且在 iOS v1 几个月后于 2007 年推出(我现在假设它适用于 iOS)。我确定支持 NSThread。

我很好奇 iOS 设备版本的分布。 Google 在此处发布每个版本的手机数量数据:

http://developer.android.com/resources/dashboard/platform-versions.html

我没有从 Apple 找到任何类似的东西(是的,他们会发布)。在其他地方我可以找到有关 iOS 的类似信息吗?

我知道对于任何给定的设备,NSThread 无疑是兼容的。 NSOperation 可能会兼容,GCD 可能会兼容。但是一般情况下应该怎么做呢?就像我将来想要实现的其他一些功能一样。

对于手头的实际问题的任何建议也将不胜感激。

【问题讨论】:

  • Marco Arment 在他的博客上发布了一些关于 iOS 版本分布的有用统计数据,这些统计数据基于他的应用程序的用户:marco.org/2011/11/30/…

标签: iphone ios multithreading concurrency grand-central-dispatch


【解决方案1】:

NSThreadNSOperation 在 iOS2.0 及更高版本中均可用。

question 讨论了在现有应用程序中切断对旧 iOS 版本的支持的想法。并且another 讨论了有关版本支持的更多信息。

如果您希望支持旧 iOS 版本,但仍要使用新 iOS 版本中的某些功能,您可能需要做两件事:

方法可用性测试:

//UITableView - backgroundView is available in iOS3.2 and later.
if ([self.tableView respondsToSelector:@selector(setBackgroundView:)]) {
    UIImageView *theBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"back.png"]];
    [self.tableView setBackgroundView:theBackgroundView];
    [theBackgroundView release];
} else {
    //on devices running iOS 3.2 and below, the background remains unchanged, default.
}

弱链接:

iOS SDK 4.2(不是固件)中的新功能,对于针对 SDK 4.2 编译的项目,您可以简单地检查类是否存在:

if ([UIPrintInteractionController class]) {
    // Create an instance of the class and use it.
} else {
    // The print interaction controller is not available.
}

苹果docs。 (搜索弱链接)

在 iOS SDK 4.2 之前,您可以使用带有类名的字符串来执行此操作:

Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));
if (messageClass != nil) {          
    // Check whether the current device is configured for sending SMS messages
    if ([messageClass canSendText]) {
        [self displaySMSComposerSheet];
    }
}

【讨论】:

    猜你喜欢
    • 2021-11-04
    • 2015-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-13
    • 2019-11-12
    相关资源
    最近更新 更多