我正在尝试在 iPhone 的照片库中创建一个自定义相册,然后将我用相机拍摄的照片或从手机相机胶卷中选择的照片保存到该自定义相册。我可以成功创建相册,但照片没有保存在那里,而是保存到模拟器 Saved Photos 相册中......我不知道如何告诉我如何UIImageWriteToSavedPhotosAlbum
保存到我刚刚创建的新相册中addAssetsGroupAlbumWithName
。 ..
这是我到目前为止的代码 - 我已经剪掉了几个部分以保持我的代码示例简短......
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if([mediaType isEqualToString:(__bridge NSString *)kUTTypeImage])
{
// pull GPS information from photos metadata using ALAssetsLibrary
void (^ALAssetsLibraryAssetForURLResultBlock)(ALAsset *) = ^(ALAsset *asset)
{
// code snipped out
};
NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library assetForURL:assetURL
resultBlock:ALAssetsLibraryAssetForURLResultBlock
failureBlock:^(NSError *error)
{
// code snipped out
}];
// getimage from imagePicker and resize it to the max size of the iPhone screen
UIImage *originalImage = [info objectForKey:UIImagePickerControllerOriginalImage];
UIImage *resizedImage = [util_ createThumbnailForImage:originalImage thumbnailSize:[util_ determineIPhoneScreenSize]];
NSData *imageData = UIImagePNGRepresentation(resizedImage);
// code snipped out
// code snipped out
// code snipped out
// code snipped out
// code snipped out
// code snipped out
// create a new album called "My Apps Photos"
[library addAssetsGroupAlbumWithName:@"My Apps Photos"
resultBlock:^(ALAssetsGroup *group)
{
NSLog(@"in addAssetsGroupAlbumWithName resultBlock");
// save file to album
UIImageWriteToSavedPhotosAlbum(resizedImage, self, nil, nil);
}
failureBlock:^(NSError *error)
{
NSLog(@"in addAssetsGroupAlbumWithName failureBlock");
}
];
}
}
所以...就像我说的那样,它会创建新相册,但不会将照片保存在那里。我如何告诉它保存到新专辑中?也许我听起来不使用UIImageWriteToSavedPhotosAlbum
??
注意:我使用的是 Xcode 4.3.2、IOS 5.1 和 ARC