2015-10-13 148 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

相關問題