在 iphone 个应用程序中实施应用程序瘦身
Implement app thinning in iphone application
我的 iOS 应用程序在应用商店中的大小相当大。我怎样才能降低 app thinning 以降低应用程序大小。
Note
:-
- 我已经在使用Images.xcassets单独放置x/2x/3x张图片。
- 我也读过这个 apple documentation 并负责优化级别构建设置。
- 我也在使用 8 位 PNG 而不是 32 位 PNG。
据我了解App瘦身,都是Apple做的。它会查看目标设备是什么,并将自动向用户提供所需的图像和内容。
如果你想要更瘦的应用程序,也许重构是你应该关注的主题。
应用切片 currently not working 直至另行通知。目前,减小应用程序大小的唯一方法是减少 .ipa 中包含的资产数量。
如果对您的应用有意义,您可以尝试使用 On Demand Resources。
从昨天开始搜索应用程序细化、位代码和按需应用程序资源,现在我调试所有这些东西并分享我在示例项目的帮助下从美丽 apple documentation 获得的知识。
应用程序瘦身概念涵盖 bit code 和按需资源。我将在下面详细讨论点播资源:-
iOS中的点播资源:-
它在需要时访问 images/videos/.h/.m/swift 文件 (Yes, on-demand resouring include source code files also
).
- 转到目标中的
Resource tags
设置。
- 创建一个新的
Tag
。它将出现在“仅按需下载”下。
- 您可以在各种标签下添加.h、.m、.xassest、.png 等。您还可以通过选择单个文件来分配标签 like this in file inspector.
现在是编码部分(my favourite site):-
NSBundleResourceRequest *resourceRequest;
#pragma mark - On demand resource
-(void)getOnDemandResource{
NSSet *setOfTag = [NSSet setWithObjects:@"chair", nil];
resourceRequest = [[NSBundleResourceRequest alloc]initWithTags:setOfTag];
[resourceRequest conditionallyBeginAccessingResourcesWithCompletionHandler:^(BOOL resourcesAvailable) {
if (!resourcesAvailable) {
// resourceRequest.loadingPriority = 1;//set the downloading priority (0 - 1) , NSBundleResourceRequestLoadingPriorityUrgent
[resourceRequest beginAccessingResourcesWithCompletionHandler:^(NSError * _Nullable error) {
if (error) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Error" message:error.debugDescription preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:alert animated:YES completion:nil];
}else{
//// The associated resources are loaded
}
}];
}else{
// The associated resources are available
}
}];
}
在不使用时结束访问点播资源(通常在游戏关卡改变时)
#pragma mark - Remove access to on demand
-(void)endAccessToOnDemandResource{
[resourceRequest endAccessingResources];
}
NOTE:-
别忘了enable On_Demand_Resources in build setting.
EXAMPLE PROJECT:- I create a sample project and uploaded here:- [http://www.dropbox.com/s/edi5zj68a4wuguh/WebOnTab.zip?dl=0][6]
请不要为这个项目中的自动布局烦恼。我主要关注点播resourcing/App的事情。
总结:- 因此我们可以使用上述技术通过 on-demand resourcing
实现 app thinning
。另请查看 official documentation,其中还描述了关于 tracking progress
、priorities
的 resourceRequests(NSBundleResourceRequest
).
我的 iOS 应用程序在应用商店中的大小相当大。我怎样才能降低 app thinning 以降低应用程序大小。
Note
:-
- 我已经在使用Images.xcassets单独放置x/2x/3x张图片。
- 我也读过这个 apple documentation 并负责优化级别构建设置。
- 我也在使用 8 位 PNG 而不是 32 位 PNG。
据我了解App瘦身,都是Apple做的。它会查看目标设备是什么,并将自动向用户提供所需的图像和内容。
如果你想要更瘦的应用程序,也许重构是你应该关注的主题。
应用切片 currently not working 直至另行通知。目前,减小应用程序大小的唯一方法是减少 .ipa 中包含的资产数量。
如果对您的应用有意义,您可以尝试使用 On Demand Resources。
从昨天开始搜索应用程序细化、位代码和按需应用程序资源,现在我调试所有这些东西并分享我在示例项目的帮助下从美丽 apple documentation 获得的知识。
应用程序瘦身概念涵盖 bit code 和按需资源。我将在下面详细讨论点播资源:-
iOS中的点播资源:-
它在需要时访问 images/videos/.h/.m/swift 文件 (Yes, on-demand resouring include source code files also
).
- 转到目标中的
Resource tags
设置。 - 创建一个新的
Tag
。它将出现在“仅按需下载”下。 - 您可以在各种标签下添加.h、.m、.xassest、.png 等。您还可以通过选择单个文件来分配标签 like this in file inspector.
现在是编码部分(my favourite site):-
NSBundleResourceRequest *resourceRequest;
#pragma mark - On demand resource
-(void)getOnDemandResource{
NSSet *setOfTag = [NSSet setWithObjects:@"chair", nil];
resourceRequest = [[NSBundleResourceRequest alloc]initWithTags:setOfTag];
[resourceRequest conditionallyBeginAccessingResourcesWithCompletionHandler:^(BOOL resourcesAvailable) {
if (!resourcesAvailable) {
// resourceRequest.loadingPriority = 1;//set the downloading priority (0 - 1) , NSBundleResourceRequestLoadingPriorityUrgent
[resourceRequest beginAccessingResourcesWithCompletionHandler:^(NSError * _Nullable error) {
if (error) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Error" message:error.debugDescription preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:alert animated:YES completion:nil];
}else{
//// The associated resources are loaded
}
}];
}else{
// The associated resources are available
}
}];
}
在不使用时结束访问点播资源(通常在游戏关卡改变时)
#pragma mark - Remove access to on demand
-(void)endAccessToOnDemandResource{
[resourceRequest endAccessingResources];
}
NOTE:-
别忘了enable On_Demand_Resources in build setting.
EXAMPLE PROJECT:- I create a sample project and uploaded here:- [http://www.dropbox.com/s/edi5zj68a4wuguh/WebOnTab.zip?dl=0][6]
请不要为这个项目中的自动布局烦恼。我主要关注点播resourcing/App的事情。
总结:- 因此我们可以使用上述技术通过 on-demand resourcing
实现 app thinning
。另请查看 official documentation,其中还描述了关于 tracking progress
、priorities
的 resourceRequests(NSBundleResourceRequest
).