来自PHAsset的NSURL [英] NSURL from PHAsset

查看:398
本文介绍了来自PHAsset的NSURL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将我们的应用程序转换为使用iOS8的照片框架,ALAsset框架显然是iOS8下的二等公民。

I'm converting our app over to use the Photos Framework of iOS8, the ALAsset framework is clearly a second class citizen under iOS8.

我有一个问题是我们的架构真的需要一个代表媒体在磁盘上的位置的NSURL。我们使用它将媒体上传到我们的服务器进行进一步处理。

I'm having a problem is that our architecture really wants an NSURL that represents the location of the media on "disk." We use this to upload the media to our servers for further processing.

使用ALAsset这很容易:

This was easy with ALAsset:

    ALAssetRepresentation *rep = [asset defaultRepresentation];
    self.originalVideo = rep.url;

但我只是没有在PHAsset中看到这种能力。我想我可以打电话:

But I'm just not seeing this ability in PHAsset. I guess I can call:

    imageManager.requestImageDataForAsset

然后将其写入文件系统中的临时点,但这看起来非常重量级且浪费,更不用说可能很慢。

and then write it out to a temp spot in the file system but that seems awfully heavyweight and wasteful, not to mention potentially slow.

有没有办法解决这个问题,或者我是否会重构我的应用程序以仅使用iOS7的NSURL和iOS8的其他方法?

Is there a way to get this or am I going to have refactor more of my app to only use NSURLs for iOS7 and some other method for iOS8?

推荐答案

如果您使用[ imageManager requestAVAssetForVideo ...],它将会返回 AVAsset 。 AVAsset实际上是一个 AVURLAsset ,所以如果你投了它,你可以访问它的 - url 属性。

If you use [imageManager requestAVAssetForVideo...], it'll return an AVAsset. That AVAsset is actually an AVURLAsset, so if you cast it, you can access it's -url property.

我不确定你是否可以创建一个新的资产,但它确实为你提供了位置。

I'm not sure if you can create a new asset out of this, but it does give you the location.

这篇关于来自PHAsset的NSURL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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