ios Single App Binary 如何支持 64 位和 32 位应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21200669/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 23:10:36  来源:igfitidea点击:

How Single App Binary Supports 64-bit and 32-bit Apps

iosiphoneapp-store32bit-64bit

提问by Mani

We can see apple announcement here.. According to this doc, we can submit same binary with supporting 32-bit and also 64-bit. I found one stack overflow answer here. But According to this answer, we shouldset deployment target as IO7+. But apple doc said, you can submit this with IOS 7 and IOS 6 support? My question is, How can we generate binary with supporting 32-bit and 64-bit by deployment target IOS6+?

我们可以在这里看到苹果的公告. 根据此文档,我们可以提交支持 32 位和 64 位的相同二进制文件。我在这里找到了一个堆栈溢出答案。但是根据这个答案,我们should设置了deployment target as IO7+. 但是apple doc说,你可以在IOS 7和IOS 6支持的情况下提交这个吗?我的问题是,我们如何通过部署目标 IOS6+ 生成支持 32 位和 64 位的二进制文件?

Note:I'm using xcode 5.0

注意:我正在使用xcode 5.0

Update:Question above is fixed by using xcode 5.0.2. But I get confused how can I make code for 32-bit as well 64-bit. I know one thing, we must do code for two separately in some times. But How can I do?. for example, if one method in deprecated in ios6 means, we provide code for ios 6 and ios7 also. In same case also followed here or do some other technic for this.

更新:Question above is fixed by using xcode 5.0.2。但是我很困惑如何为 32 位和 64 位编写代码。我知道一件事,我们有时必须分别为两个代码编写代码。但是How can I do?。例如,如果 ios6 中不推荐使用的一种方法意味着,我们也为 ios 6 和 ios7 提供代码。在同样的情况下也遵循这里或为此做一些其他技术。

回答by codercat

Xcode can build your app with both 32-bit and 64-bit binaries included so it works across all devices running iOS 7. If you wish to continue to support iOS 6 then you will need to build for 32-bit only. Next month we will be making changes that will allow you create a single app binary that supports 32-bit on iOS 6, as well as 32-bit and 64-bit on iOS 7.

Converting Your App to a 64-Bit Binary

At a high level, here are the steps to create an app that targets both the 32-bit and the 64-bit runtime environments:

1.Install Xcode 5.0.1.

2.Open your project. Xcode prompts you to modernize your project. Modernizing the project adds new warnings and errors that are important when compiling your app for 64-bit.

3.Update your project settings to support iOS 5.1.1 or later. You can't build a 64-bit project if it targets an iOS version earlier than iOS 5.1.

4.Change the Architectures build setting in your project to “Standard Architectures (including 64-bit).”

5.Update your app to support the 64-bit runtime environment. The new compiler warnings and errors will help guide you through this process. However, the compiler doesn't do all of the work for you; use the information in this document to help guide you through investigating your own code.

6.Test your app on actual 64-bit hardware. iOS Simulator can also be helpful during development, but some changes, such as the function calling conventions, are visible only when your app is running on a device.

7.Use Instruments to tune your app's memory performance.

8.Submit an app that includes both architectures for approval.

The remainder of this chapter describes problems that frequently occur when porting a Cocoa Touch app to the 64-bit runtime environment. Use these sections to guide your own efforts to investigate your code.

Xcode 可以构建包含 32 位和 64 位二进制文​​件的应用程序,因此它可以在所有运行 iOS 7 的设备上运行。如果您希望继续支持 iOS 6,那么您只需要为 32 位构建。下个月,我们将进行更改,允许您创建单个应用程序二进制文件,在 iOS 6 上支持 32 位,在 iOS 7 上支持 32 位和 64 位。

将您的应用程序转换为 64 位二进制文​​件

概括地说,以下是创建面向 32 位和 64 位运行时环境的应用程序的步骤:

1.安装Xcode 5.0.1。

2.打开你的项目。Xcode 会提示您对项目进行现代化改造。项目现代化会添加新的警告和错误,这在为 64 位编译应用程序时很重要。

3.更新您的项目设置以支持 iOS 5.1.1 或更高版本。如果目标是早于 iOS 5.1 的 iOS 版本,则无法构建 64 位项目。

4.将项目中的架构构建设置更改为“标准架构(包括 64 位)”。

5.更新您的应用程序以支持 64 位运行时环境。新的编译器警告和错误将帮助指导您完成此过程。但是,编译器不会为您完成所有工作。使用本文档中的信息来帮助指导您调查您自己的代码。

6.在实际的 64 位硬件上测试您的应用程序。iOS 模拟器在开发过程中也很有帮助,但某些更改(例如函数调用约定)仅在您的应用程序在设备上运行时可见。

7.使用 Instruments 来调整您的应用程序的内存性能。

8.提交包含两种架构的应用程序以供批准。

本章的其余部分描述了将 Cocoa Touch 应用程序移植到 64 位运行时环境时经常出现的问题。使用这些部分来指导您自己调查代码的工作。

