iosiphoneios9xcode7on-demand-resources

Implement app thinning in iphone application


My iOS application's size is quite bigger on app store. How can I lower achieve the app thinning so that application size get lower.

Note:-

  1. I am already using Images.xcassets to put x/2x/3x images separately.
  2. I also read this apple documentation and take care of optimisation level build settings.
  3. I am also using an 8-bit PNG instead of a 32-bit PNG.

Solution

  • 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).

    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).