照片框架:与资产的连接中断或资产死亡 [英] Photos framework: Connection to assetsd was interrupted or assetsd died

查看:270
本文介绍了照片框架:与资产的连接中断或资产死亡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用此Swift库播放多个视频时,出现此错误( https://github. com/piemonte/player ).不知道它是否与该播放器,照片框架有关,还是与之相关.

I am getting this error when I am trying to play multiple videos using this swift library (https://github.com/piemonte/player). Not sure if it's related to that player, or to the Photos framework or what though.

发生的事情是,我有一个视图,其中将显示照片或视频.一切运行良好几次,直到播放了一些视频,然后弹出此消息,随后所有视频均无法播放,而在您所处的位置,您只会看到黑屏,然后出现内存使用错误.

What happens is, I have a view that will display either a photo or a video. Everything works fine a few times until a few videos have played and then this message will pop up, followed by all the videos not being able to play and in their place you just see a black screen, and then I get a memory usage error.

我正在使用一个名为SwipeView的库,下面是一些相关的代码,可能会有所帮助.

I am using a library called SwipeView and here is some relevant code which may be helpful.

func swipeView(swipeView: SwipeView!, viewForItemAtIndex index: Int, reusingView view: UIView!) -> UIView! {
    let asset: PHAsset = self.photosAsset[index] as PHAsset

    // Create options for retrieving image (Degrades quality if using .Fast)
    //        let imageOptions = PHImageRequestOptions()
    //        imageOptions.resizeMode = PHImageRequestOptionsResizeMode.Fast
    var imageView: UIImageView!

    let screenSize: CGSize = UIScreen.mainScreen().bounds.size
    let targetSize = CGSizeMake(screenSize.width, screenSize.height)

    var options = PHImageRequestOptions()
    options.resizeMode = PHImageRequestOptionsResizeMode.Exact
    options.synchronous = true

    if (asset.mediaType == PHAssetMediaType.Image) {
        PHImageManager.defaultManager().requestImageForAsset(asset, targetSize: targetSize, contentMode: .AspectFill, options: options, resultHandler: {(result, info) in
            if (result.size.width > 200) {
                imageView = UIImageView(image: result)
            }
        })

        return imageView
    } else if (asset.mediaType == PHAssetMediaType.Video) {
        self.currentlyPlaying = Player()


        PHImageManager.defaultManager().requestAVAssetForVideo(asset, options: nil, resultHandler: {result, audio, info in
            self.currentlyPlaying.delegate = self
            self.currentlyPlaying.playbackLoops = true
            self.addChildViewController(self.currentlyPlaying)
            self.currentlyPlaying.didMoveToParentViewController(self)

            var t = result as AVURLAsset
            var url = t.valueForKey("URL") as NSURL
            var urlString = url.absoluteString

            self.currentlyPlaying.path = urlString
        })

        return self.currentlyPlaying.view
    }
    return UIView()
}


    func swipeViewItemSize(swipeView: SwipeView!) -> CGSize {
    return self.swipeView.bounds.size;
}

func swipeView(swipeView: SwipeView!, didSelectItemAtIndex index: Int) {
    self.currentlyPlaying.playFromBeginning()
}

func swipeViewCurrentItemIndexDidChange(swipeView: SwipeView!) {
    self.currentlyPlaying.stop()
}

任何想法都会很棒.

推荐答案

我遇到了同样的"与资产连接中断或资产死亡"错误.

I had this same "Connection to assetsd was interrupted or assetsd died" error.

通常后跟内存警告. 我试图找到保留周期,但不是.

Usually followed by a memory warning. I tried to find retain cycles, but it wasn't it.

我的问题与已知事实有关,即任何 PHImageManager request...() resultHandler 块在调用时 not 主队列.

The problem for me had to do with the known fact that the resultHandler block of any PHImageManager request...() is not called on the main queue.

因此,我们不能直接在这些块中运行 UIView 代码,而不会在以后的应用程序生命中寻求麻烦.

So we cannot run UIView code directly within those blocks without asking for trouble later on in the app life.

要解决此问题,我们可以运行所有 UIView 代码,这些代码将在dispatch_async(dispatch_get_main_queue(), block)

To fix this we may for instance run all UIView code that would be executed within the scope of the resultHandler block inside a dispatch_async(dispatch_get_main_queue(), block)

我遇到了这个问题,因为我没有意识到我在应用程序的 resultHandler .s之一中调用的功能之一最终调用了某些 UIView 向下编码. 因此,我没有将该调用转发给主线程.

I was having this problem because I did not realize that one of the functions that I was calling within one of the resultHandler.s of my app did eventually call some UIView code down the line. And so I was not forwarding that call to the main thread.

希望这会有所帮助.

这篇关于照片框架:与资产的连接中断或资产死亡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