为多个 iOS 版本构建时处理已弃用的符号和方法

发布于 10-07 11:31 字数 537 浏览 5 评论 0原文

我是一名 C++ 开发人员,正在过渡到 iPhone 世界,我很乐意在某些方面获得帮助。

举例来说,MPMoviePlayerController 用于在 iOS 3.1 及更早版本中发布 MPMoviePlayerContentPreloadDidFinishNotification 通知。

但是,现在此通知已被弃用。

我希望我的应用程序能够在每台装有 iOS 3 及更高版本的 iPhone 上运行。

如果我使用基础 sdk 4.2 进行开发,当我在 iOS 3.2 的 iPhone 上安装应用程序时会发生什么?该应用程序是否附带链接到它的 sdk(例如 mfc 静态链接)?

如果我理解正确的话,例如在装有 iOS 3.2 的 iPhone 上,该通知仍然会被调用。 (如果我在早期的 sdk 上调用函数,假设它没有像我上面问的那样静态链接)。

这是否意味着如果我现在正在编写一个新应用程序,我仍然需要处理那些已弃用的通知?

我无法理解这个问题,希望得到任何解释。

谢谢

I'm a c++ developer who is transitioning into the iPhone world, and I would love to get help around something.

Let's say for example, MPMoviePlayerController used to post the MPMoviePlayerContentPreloadDidFinishNotification notification in iOS 3.1 and earlier.

However, now this notification is deprecated.

I want my app to be able to run on every iPhone that has iOS 3 and above.

If I'm developing using base sdk 4.2, when I'm installing my app on an iphone with iOS 3.2 what will happen? Does the app comes with the sdk linked to it (like mfc static link for example)?

If I understand correctly, on iPhone with iOS 3.2 for example, that notification will still get called. (If i'm calling a function on an earlier sdk, assuming it's not statically linked like I asked above).

Does that mean that if I'm writing a new app now, I still have to take care of those deprecated notifications?

I can't get my head around this and would appreciate any explanation.

Thanks

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

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

发布评论

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

评论(1

比忠2024-10-14 11:31:30

如果您在运行 3.2 的设备上使用 iOS 4.2 中包含的符号,您将遇到崩溃。

解决这个问题的方法是根据新符号在运行时是否可用有条件地使用它们。

例如。

if (&NewNotificationSymbol != NULL)
{
    // awesome, it's not NULL, we can use it
}
else
{
    // not so awesome, we'll use the old, deprecated one
    // but at least we won't crash
}

同样的方法也适用于在 3.x 上运行时在 4.x 中新增的类:

if (NSClassFromString(@"MyAwesomeNewClass") != nil)
{
    // awesome, it's not NULL, we can use it
}
else
{
    // not so awesome, we'll use the old, deprecated one
    // but at least we won't crash
}

根据经验,您应该始终针对开发人员工具提供的最新 iOS SDK 进行编译和链接,然后设置您的部署将构建设置目标设置为您希望支持的最旧的 iOS 版本。然后使用这些条件来利用新功能,并在它们不可用时优雅地回退,而不会崩溃。

If you use a symbol that was included with iOS 4.2 on a device that is running 3.2 you will encounter a crash.

The way to get around this is to use new symbols conditionally based on whether or not they're available at runtime.

Eg.

if (&NewNotificationSymbol != NULL)
{
    // awesome, it's not NULL, we can use it
}
else
{
    // not so awesome, we'll use the old, deprecated one
    // but at least we won't crash
}

The same approach can be used for Classes that are new in 4.x when running on 3.x too:

if (NSClassFromString(@"MyAwesomeNewClass") != nil)
{
    // awesome, it's not NULL, we can use it
}
else
{
    // not so awesome, we'll use the old, deprecated one
    // but at least we won't crash
}

As a rule of thumb, you should always compile and link against the latest iOS SDK provided with the developer tools and then set your Deployment Target build setting to the oldest version of iOS that you wish to support. Then use these conditionals to make use of new features and gracefully fallback without crashing if they're not available.

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