- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我一直在 iOS 6.x(目前特别是 6.0.1)中使用 ALAssetsLibraryChangedNotification,根据我的理解,我得到的结果与我期望在用户信息中收到的结果相反来自文档。
这是我的事件注册代码:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(assetsLibraryDidChange:) name:ALAssetsLibraryChangedNotification object:_library];
为了测试,我进入我的照片库,删除一些项目,添加一些项目。
这是我的处理程序。
- (void)assetsLibraryDidChange:(NSNotification *)note
{
NSDictionary* info = [note userInfo];
NSLog(@"assetsLibraryDidChange calling syncPhotoInfoFromAssets, userInfo %@", info);
// If the user information dictionary is nil, reload all assets and asset groups.
if(note.userInfo==nil) {
[self syncPhotoInfoFromAssets];
return;
}
// If the user information dictionary an empty dictionary, there is no need to reload assets and asset groups.
if(note.userInfo.count == 0) {
return;
}
// If the user information dictionary is not empty, reload the effected assets and asset groups. For the keys used, see “Notification Keys.”
NSSet *updatedAssets = [info objectForKey:ALAssetLibraryUpdatedAssetsKey];
NSSet *updatedAssetGroup = [info objectForKey:ALAssetLibraryUpdatedAssetGroupsKey];
NSSet *deletedAssetGroup = [info objectForKey:ALAssetLibraryDeletedAssetGroupsKey];
NSSet *insertedAssetGroup = [info objectForKey:ALAssetLibraryInsertedAssetGroupsKey];
NSLog(@"updated assets:%@", updatedAssets);
NSLog(@"updated asset group:%@", updatedAssetGroup);
NSLog(@"deleted asset group:%@", deletedAssetGroup);
NSLog(@"inserted asset group:%@", insertedAssetGroup);
//further processing here
}
我的输出:
ALAssetLibraryUpdatedAssetGroupsKey = "{(\n assets-library://group/?id=736B6346-6DA2-4E43-8830-9C263B2D29ED\n)}";
ALAssetLibraryUpdatedAssetsKey = "{(\n assets-library://asset/asset.JPG?id=A695208B-3546-4CCA-B539-B1D132A209B3&ext=JPG\n)}";
}
2013-01-06 22:50:45.738 Olesi[25468:3613] updated assets:{(
assets-library://asset/asset.JPG?id=A695208B-3546-4CCA-B539-B1D132A209B3&ext=JPG
)}
2013-01-06 22:50:45.738 Olesi[25468:3613] updated asset group:{(
assets-library://group/?id=736B6346-6DA2-4E43-8830-9C263B2D29ED
)}
2013-01-06 22:50:45.739 Olesi[25468:3613] deleted asset group:(null)
2013-01-06 22:51:06.658 Olesi[25468:3613] inserted asset group:(null)
删除并插入相册后,我希望在 ALAssetLibraryDeletedAssetGroupsKey 和 ALAssetLibraryInsertedAssetGroupsKey 中都收到数据,但在 ALAssetLibraryUpdatedAsset*Key 中都没有收到任何数据。有任何想法吗?我注意到甚至 Apple's sample code收听此通知的人甚至不使用 key ,而是重新枚举所有 Assets ,而不考虑特定 key (这听起来像是他们不信任通知信息)
最佳答案
如果您没有对要删除的组的引用,操作系统不会通知您。
我使用以下代码获得了正确的行为:
#import "ROBKViewController.h"
#import <AssetsLibrary/AssetsLibrary.h>
@interface ROBKViewController ()
@property (nonatomic, strong) ALAssetsLibrary *assetsLibrary;
@property (nonatomic, strong) ALAssetsGroup *currentAssetGroup;
- (void) handleAssetChangedNotifiation:(NSNotification *)notification;
@end
@implementation ROBKViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
_assetsLibrary = [ALAssetsLibrary new];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleAssetChangedNotifiation:) name:ALAssetsLibraryChangedNotification object:_assetsLibrary];
}
return self;
}
- (void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:ALAssetsLibraryChangedNotification object:nil];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self.assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
} failureBlock:^(NSError *error) {
}];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Notification handlers
- (void) handleAssetChangedNotifiation:(NSNotification *)notification
{
NSLog(@"notification: %@", notification);
if ([notification userInfo]) {
NSSet *insertedGroupURLs = [[notification userInfo] objectForKey:ALAssetLibraryInsertedAssetGroupsKey];
NSURL *assetURL = [insertedGroupURLs anyObject];
if (assetURL) {
[self.assetsLibrary groupForURL:assetURL resultBlock:^(ALAssetsGroup *group) {
self.currentAssetGroup = group;
} failureBlock:^(NSError *error) {
}];
}
}
}
@end
请注意,我只会收到分配给 self.currentAssetGroup 的组的通知。
关于objective-c - ios 6.0.1 ALAssetsLibraryChangedNotification,试图了解发送的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14191331/
我是 C++ 的新手,我在使用这段代码时遇到了问题: string output_date(int day, int month, int year){ string date; if
所以我这样做了 tar cvzf test.zip FP 为了创建目录 FP 的 zip 但是,它会列出 zip 中的目录 FP/ FP/php/ FP/php/pdf/ FP/php/docs/ F
我正在尝试在 Swift、Xcode 7.3(所以是 Swift 2.2)中创建一个通用类,但我似乎无法让它通过编译器: protocol Struct1Protocol { } struct Str
我的测试用例是这样的: class FooTest extends PHPUnit_Framework_TestCase { /** @covers MyClass::bar */ f
我正在尝试将brew install wine作为使electron-builder工作的一步。但是我所能得到的只是以下响应: ==> Installing dependencies for wine
我这样做: string[,] string1 = {{"one", "0"},{"Two", "5"},{"Three","1"}}; int b = 0; for(int i = 0; i <=
我正在尝试使用 SetWindowsHookEx 键盘 Hook Notepad.exe。 如您所见,工作线程正在将其 ASCII 代码(即 wParam)发送到指定的服务器。 UINT WINAPI
我正在尝试将 ListView 实现到我的 Fragment 中,但无论我尝试什么,我都会得到一个 NullPointerException。我检查对象是否为 null 并记录是否为 null,看起来
我尝试在一行中对齐两个 div。使用 float left 属性,一切顺利。但是当我在 div 中使用图像时,它开始产生问题。 所以这是我的示例代码:- Some headi
我目前正在使用此代码来获取图像的灰度图像表示并以 (512, 370, 1) 的格式表示它大批。 img_instance = cv2.imread(df.iloc[i][x_col]) / 255.
总结 我正在创建一个简单的应用程序,它允许用户选择一个包含顶级窗口的进程。用户首先键入 native DLL(而非托管 DLL)的路径。然后用户键入将在 Hook 过程中调用的方法的名称。该方法不得返
我是一名优秀的程序员,十分优秀!