2015-10-13 151 views

回答

1

从昨天开始搜索应用程序,位代码和按需应用程序资源,现在我调试所有这些事情,并在我的示例项目的帮助下分享我从美丽apple documentation获得的知识。

应用稀疏概念涵盖bit code和按需资源。在iOS中

按需资源: - - :我将在下面详细讨论点播资源 据访问图像/视频/ .H/.M /快捷文件时需要(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] 

请不要在这个项目中自动布局。我主要关注的是需求资源/应用程序。

总结: -因此,我们可以使用上述技术实现app thinningon-demand resourcing。请参阅official documentation,其中还描述了资源请求(NSBundleResourceRequest)的tracking progress,priorities

+0

有谁知道如何检测点播资源下载后的位置?我正在尝试将它们用于我的游戏女巫不使用xcasset目录。我想下载纹理,然后使用它们,就好像它们是初始包的一部分,但我需要知道文件的确切位置。 – dimayak

+0

我检查了苹果文档(https://developer.apple.com/library/prerelease/ios/documentation/Foundation/Reference/NSBundleResourceRequest_Class/index.html#//apple_ref/occ/instm/NSBundleResourceRequest/initWithTags:bundle :) ,但仍然无法找到位置。所以我在SO上提出这个问题:http://stackoverflow.com/questions/33824601/how-to-detect-where-the-on-demand-resources-are-located-after-being-downloaded – pkc456

0

据我了解的应用程序的细化,这一切都由苹果公司完成。它着眼于目标设备是什么,所需的图像和内容将自动提供给用户。

如果你想获得更薄的应用程序,也许重构是你应该看看的主题。

+0

没错。它由Apple负责。但是在我的问题中列出的开发人员需要注意的地方可能存在一些不足之处。你有没有关于标签的想法,这与点播资源有关? – pkc456

1

应用程序切片是currently not working直到另行通知。减少应用程序大小的唯一方法是减少包含在.ipa中的资源数量。

如果它们对您的应用有意义,您可以尝试使用On Demand Resources

+0

感谢您分享有用的链接。我也跟随需求资源。让我再次在应用程序中进行检查。 – pkc456

+0

我尝试了需求资源并成功地在我的项目中实现了这一点。我在答案中也分享了一个详细的答案和示例项目。谢谢你指导我。 – pkc456

相关问题