ios切片工具 苹果切片_物联网


ios 九切片

App slicing is a new iOS feature available since iOS and tvOS version 9.0. It’s purpose is to reduce the size of the main application bundle by allowing developers to upload several device-dependent versions of resources to the App Store. Only one out of these is included in the App bundle for the device of the particular user.

应用程序切片是iOS和tvOS 9.0版以来可用的新iOS功能。 目的是通过允许开发人员将多个设备相关的资源版本上载到App Store,以减小主应用程序包的大小。 对于特定用户的设备,App捆绑包中仅包含其中的一个。

App slicing is very useful on iOS platform, because it helps the developers to pack more assets into the initial app bundle and still stay within the 100MB over-the-air download limit. To achieve this objective, the developer may also use the counterpart of app slicing, on-demand resources, which we have covered previously. However, in order to use on-demand resources, the app needs to be adapted to download needed resources dynamically, which is not always convenient or optimal. It’s also more complex in all cases. App slicing does not have these drawbacks.

应用程序切片在iOS平台上非常有用,因为它可以帮助开发人员将更多资产打包到初始应用程序包中,并且仍保持在100MB无线下载限制之内。 为了实现此目标,开发人员还可以使用应用切片的对应资源,这是我们先前介绍的按需资源。 但是,为了使用按需资源,需要使该应用适应于动态下载所需资源,这并不总是很方便或最佳。 在所有情况下它都更加复杂。 应用程序切片没有这些缺点。

There are two flavors of app slicing: app executable slicing and app resource slicing. The former refers to removal of unneeded executable code from the application bundle and is employed automatically on the App Store for all apps that target iOS/tvOS version 9.0 and higher. The latter refers to removal of unneeded assets and needs more developer effort in order to work. This is what we will cover in this blog post.

应用程序切片有两种形式:应用程序可执行文件切片和应用程序资源切片。 前者是指从应用程序捆绑包中删除不需要的可执行代码,并且在所有面向iOS / tvOS 9.0或更高版本的应用程序中自动在App Store上使用。 后者是指删除不需要的资产,并且需要更多开发人员的努力才能工作。 这就是我们将在这篇博客文章中介绍的内容。

The primary objective of app resource slicing is to reclaim wasted bandwidth and space in cases when there are several variants of the same asset. Usage of different asset variants is frequently needed because there is large difference of hardware capabilities between the most recent and older, but still widely used iOS devices. Most of the time developers need to use assets of different quality to fully utilize the most performant devices without penalizing the rest. Prior to iOS 9.0, all asset variants had to be included into the main app bundle. That wasted bandwidth and storage space on devices, as all but one asset variants were unused. By employing app resource slicing, it’s possible to exclude any unneeded assets from the application bundle.

应用程序资源切片的主要目的是在同一资产有多个变体的情况下回收浪费的带宽和空间。 经常需要使用不同的资产变体,因为最新和较旧但仍被广泛使用的iOS设备之间的硬件功能差异很大。 大多数时候,开发人员需要使用质量不同的资产来充分利用性能最高的设备,而不会对其余设备造成损失。 在iOS 9.0之前,所有资产变体都必须包含在主应用程序包中。 这浪费了设备上的带宽和存储空间,因为除了一种资产变体之外,其他所有变量都没有使用。 通过使用应用程序资源切片,可以从应用程序包中排除任何不需要的资产。

The most convenient way of taking advantage of app resource slicing is via asset bundles. They are the easiest option for adapting the layout of the application assets for slicing. Asset bundles are integrated within Unity and the performance is effectively equivalent to loading from regular data files. Asset bundles are also used as the backend for on-demand resources, thus it’s convenient to add app thinning support to an app that already uses on-demand resources or vice-versa. Once asset bundles are configured, you need very few additional changes to use app resource slicing, as shown in the code examples below. In this blog post, we won’t cover asset bundles. If this is the first time you hear about them, this resource will help you.

利用应用程序资源切片的最便捷方法是通过资产捆绑包。 它们是调整应用程序资产布局以进行切片的最简单选择。 资产捆绑包已集成到Unity中,其性能实际上等效于从常规数据文件加载。 资产捆绑包还用作按需资源的后端,因此可以为已经使用按需资源的应用程序添加应用程序精简支持,反之亦然。 配置资产捆绑包后,只需很少的其他更改即可使用应用程序资源切片,如下面的代码示例所示。 在此博客文章中,我们将不介绍资产捆绑包。 如果这是您第一次听说它们,那么本资源将为您提供帮助。

