转换到iOS 5时要注意什么 [英] What to watch out for when transitioning to iOS 5

查看:88
本文介绍了转换到iOS 5时要注意什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

摘要: 您是否可以在迁移到iOS 5时添加我需要注意的事项清单? StackOverflow非常宝贵,因为我一直致力于升级到iOS 5.我发现了一些在Xcode 4.2之前我错过的非常基本的东西,我想知道其他陷阱可能潜伏着什么。

Summary: Can you add to my checklist of things to watch out for when migrating to iOS 5? StackOverflow has been invaluable as I've worked on upgrading to iOS 5. I've discovered some pretty basic things I'd missed prior to Xcode 4.2, and I'm wondering what other "gotchas" might be lurking.

详细信息:本周iOS 5发货时,我不得不对我的几个应用进行一些更改。由于新的ARC功能,Xcode 4.2在分析内存管理代码方面做得更好。 iOS 5更新是查看所有内存管理代码的重要信息。新编译器还发现了早期编译器遗漏的许多其他问题。感谢Apple编译工程师。以下是有帮助的主要内容(其中许多内容也适用于早期版本的iOS)。

Detail: With iOS 5 shipping this week, I've had to make some changes to a couple of my apps. Xcode 4.2 does a much better job analyzing memory management code because of the new ARC feature. The iOS 5 update is a great point at which to review all your memory management code. The new compiler also finds a number of other issues that earlier compilers missed. Kudos to the Apple compiler engineers. Here are the main things that have helped (and many of them will also apply to earlier versions of iOS).


  1. 确保在你的dealloc方法的结尾处​​调用[super dealloc] ,而不是开头。

  2. 在viewDidUnload中,有些人报告了需要的错误[super viewDidUnload]将在viewDidUnload的末尾而不是开头调用。

  3. 了解保留计数,合成设置器以及何时调用release或autorelease。新编译器将指出比旧编译器更多的问题。 (我以为我一直很小心,但显然我不够小心。)Apple的内存管理指南是必读的 - 没有捷径。

  4. 这是一个最好在调试时打开僵尸(在Xcode中,选择Product | Edit Scheme。 ..并选择Debug方案;在Diagnostics选项卡上,选中Enable Zombie Objects。这可以帮助您找到僵尸的尝试用途(您不应再使用的对象)。

  5. Leaks仪器也很有帮助。在配置文件模式下运行您的应用程序,然后选择Leaks模板。在仪器窗口中,选择泄漏仪器并选中收集泄漏的内存内容框,它将帮助您查看泄露的内存源自代码的位置。

  1. Make sure to call [super dealloc] at the END of your dealloc methods, not the beginning.
  2. In viewDidUnload, some people have reported bugs that require [super viewDidUnload] to be called at the end, not the beginning, of your viewDidUnload.
  3. Understand retain counts, synthesized setters, and when to call release or autorelease. The new compiler will point out more problems than the older compilers did. (I thought I'd been careful, but apparently I wasn't careful enough.) Apple's memory management guide is required reading -- no shortcuts.
  4. It's a good idea to turn on zombies when debugging (in Xcode, choose Product | Edit Scheme... and select the Debug scheme; on the Diagnostics tab, check Enable Zombie Objects). This can help you find attempted uses of zombies (objects you shouldn't be using any more).
  5. The Leaks instrument is also helpful. Run your app in Profile mode and choose the Leaks template. In the Instruments window, select the Leaks instrument and check the box that says "Gather Leaked Memory Contents" and it will help you see where the leaked memory originates in your code.

我遇到过一些可能的结果:

There are a few odds and ends I've encountered:


  • Apple的单身模式需要在返回类型声明中添加oneway:

  • Apple's singleton pattern needs "oneway" added to the return type declaration:

    - (oneway void) release { }




  • 您可能需要在构建设置中手动添加armv6作为架构类型(和确保Build Active Architecture Only设置为NO)。

    • You may need to manually add "armv6" as an architecture type in your Build Settings (and be sure Build Active Architecture Only is set to NO).
    • 我应该寻找潜在陷阱的其他建议吗?我觉得我的应用程序现在更稳定了,但我之前觉得它们相当不错。

      Any other suggestions of potential pitfalls I should look for? I have a feeling that my apps are more stable now, but I felt pretty good about them before.

      推荐答案

      1 /模态控制器如果你改变他们的大小,表现不同。如果您需要不同大小的模态对话框,请考虑使用iOS 5子视图控制器。

      1/ Modal controllers behave differently, if you were changing their size. If you need modal dialog of a different size, consider using iOS 5 child view controllers.

      2 /对于表格,如果您返回的是nil节标题和正高度,在iOS 4中,标题被隐藏了。在iOS 5中,您必须为nil标头返回零高度。

      2/ For a table, if you were returning nil section header and positive height, in iOS 4, the header was hidden. In iOS 5, you have to return zero height for nil headers.

      3 / UDID已弃用。您可以使用CFUUIDCreate创建唯一ID并将其保存到您的设置中,但请注意,可以备份设备数据,然后将其还原到其他设备,从而使您拥有两个具有相同ID的设备。我通过使用属性kSecAttrAccessibleWhenUnlockedThisDeviceOnly将我的id保存到keychain来解决了这种情况。

      3/ UDID is deprecated. You can use CFUUIDCreate to create a unique id and save it into your settings but be aware that a device data can be backed up and then restored to another device, leaving you with two devices with the same id. I solved the situation by saving my id into keychain with attribute kSecAttrAccessibleWhenUnlockedThisDeviceOnly.

      关于你的列表:
      [super viewDidUnload]应始终作为最后一个语句调用你的viewDidUnload。逻辑与[super dealloc]中的逻辑相同。注意,你还应该在你的dealloc中调用[self viewDidUnload](如果你还没有在那里释放你的内存),因为它不是隐式调用的(尽管有时是)。

      About your list: [super viewDidUnload] should be always called as the last statement in your viewDidUnload. The logic is the same as in [super dealloc]. Note, that you should also call [self viewDidUnload] in your dealloc (if you don't already release your memory there) because it is not called implicitly (although sometimes it is).

      从我的实验中,仪器中的泄漏检测不会报告在没有指定属性名称的情况下合成的属性的泄漏。

      From my experiments, leak detection in Instruments don't report leaks on properties which are synthesized without assigning a property name.

      这篇关于转换到iOS 5时要注意什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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