2016-05-13 78 views
0

我正在開發一個iOS應用程序,它從照片庫中獲取視頻,並且它一直工作。我只是測試的應用程序在不同的設備上(這是不是我考第一),它崩潰,當我使用檢索到的數據,我不明白爲什麼...NSRangeException與PHFetchResult

這裏是我的代碼:

self.videosAssets = PHAsset.fetchAssetsWithMediaType(.Video, options: nil) 

if self.videosAssets != nil { 
    for i in 0..<self.videosAssets!.count { 
     if let video = self.videosAssets!.objectAtIndex(i) as? PHAsset { 
      self.videos.append(Video(asset: video)) 
     } 
    } 
} 

它獲取221個視頻,但它崩潰時,我== 59

以下是錯誤我得到:

Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArray0 objectAtIndex:]: index 0 beyond bounds for empty NSArray' 
+1

不,它不會在'我== 59',它崩潰索引0崩潰,你肯定是代碼實際上導致錯誤/崩潰? – luk2302

+0

我意識到之後,我沒有測試視頻構造函數......我認爲應用程序崩潰在這裏。我將在星期一進行測試 –

回答

0
self.videosAssets = PHAsset.fetchAssetsWithMediaType(.Video, options: nil) 

if let videoAssets = self.videosAssets { 
    videoAssets.forEach { video in 
     if video as? PHAsset { self.videos.append(Video(asset: video)) } 
    } 
} 
0

在測試Video構造函數之後,出現這個問題。出於某種原因,當我打電話給let resources = PHAssetResource.assetResourcesForAsset(asset)時,它會返回一個空數組,這是應用程序崩潰的位置。

對不起,我這個沒用的帖子,也許這將幫助別人......

相關問題