Ios5 在库问题上,代码在4.3中工作,但在5.0中不工作
这是我的问题,如果我使用iOS 4.X访问这个类,代码工作正常。。。。但是,每当我尝试使用iOS 5.0访问它时,我都会得到组和资产的零值。什么是最好的方法让这个工作?我把整个班级都贴出来作为参考 hIos5 在库问题上,代码在4.3中工作,但在5.0中不工作,ios5,alassetslibrary,Ios5,Alassetslibrary,这是我的问题,如果我使用iOS 4.X访问这个类,代码工作正常。。。。但是,每当我尝试使用iOS 5.0访问它时,我都会得到组和资产的零值。什么是最好的方法让这个工作?我把整个班级都贴出来作为参考 h #导入 #进口 #导入“DejViewController.h” @班级活动、场地; @界面选择MediaViewController:DejViewController{ 事件*事件; 地点*地点; UITableView*表格视图; NSMutableArray*所选资产; NSMutable
#导入
#进口
#导入“DejViewController.h”
@班级活动、场地;
@界面选择MediaViewController:DejViewController{
事件*事件;
地点*地点;
UITableView*表格视图;
NSMutableArray*所选资产;
NSMutableArray*allMedia;
图书馆*图书馆;
NSMutableArray*资产组;
}
@属性(非原子,保留)事件*事件;
@财产(非原子,保留)场地*场地;
@属性(非原子,保留)IBUITableView*tableView;
@属性(非原子,保留)NSMutableArray*allMedia;
@属性(非原子,保留)NSMutableArray*AssetGroup;
-(iAction)continuePressed:(id)发送方;
@结束
m
#导入
#导入“SelectMediaViewController.h”
#导入“CapitalialMediaViewController.h”
#导入“MediaItem.h”
#导入“CLValueButton.h”
#导入“SelectMediaTableViewCell.h”
#定义kMediaGridSize 75
#定义KMEDIAGRIDP4
#定义kSelectImageTag 828
@界面选择MediaViewController(专用)
-(void)setContentForButton:(CLValueButton*)按钮与资产:(ALASET*)资产;
-(void)载荷数据;
@结束
@MediaViewController的实现
@综合活动、场地;
@综合桌面视图;
@综合所有媒体、资产组;
-(id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil{
self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
如果(自我){
//自定义初始化
selectedAssets=[[NSMutableArray alloc]init];
showNextButton=是;
}
回归自我;
}
-(无效)解除锁定{
[tableView发布];
[事件发布];
[场地释放];
[图书馆发行];
[所有媒体发布];
[所选资产发布];
[资产组发布];
[super dealoc];
}
-(无效)未收到记忆警告{
//如果视图没有superview,则释放该视图。
[超级记忆警告];
//释放所有未使用的缓存数据、图像等。
}
#pragma标记-视图生命周期
-(无效)viewDidLoad{
[超级视图下载];
NSLog(@“SelectMediaViewController-viewDidLoad”);
}
-(无效)视图卸载{
NSLog(@“SelectMediaViewController-viewDidUnload”);
[自设置表视图:无];
[超级视频下载];
}
-(无效)视图显示:(BOOL)动画{
NSLog(@“SelectMediaViewController-ViewDidDisplay”);
[超级视图显示:动画];
[self-setNavTitle:@“选择媒体”];
[自动加载数据];
[self.tableView重载数据];
float contentOffset=self.tableView.contentSize.height-self.tableView.frame.size.height;
如果(contentOffset<0)contentOffset=0;
[self.tableView setContentOffset:CGPointMake(0,contentOffset)动画:否];
}
-(无效)视图消失:(BOOL)已设置动画{
NSLog(@“SelectMediaViewController-ViewDidEnglish”);
self.allMedia=nil;
[所选资产删除所有对象];
[self.tableView重载数据];
}
-(void)加载数据{
NSMutableArray*tempArray=[[NSMutableArray]init];
库=[[AlassetLibrary alloc]init];
void(^assetEnumerator)(ALAsset*,NSUTEGER,BOOL*)=^(ALAsset*结果,NSUTEGER索引,BOOL*停止){
如果(结果!=NULL){
NSLog(@“见资产:%@”,结果);
[tempArray addObject:result];
NSLog(@“资产计数:%i”,tempArray.count);
}
否则{
NSLog(@“结果为零或列表结束”);
}
};
void(^assetGroupEnumerator)(AlasSetGroup*,BOOL*)=^(AlasSetGroup*组,BOOL*停止){
如果(组!=nil){
[组枚举AssetSungBlock:AssetUmerator];
NSLog(@“组:%@”,组);
}
否则{
NSLog(“无组或列表末尾”);
}
如果(停止){
self.allMedia=[NSMutableArray arrayWithCapacity:[tempArray count]];
self.allMedia=tempArray;
NSLog(@“加载的数据:%d&%d”,[tempArray count],[self.allMedia count]);
}
};
//AlassetLibrary*库=[[[AlassetLibrary alloc]init]autorelease];
[库枚举组类型:ALAssetsGroupSavedPhotos
usingBlock:assetGroupEnumerator
故障块:^(N错误*错误){
}];
//[图书馆发行];
}
-(布尔)应自动旋转指针面定向:(UIInterfaceOrientation)interfaceOrientation{
//对于支持的方向返回YES
返回(interfaceOrientation==UIInterfaceOrientationGraphic);
}
-(iAction)continuePressed:(id)发送方{
如果([selectedAssets count]>0){
CaptionalMediaViewController*captionVC=[[CaptionalMediaViewController alloc]initWithNibName:nil bundle:nil];
captionVC.event=self.event;
captionVC.vention=self.vention;
//创建媒体项
NSMutableArray*mediaItems=[NSMutableArray阵列容量:[所选资产计数]];
用于(所选资产集中的资产集*){
MediaItem*item=[[MediaItem alloc]init];
项目资产=资产;
NSDictionary*元数据=[[asset defaultRepresentation]元数据];
NSDictionary*gpsMeta=[元数据对象forkey:@“{GPS}]”;
如果(gpsMeta){
浮动纬度=[[gpsMeta objectForKey:@“纬度”]floatValue];
如果([[gpsMeta objectForKey:@“LatitudeRef”]isEqualToString:@“S”])纬度=纬度*-1;
浮点经度=[[gpsMeta objectForKey:@“经度”]floatValue];
如果([[gpsMeta objectForKey:@“LongitudeRef”]isEqualToString:@“W”])经度=经度*-1;
item.location=CLLocationCoordination2dMake(纬度、经度);
}
[mediaItems添加对象:项];
#import <UIKit/UIKit.h>
#import <AssetsLibrary/AssetsLibrary.h>
#import "DejViewController.h"
@class Event, Venue;
@interface SelectMediaViewController : DejViewController <UITableViewDelegate, UITableViewDataSource> {
Event *event;
Venue *venue;
UITableView *tableView;
NSMutableArray *selectedAssets;
NSMutableArray *allMedia;
ALAssetsLibrary *library;
NSMutableArray *assetGroups;
}
@property (nonatomic, retain) Event *event;
@property (nonatomic, retain) Venue *venue;
@property (nonatomic, retain) IBOutlet UITableView *tableView;
@property (nonatomic, retain) NSMutableArray *allMedia;
@property (nonatomic, retain) NSMutableArray *assetGroups;
- (IBAction)continuePressed:(id)sender;
@end
#import <ImageIO/ImageIO.h>
#import "SelectMediaViewController.h"
#import "CaptionAllMediaViewController.h"
#import "MediaItem.h"
#import "CLValueButton.h"
#import "SelectMediaTableViewCell.h"
#define kMediaGridSize 75
#define kMediaGridPadding 4
#define kSelectImageTag 828
@interface SelectMediaViewController(Private)
- (void)setContentForButton:(CLValueButton *)button withAsset:(ALAsset *)asset;
- (void)loadData;
@end
@implementation SelectMediaViewController
@synthesize event, venue;
@synthesize tableView;
@synthesize allMedia,assetGroups;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
selectedAssets = [[NSMutableArray alloc] init];
showNextButton = YES;
}
return self;
}
- (void)dealloc {
[tableView release];
[event release];
[venue release];
[library release];
[allMedia release];
[selectedAssets release];
[assetGroups release];
[super dealloc];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"SelectMediaViewController - viewDidLoad");
}
- (void)viewDidUnload {
NSLog(@"SelectMediaViewController - viewDidUnload");
[self setTableView:nil];
[super viewDidUnload];
}
- (void)viewDidAppear:(BOOL)animated {
NSLog(@"SelectMediaViewController - viewDidAppear");
[super viewDidAppear:animated];
[self setNavTitle:@"Select Media"];
[self loadData];
[self.tableView reloadData];
float contentOffset = self.tableView.contentSize.height - self.tableView.frame.size.height;
if (contentOffset < 0) contentOffset = 0;
[self.tableView setContentOffset:CGPointMake(0, contentOffset) animated:NO];
}
- (void)viewDidDisappear:(BOOL)animated {
NSLog(@"SelectMediaViewController - viewDidDisappear");
self.allMedia = nil;
[selectedAssets removeAllObjects];
[self.tableView reloadData];
}
- (void)loadData {
NSMutableArray *tempArray = [[NSMutableArray array] init];
library = [[ALAssetsLibrary alloc] init];
void (^assetEnumerator)(ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
if(result != NULL) {
NSLog(@"See Asset: %@", result);
[tempArray addObject:result];
NSLog(@"assets count: %i", tempArray.count);
}
else {
NSLog(@"result nil or end of list");
}
};
void (^assetGroupEnumerator)(ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop) {
if(group != nil) {
[group enumerateAssetsUsingBlock:assetEnumerator];
NSLog(@"group: %@",group);
}
else {
NSLog(@"group nil or end of list");
}
if (stop) {
self.allMedia = [NSMutableArray arrayWithCapacity:[tempArray count]];
self.allMedia = tempArray;
NSLog(@"Loaded data: %d & %d", [tempArray count], [self.allMedia count]);
}
};
//ALAssetsLibrary *library = [[[ALAssetsLibrary alloc] init] autorelease];
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
usingBlock:assetGroupEnumerator
failureBlock:^(NSError *error) {
}];
//[library release];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (IBAction)continuePressed:(id)sender {
if ([selectedAssets count] > 0) {
CaptionAllMediaViewController *captionVC = [[CaptionAllMediaViewController alloc] initWithNibName:nil bundle:nil];
captionVC.event = self.event;
captionVC.venue = self.venue;
// Create media items
NSMutableArray *mediaItems = [NSMutableArray arrayWithCapacity:[selectedAssets count]];
for (ALAsset *asset in selectedAssets) {
MediaItem *item = [[MediaItem alloc] init];
item.asset = asset;
NSDictionary *metadata = [[asset defaultRepresentation] metadata];
NSDictionary *gpsMeta = [metadata objectForKey:@"{GPS}"];
if (gpsMeta) {
float latitude = [[gpsMeta objectForKey:@"Latitude"] floatValue];
if ([[gpsMeta objectForKey:@"LatitudeRef"] isEqualToString:@"S"]) latitude = latitude * -1;
float longitude = [[gpsMeta objectForKey:@"Longitude"] floatValue];
if ([[gpsMeta objectForKey:@"LongitudeRef"] isEqualToString:@"W"]) longitude = longitude * -1;
item.location = CLLocationCoordinate2DMake(latitude, longitude);
}
[mediaItems addObject:item];
[item release];
}
captionVC.media = mediaItems;
[self.navigationController pushViewController:captionVC animated:YES];
[captionVC release];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Images Selected"
message:@"Please select at least one image to continue."
delegate:nil
cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
[alert release];
}
}
- (void)imagePressed:(CLValueButton *)sender {
BOOL currentlySelected = [selectedAssets containsObject:sender.valueObject];
UIImageView *imageView = (UIImageView *)[sender viewWithTag:kSelectImageTag];
if (!currentlySelected) {
[imageView setImage:[UIImage imageNamed:@"image-select-active.png"]];
[selectedAssets addObject:sender.valueObject];
} else {
[imageView setImage:[UIImage imageNamed:@"image-select.png"]];
[selectedAssets removeObject:sender.valueObject];
}
}
#pragma Table view methods
- (int)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"Getting table view count: %d", [self.allMedia count]);
if ([self.allMedia count] == 0) return 0;
return ceil([self.allMedia count] / 4.0);
}
- (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 83;
NSLog(@"return83");
}
- (UITableViewCell *)tableView:(UITableView *)_tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
SelectMediaTableViewCell *cell = (SelectMediaTableViewCell *)[_tableView dequeueReusableCellWithIdentifier:@"MEDIA_CELL"];
if (!cell) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"SelectMediaTableViewCell" owner:nil options:nil] objectAtIndex:0];
// wire up selectors
[cell.image1 addTarget:self action:@selector(imagePressed:) forControlEvents:UIControlEventTouchUpInside];
[cell.image2 addTarget:self action:@selector(imagePressed:) forControlEvents:UIControlEventTouchUpInside];
[cell.image3 addTarget:self action:@selector(imagePressed:) forControlEvents:UIControlEventTouchUpInside];
[cell.image4 addTarget:self action:@selector(imagePressed:) forControlEvents:UIControlEventTouchUpInside];
}
int startIndex = indexPath.row * 4;
for (int i = 0; i < 4; i++) {
ALAsset *thisAsset = (startIndex + i) < [self.allMedia count] ? [self.allMedia objectAtIndex:startIndex + i] : nil;
CLValueButton *button = nil;
switch (i) {
case 0:
button = cell.image1;
break;
case 1:
button = cell.image2;
break;
case 2:
button = cell.image3;
break;
case 3:
button = cell.image4;
break;
default:
break;
}
[self setContentForButton:button withAsset:thisAsset];
UIImageView *imageView = (UIImageView *)[button viewWithTag:kSelectImageTag];
// letse see if it's selected or not...
if ([selectedAssets containsObject:button.valueObject]) {
[imageView setImage:[UIImage imageNamed:@"image-select-active.png"]];
} else {
[imageView setImage:[UIImage imageNamed:@"image-select.png"]];
}
}
return cell;
}
- (void)setContentForButton:(CLValueButton *)button withAsset:(ALAsset *)asset {
button.hidden = asset == nil;
if (asset) {
CGImageRef image = [asset thumbnail];
[button setImage:[UIImage imageWithCGImage:image] forState:UIControlStateNormal];
}
[button setValueObject:asset];
}
#pragma -
@end