如何在后台接收iOS 4中的ALAssetsLibraryChangedNotification [英] How to receive ALAssetsLibraryChangedNotification in iOS 4 while in background

查看:179
本文介绍了如何在后台接收iOS 4中的ALAssetsLibraryChangedNotification的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我的iOS 4应用程序注册为ALAssetsLibraryChangedNotification的观察者,并在相机胶卷和照片库发生更改时接收通知。最明显的情况是:
1)我的应用程序使用ALAssetsLibrary枚举照片内容。
2)离开我的应用程序(进入后台)并启动相机应用程序。
3)拍照。
4)离开相机应用程序并返回我的应用程序。

I would like to register my iOS 4 app as an observer for ALAssetsLibraryChangedNotification and receive notifications when changes happen to the camera roll and photo library. The most obvious scenario is: 1) My app enumerates photo contents using ALAssetsLibrary. 2) Leave my app (goes into background) and launch the camera app. 3) Take a picture. 4) Leave the camera app and return to my app.

我希望当我的应用程序返回到前台时会传递ALAssetsLibraryChangedNotification,但这样做似乎并非如此。我已经尝试过addObserver的块和选择器形式。当我的应用在后台时,如何在添加或删除照片时收到通知?

I was hoping the ALAssetsLibraryChangedNotification would be delivered when my app returned to the foreground, but this does not seem to be the case. I've tried both the block and selector form of addObserver. How can I receive notifications when photos are added or removed while my app is in the background?

推荐答案

我通过走过来处理这个问题ALAssetsLibrary并使用 [[asset defaultRepresentation] url] 存储所有资产URL。当我的应用程序变为活动状态时,我再次浏览ALAssetsLibrary,检查我存储的列表。但请注意,iOS 4.x和iOS 5之间的URL格式会发生变化。

I handle this by walking through the ALAssetsLibrary and storing all the asset URLs using [[asset defaultRepresentation] url]. When my app becomes active I walk through the ALAssetsLibrary again, checking against my stored list. Note however that the URL format changes between iOS 4.x and iOS 5.

这篇关于如何在后台接收iOS 4中的ALAssetsLibraryChangedNotification的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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