2014-10-17 116 views
0

的alasset我得到用戶ALAssetsLibrary與此代碼enumerateAssetsWithOptions返回nil

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; 

    // Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos. 
    [library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) { 
     // Within the group enumeration block, filter to enumerate just photos. 
     [group setAssetsFilter:[ALAssetsFilter allPhotos]]; 

     // Chooses the photo at the last index 
     [group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) { 

      // The end of the enumeration is signaled by asset == nil. 
      if (alAsset) { 

,從時間到時間alasset回報作爲零,我不知道爲什麼的問題。我試過的大多數手機都能正常工作,但由於某種原因,其他手機的alasset只是以零的形式返回。

+0

所有手機都是iOS版本嗎?你在調試輸出中看到任何警告嗎?他們是否都授予照片訪問權限? – 2014-10-17 19:14:47

+0

當'alAsset'爲'nil'時'index'的值是多少? – rmaddy 2014-10-17 20:05:48

+0

我不確定,因爲它在手機中,我沒有訪問權限。我試圖在模擬器中獲得相同的結果,索引號爲9223372036854775807. 當alAsset爲零且索引有值時,意味着什麼? – 2014-10-17 21:02:42

回答

1

iOS8引入了新的Photos Framework。現在,許多以前存儲在設備上的資產現在都存儲在iCloud中(即不在設備上)。在與這些資產進行交互(設備上可能有或沒有的資產)時,將使用照片框架。

我的猜測是ALAssetLibrary對於沒有存儲在設備本地的資產返回nil。因此,你遇到的問題。

我最近聽說iOS 8.1回滾了這個iCloud相關的變化,雖然我還沒有能夠驗證自己。

希望這會有所幫助。