From https://developer.apple.com/library/ios/documentation/General/Conceptual/CocoaTouch64BitGuide/ConvertingYourAppto64-Bit/ConvertingYourAppto64-Bit.html#//apple_ref/doc/uid/TP40013501-CH3-SW1

来自https://developer.apple.com/library/ios/documentation/General/Conceptual/CocoaTouch64BitGuide/ConvertingYourAppto64-Bit/ConvertingYourAppto64-Bit.html#//apple_ref/doc/uid/TP40013501-CH3-SW1

回答by codercat

iOS apps rely on a low-level application binary interface and coding conventions established by the Objective-C language and the system frameworks. Starting with iOS 7, some iOS devices use 64-bit processors and offer both a 32-bit and a 64-bit runtime environment. For most apps, the 64-bit runtime environment differs from the 32-bit runtime environment in two significant ways:

iOS 应用程序依赖于由 Objective-C 语言和系统框架建立的低级应用程序二进制接口和编码约定。从 iOS 7 开始,一些 iOS 设备使用 64 位处理器并提供 32 位和 64 位运行时环境。对于大多数应用程序,64 位运行时环境与 32 位运行时环境有两个显着不同:

In the 64-bit runtime, many data types used by Cocoa Touch frameworks (as well as the Objective-C language itself) have increased in size or have stricter memory alignment rules. See “Changes to Data Types.” The 64-bit runtime requires proper function prototypes to be used when making function calls. See “Changes to Function Calling.”

在 64 位运行时,Cocoa Touch 框架(以及 Objective-C 语言本身)使用的许多数据类型都增加了大小或具有更严格的内存对齐规则。请参阅“数据类型的更改”。64 位运行时要求在进行函数调用时使用正确的函数原型。请参阅“函数调用的变化”。

application binary interface (ABI)

应用程序二进制接口 (ABI)

Other Changes to the 64-Bit Runtime

64 位运行时的其他更改

The 64-bit ARM instruction set is significantly different from the 32-bit instruction set. If your app includes any assembly language code, you need to rewrite it to use the new instruction set. You also need a more detailed description of the 64-bit calling conventions in iOS, because the conventions do not exactly match the ARM standard. For more information, see iOS ABI Function Call Guide.

64 位 ARM 指令集与 32 位指令集有很大不同。如果您的应用程序包含任何汇编语言代码,您需要重写它以使用新的指令集。您还需要更详细地描述 iOS 中的 64 位调用约定,因为这些约定并不完全符合 ARM 标准。有关更多信息,请参阅 iOS ABI 函数调用指南

At a high level, to make your code 64-bit clean, you must do the following:

概括地说,要使您的代码 64 位整洁,您必须执行以下操作:

  1. Avoid assigning 64-bit long integers to 32-bit integers.
  2. Avoid assigning 64-bit pointers to 32-bit integers.
  3. Avoid pointer and long integer truncation during arithmetic operations (or other arithmetic problems caused by the change in integer types).
  4. Fix alignment issues caused by changes in data type sizes.
  5. Ensure that memory structures that are shared between the 32-bit and 64-bit runtimes share a similar layout.
  6. Rewrite any assembly language code so that your code uses the new 64-bit opcodes and runtime.
  7. Avoid casting variadic functions to functions that take a fixed number of parameters, or vice versa.
  1. 避免将 64 位长整数分配给 32 位整数。
  2. 避免将 64 位指针分配给 32 位整数。
  3. 避免在算术运算过程中出现指针和长整数截断(或其他因整数类型变化引起的算术问题)。
  4. 修复由数据类型大小变化引起的对齐问题。
  5. 确保在 32 位和 64 位运行时之间共享的内存结构共享类似的布局。
  6. 重写任何汇编语言代码,以便您的代码使用新的 64 位操作码和运行时。
  7. 避免将可变参数函数转换为采用固定数量参数的函数,反之亦然。

回答by Retro

At a high level, here are the steps to create an app that targets both the 32-bit and the 64-bit runtime environments:

概括地说,以下是创建面向 32 位和 64 位运行时环境的应用程序的步骤:

Install Xcode 5.0.2 (I have done with this only, maybe higher is better)

安装 Xcode 5.0.2(我只做过这个,也许越高越好)

Open your project. Xcode prompts you to modernize your project. Modernizing the project adds new warnings and errors that are important when compiling your app for 64-bit.

打开您的项目。Xcode 会提示您对项目进行现代化改造。项目现代化会添加新的警告和错误,这在为 64 位编译应用程序时很重要。

Update your project settings to support iOS 5.1.1 or later. You can't build a 64-bit project if it targets an iOS version earlier than iOS 5.1.

更新您的项目设置以支持 iOS 5.1.1 或更高版本。如果目标是早于 iOS 5.1 的 iOS 版本,则无法构建 64 位项目。