In order to use app resource slicing, the developer needs to specify which devices are eligible for all variants of assets that need to participate in resource slicing and then load the assets during application startup. In vanilla iOS app development, this is done by creating data set or image set items within an asset catalog, setting up device variations and then assigning resources to the placeholders in the UI. In Unity, the developer needs to set up asset bundle variants, that is, several asset bundles containing the same set of assets assets themselves potentially being different. All asset bundle variants that participate in app resource slicing need to be registered in code using UnityEditor.iOS.BuildPipeline.collectResources callback API. Later, the exact device requirements are specified in the player settings UI. Finally, the developer needs to manually load asset bundle via AssetBundle.CreateFromFile API on application startup.

为了使用应用程序资源切片,开发人员需要指定哪些设备适用于需要参与资源切片的资产的所有变体,然后在应用程序启动期间加载资产。 在原始iOS应用程序开发中,这是通过在资产目录中创建数据集或图像集项,设置设备版本 ,然后在UI中将资源分配给占位符来完成的。 在Unity中,开发人员需要设置资产束变体,即,包含同一组资产的多个资产束本身可能不同。 需要使用UnityEditor.iOS.BuildPipeline.collectResources回调API在代码中注册所有与应用程序资源切片有关的资产捆绑变体。 稍后,在播放器设置UI中指定确切的设备要求。 最后,开发人员需要在应用程序启动时通过AssetBundle.CreateFromFile API手动加载资产捆绑包。


ios切片工具 苹果切片_python_02


(The following two code examples demonstrate the essence of using app resource slicing:)

Editor script to register resources that should participate in app resource slicing:

编辑器脚本,用于注册应参与应用程序资源切片的资源:



using UnityEditor.iOS;         

          #if ENABLE_IOS_APP_SLICING         

          public class BuildResources         

          {         

          [InitializeOnLoadMethod]         

          static void SetupResourcesBuild()         

          {         

             UnityEditor.iOS.BuildPipeline.collectResources += CollectResources;         

          }         

          static UnityEditor.iOS.Resource[] CollectResources()         

          {         

            return new Resource[] {         

              new Resource("asset-bundle-name").BindVariant("path/to/asset-bundle.hd"), "hd")         

                                               .BindVariant("path/to/asset-bundle.md"), "md")         

                                               .BindVariant("path/to/asset-bundle.sd"), "sd"),         

            };         

          }
using UnityEditor . iOS ;         

          #if ENABLE_IOS_APP_SLICING         

          public class BuildResources         

          {         

          [ InitializeOnLoadMethod ]         

          static void SetupResourcesBuild ( )         

          {         

             UnityEditor . iOS . BuildPipeline . collectResources += CollectResources ;         

          }         

          static UnityEditor . iOS . Resource [ ] CollectResources ( )         

          {         

             return new Resource [ ] {         

               new Resource ( "asset-bundle-name" ) . BindVariant ( "path/to/asset-bundle.hd" ) , "hd" )         

                                               . BindVariant ( "path/to/asset-bundle.md" ) , "md" )         

                                               . BindVariant ( "path/to/asset-bundle.sd" ) , "sd" ) ,         

             } ;         

          }


Loading of asset bundles during startup:

启动期间加载资产束:

< ...>         

          var bundle = AssetBundle.LoadFromFile("res://asset-bundle-name");         

          // now use AssetBundle APIs to load assets         

          // or Application.LoadLevel to load scenes         

          var asset = bundle.LoadAsset("Asset");         

          < ...>

& lt ; . . . & gt ;         

          var bundle = AssetBundle . LoadFromFile ( "res://asset-bundle-name" ) ;         

          // now use AssetBundle APIs to load assets         

          // or Application.LoadLevel to load scenes         

          var asset = bundle . LoadAsset ( "Asset" ) ;         

          & lt ; . . . & gt ;


The easiest way to start exploring asset bundles and app resource slicing is to use our Asset Bundle Manager demo project, which is available on BitBucket. The landing page offers a comprehensible description of how to use and tweak the demo.

开始探索资产捆绑和应用程序资源切片的最简单方法是使用我们的Asset Bundle Manager演示项目,该项目可在BitBucket上获得 。 登陆页面提供了有关如何使用和调整演示的全面描述。

翻译自: https://blogs.unity3d.com/2015/12/28/optimizing-ios-app-size-with-resource-slicing/

ios 九切片