使用Photos框架删除相机胶卷资产 [英] deleting a camera roll asset using Photos framework

查看:143
本文介绍了使用Photos框架删除相机胶卷资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个测试应用程序,看看是否可以使用Photos框架删除iOS 8中的照片库资产。虽然我怀疑这是不可能的,但我发现文档不清楚,并且该网站上的帖子似乎表明它是可能的。例如,请参见此处

I'm writing a test application to see if it is possible to delete a "photo library" asset in iOS 8, using the Photos framework. Although I suspect it is not possible, I find the documentation to be unclear, and there are posts on this site that seem to indicate it is possible. See here for example.

在我的测试应用程序中,我从库中选择一项资产:

In my test app, I pick an asset from the library:

var picker = UIImagePickerController()
picker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
picker.mediaTypes = [kUTTypeMovie]

在委托回调中,我获得资产的NSURL,并将其放入数组:

In the delegate callback, I get the NSURL of the asset, and put it into an array:

let thePicked = info[UIImagePickerControllerMediaURL] as NSURL!
var videosToDelete: [NSURL] = [theURL]

这是我的第一部分我最不自信,在哪里获得PhotoLibrary,并执行更改请求以删除资产:

And here is the part I'm least confident about, where I get the PhotoLibrary, and do a change request to delete the asset:

PHPhotoLibrary.sharedPhotoLibrary().performChanges( {
    let assetToDelete = PHAsset.fetchAssetsWithALAssetURLs(videosToDelete, options: nil)
    PHAssetChangeRequest.deleteAssets(assetToDelete)
},
    completionHandler: { success, error in
        NSLog("Finished deleting asset. %@", (success ? "Success" : error))
})

完成处理程序成功返回,但永远不会删除资产。难道我做错了什么?或者我是否试图做一些本来不允许的事情,我没有收到正确的反馈意见?

The completion handler returns successfully, but the asset is never deleted. Am I doing something wrong? Or am I trying to do something inherently not allowed, and I'm not receiving the correct feedback for it?

推荐答案

让我确保我理解这个问题:

Let me make sure I understand the question:

1)您使用照片框架删除具有PHAssetChangeRequest.deleteAssets(assetToDelete)的资产

1) You use the photos framework to delete an asset with PHAssetChangeRequest.deleteAssets(assetToDelete)

2)你去了照片应用程序并查看最近删除的照片,但你没有在照片应用程序的垃圾桶中看到你刚刚删除的图像/资产。

2) you go to the Photos app and view the Recently Deleted photos, but you do not see the image/asset which you just deleted in the trash in the photos app.

如果您遇到这种情况,那是因为您删除了不属于用户相机胶卷的资产,但是来自其他设备的照片流中的PHAsst。删除这些资源时,它们不会被发送到垃圾箱,并且会以与普通照片不同的方式删除。我建议去照片应用程序并删除相同的资产 - 如果它是一个照片流资产,你会发现它永远不会进入垃圾桶。

If this is what you are experiencing, it is because you have deleted an asset that is not in the users 'camera roll' but is a PHAsst from the photostream from another device. When you delete these assets, they are not sent to the trash and are deleted differently than a normal photo. I would recommend going to the photos app and deleting the same asset--if it is a photostream asset, you will see that it never goes into the trash.

如果这不是您所面临的问题,请尝试提供更多详细信息。

If this isn't the issue you are facing, please try to provide more detail.

这篇关于使用Photos框架删除相机胶卷资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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