Change the Architectures build setting in your project to “Standard Architectures (including 64-bit).”

将项目中的架构构建设置更改为“标准架构(包括 64 位)”。

Update your app to support the 64-bit runtime environment. The new compiler warnings and errors will help guide you through this process. However, the compiler doesn't do all of the work for you; use the information in this document to help guide you through investigating your own code.

更新您的应用以支持 64 位运行时环境。新的编译器警告和错误将帮助指导您完成此过程。但是,编译器不会为您完成所有工作。使用本文档中的信息来帮助指导您调查您自己的代码。

Test your app on actual 64-bit hardware. iOS Simulator can also be helpful during development, but some changes, such as the function calling conventions, are visible only when your app is running on a device.

在实际的 64 位硬件上测试您的应用程序。iOS 模拟器在开发过程中也很有帮助,但某些更改(例如函数调用约定)仅在您的应用程序在设备上运行时可见。

Use Instruments to tune your app's memory performance. Submit an app that includes both architectures for approval.

使用 Instruments 来调整应用程序的内存性能。提交包含两种架构的应用程序以供批准。

The remainder of this chapter describes problems that frequently occur when porting a Cocoa Touch app to the 64-bit runtime environment. Use these sections to guide your own efforts to investigate your code.

本章的其余部分描述了将 Cocoa Touch 应用程序移植到 64 位运行时环境时经常出现的问题。使用这些部分来指导您自己调查代码的工作。

Follow the guide for supporting the 32 and 64 bitarchitecture by apple

遵循苹果支持 32 位和 64 位架构的指南

回答by Dracuuula

The program xcode 5 compiled contained two binary code:32-bit and 64 bit.In the 32-bit system will call the 32-bit code.In the 64-bit system will call the 64-bit code. At the same time, think about same program only have 32-bit code, the 64-bit system contained two framework:a 32-bit, a 64-bit.When the 64-bit system running the 32-bit program will call the 32-bit framework for the underlying support, running the 64-bit program will call the 64-bit framework for the underlying support.More detail you can see Apple's official documentation "64-Bit transition Guide for Cocoa Touch".

xcode 5 编译的程序包含两个二进制代码:32 位和 64 位。在 32 位系统中将调用 32 位代码。在 64 位系统中将调用 64 位代码。同时,想想同一个程序只有32位代码,64位系统包含两个框架:一个32位,一个64位。当64位系统运行32位程序时会调用底层支持32位框架,运行64位程序会调用底层支持的64位框架。更详细的可以看苹果官方文档《Cocoa Touch的64位过渡指南》。

Use xcode 5 can be easily compiled program into 64.The basic procedure is as follow.

使用xcode 5可以很方便的将程序编译成64位。基本过程如下。

  1. Set the support device into 'ios7'

  2. The "Architectures" in "Build Setting" changed to "Standard Architectures (including 64-bit)".

  1. 将支持设备设置为'ios7'

  2. “构建设置”中的“架构”更改为“标准架构(包括 64 位)”。

回答by Timur Kuchkarov

As for first part of question - Base SDK should be "Latest iOS SDK" which is iOS 7.0. Minimum deployment target should be iOS 6.0 or you won't be able to select "Standard architectues including 64-bit(armv7, armv7s, armv8)" for architectures. After you select these settings your app will be built for either 32 bit and 64 bit.

至于问题的第一部分 - Base SDK 应该是“最新的 iOS SDK”,即 iOS 7.0。最低部署目标应为 iOS 6.0,否则您将无法为架构选择“标准架构,包括 64 位(armv7、armv7s、armv8)”。选择这些设置后,您的应用程序将针对 32 位和 64 位构建。

As for update - after switching to 32/64bit archs, analyze your project and fix new warnings that can appear. Then test your app on real 64 bit device(iPhone 5s/iPad Air/iPad mini retina). If your app uses iCloud, test synchronization between 32 and 64 bit devices. Helpful info is in Apple's guide(summary from there is in @iDev answer).

至于更新 - 切换到 32/64 位架构后,分析您的项目并修复可能出现的新警告。然后在真正的 64 位设备(iPhone 5s/iPad Air/iPad mini 视网膜)上测试您的应用程序。如果您的应用程序使用 iCloud,请测试 32 位和 64 位设备之间的同步。有用的信息在Apple 的指南中(@iDev 答案中的摘要)。

EDIT

编辑

Actually yes, minimum is 5.1.1, but you should either set it manually or set deployment target lower than 6.0 and when you select architectures to incl. 64bit Xcode will ask you to set it as 5.1.1. Anyway I'm not sure why you'd want to support 5.1.1 specifically if you want to use 64bit archs.

实际上是的,最小值是 5.1.1,但是您应该手动设置它或将部署目标设置为低于 6.0,并且当您选择要包含的架构时。64 位 Xcode 会要求您将其设置为 5.1.1。无论如何,如果您想使用 64 位架构,我不确定为什么要特别支持 5.1.1。