Implement app thinning in iphone application

折月煮酒 提交于 2019-12-01 23:04:05

App slicing is currently not working until further notice. The only way to reduce your app size is currently to reduce the amount of assets included in the .ipa.

You could try using On Demand Resources if they make sense for your app.

Searching app thining, bit code and on demand app resource from yesterday, Now I debug all these things and sharing my knowledge that I got from beautiful apple documentation with help of my sample project.

App thinning concept covers bit code and on-demand resource. I will discuss on-demand resource in detail below:-

On-Demand Resources in iOS:- It is accessing the images/videos/.h/.m/swift file whenever needed (Yes, on-demand resouring include source code files also).

  • Goto Resource tags setting in your target.
  • Create a new Tag. It will appear under Download Only On demand.
  • You can add .h, .m, .xassest, .png etc under various tags. You can also assign tag by selecting individual file like this in file inspector.

Now comes the coding part (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
        }
    }];
}

End accessing the on demand resource when not in use(generally when game level changes)

#pragma mark - Remove access to on demand
-(void)endAccessToOnDemandResource{
    [resourceRequest endAccessingResources];
}

NOTE:- Don't forgot to 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]

Please don't bother about autolayout in this project. My main focus is on demand resourcing/App thing.

SUMMARY:- Thus we can achieve app thinning by on-demand resourcing using above technique. Please also have a look at official documentation which also describes about tracking progress, priorities of resourceRequests(NSBundleResourceRequest).

As far as i understand App thinning, it is all done by Apple. It looks at what is the target device, and the required images and stuff will be provided to the user automatically.

If you would like get thinner app, maybe refactoring is the topic you should look at.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!