ArrayBuffer.getElementSlowPath Кто-нибудь сталкивался с этой ошибкой? - PullRequest
0 голосов
/ 27 декабря 2018

В моем проекте я показываю пользователю изображение библиотеки и видео, но на каком-то устройстве я получаю сбой, как ArrayBuffer.getElementSlowPath.Кто-нибудь может подсказать мне, как я могу повторить эту проблему?Я получил эту проблему от Crashlytics.

enter image description here

Вот мой код для получения видео от phaststs.

 func getVideo(withCompletionHandler completion:@escaping CompletionHandler)  {
        let fetchOptions = PHFetchOptions()
        let requestOptions = PHVideoRequestOptions()
        requestOptions.isNetworkAccessAllowed = false
        fetchOptions.sortDescriptors = [NSSortDescriptor(key:"creationDate", ascending: false)]
        let fetchResult: PHFetchResult = PHAsset.fetchAssets(with: PHAssetMediaType.video, options: fetchOptions)

        fetchResult.enumerateObjects ({ (assest, index, isCompleted) in
            if assest.sourceType != PHAssetSourceType.typeiTunesSynced{
                PHImageManager.default().requestAVAsset(forVideo: assest , options: requestOptions, resultHandler: { (asset : AVAsset?, video : AVAudioMix?, dic : [AnyHashable : Any]?) in
                    if let _ = asset as? AVURLAsset
                    {
                        let objAssest = GallaryAssets()
                        objAssest.objAssetsType = assetsType.videoType
                        objAssest.createdDate = (assest ).creationDate
                        objAssest.assetsDuration = (assest ).duration
                        objAssest.assetsURL = (asset as! AVURLAsset).url
                        objAssest.localizationStr = assest.localIdentifier
                        objAssest.locationInfo = LocationInfo()
                        if let location = (assest).location
                        {
                            objAssest.locationInfo.Latitude = "\(location.coordinate.latitude)"
                            objAssest.locationInfo.Longitude = "\(location.coordinate.longitude)"
                        }

                        self.media.add(objAssest)
                    }
                    completion(self.media)
                   }                    
                })
            }
        })
    }
}

Ответы [ 2 ]

0 голосов
/ 04 января 2019

Может быть, из iCloud идет какое-то видео / ресурс, вам нужно удалить PHVideorequestoptions , а затем проверить свой поток.Надеюсь, твоя авария решит.

func getVideo(withCompletionHandler completion:@escaping CompletionHandler)  {
        let fetchOptions = PHFetchOptions()
        fetchOptions.sortDescriptors = [NSSortDescriptor(key:"creationDate", ascending: false)]
        let fetchResult: PHFetchResult = PHAsset.fetchAssets(with: PHAssetMediaType.video, options: fetchOptions)

        fetchResult.enumerateObjects ({ (assest, index, isCompleted) in
            if assest.sourceType != PHAssetSourceType.typeiTunesSynced{
                PHImageManager.default().requestAVAsset(forVideo: assest , options: **PHVideoRequestOptions**(), resultHandler: { (asset : AVAsset?, video : AVAudioMix?, dic : [AnyHashable : Any]?) in
                    if let _ = asset as? AVURLAsset
                    {
                        let objAssest = GallaryAssets()
                        objAssest.objAssetsType = assetsType.videoType
                        objAssest.createdDate = (assest ).creationDate
                        objAssest.assetsDuration = (assest ).duration
                        objAssest.assetsURL = (asset as! AVURLAsset).url
                        objAssest.localizationStr = assest.localIdentifier
                        objAssest.locationInfo = LocationInfo()
                        if let location = (assest).location
                        {
                            objAssest.locationInfo.Latitude = "\(location.coordinate.latitude)"
                            objAssest.locationInfo.Longitude = "\(location.coordinate.longitude)"
                        }

                        self.media.add(objAssest)
                        isCompleted.pointee = true
                    }                    
                })
            }
        })
        completion(self.media)        
}
0 голосов
/ 03 января 2019

Вы удаляете контроллер на completion?Функция enumerateObject выполняется синхронно, если вы вызываете завершение до того, как оно прекращает выполнение, и объект fetchResult освобождается до того, как функция завершает свое выполнение, это может вызвать проблемы.

Попробуйте вызвать блок завершения после окончания перечисления, и если вы хотите получить только один результат, измените указатель isCompleted на true, это остановит выполнение перечисления:

func getVideo(withCompletionHandler completion:@escaping CompletionHandler)  {
        let fetchOptions = PHFetchOptions()
        let requestOptions = PHVideoRequestOptions()
        fetchOptions.sortDescriptors = [NSSortDescriptor(key:"creationDate", ascending: false)]
        let fetchResult: PHFetchResult = PHAsset.fetchAssets(with: PHAssetMediaType.video, options: fetchOptions)

        fetchResult.enumerateObjects ({ (assest, index, isCompleted) in
            if assest.sourceType != PHAssetSourceType.typeiTunesSynced{
                PHImageManager.default().requestAVAsset(forVideo: assest , options: requestOptions, resultHandler: { (asset : AVAsset?, video : AVAudioMix?, dic : [AnyHashable : Any]?) in
                    if let _ = asset as? AVURLAsset
                    {
                        let objAssest = GallaryAssets()
                        objAssest.objAssetsType = assetsType.videoType
                        objAssest.createdDate = (assest ).creationDate
                        objAssest.assetsDuration = (assest ).duration
                        objAssest.assetsURL = (asset as! AVURLAsset).url
                        objAssest.localizationStr = assest.localIdentifier
                        objAssest.locationInfo = LocationInfo()
                        if let location = (assest).location
                        {
                            objAssest.locationInfo.Latitude = "\(location.coordinate.latitude)"
                            objAssest.locationInfo.Longitude = "\(location.coordinate.longitude)"
                        }

                        self.media.add(objAssest)
                        isCompleted.pointee = true
                    }                    
                })
            }
        })
        completion(self.media)        
}
...