应用程序尝试访问手机库中的照片。在 ipod (5.1.something) iPhone5 (6.1.4) 上运行良好,所有模拟器,但在 iPhone 4S(6.1.3) 上崩溃。
所有检查(位置服务、照片库访问)都在 ios 版本中。
控制台日志::libMobileGestalt copySystemVersionDictionaryValue:无法从系统版本字典中查找 ReleaseType
7 月 31 日 12:03:00 ABC's-iPhone awdd[296]:CoreLocation:CLClient 已弃用。很快就会过时。
顺便说一句,下面的代码从照片库中获取最后 10 张照片。如果存在。在调用此方法之前,使用 [CLLocationManager 授权状态] 检查位置。
- (void) getRecentPhotos
{
if(! oneTimeFetch) // to prevent location delegate from calling this method.
{
oneTimeFetch = TRUE;
NSLog(@"getRecentPhotos");
recenPicScroll.userInteractionEnabled = FALSE;
[self.recentPicsArr removeAllObjects];
if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 6.0)
{
NSLog(@"IOS version 6.0 and above, need to check for photo access");
if ([ALAssetsLibrary authorizationStatus] == ALAuthorizationStatusAuthorized)
{
NSLog(@"Photo ACCESS ALLOWED");
// just execute the code after loop ends. Else return :).
}
else
{
recentPicView.hidden = TRUE;
NSLog(@"PLEASE ALLLOW PHOTO ACCESS");
return;
}
}
recentPicView.hidden = FALSE;
loadingAI.hidden = FALSE;
ALAssetsLibrary *al = [[ALAssetsLibrary alloc] init];
[al enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
usingBlock:^(ALAssetsGroup *group, BOOL *stop)
{
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
[group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop)
{
if([group numberOfAssets] == 0)
{
recentPicView.hidden = TRUE;
return;
}
int startIdx = [group numberOfAssets]- 10; // Start from 10th last
if (asset)
{
//NSLog(@"asset Index: %d",index);
ALAssetRepresentation *rep = [asset defaultRepresentation];
CGImageRef imgRef = [rep fullResolutionImage];
if(group.numberOfAssets > 10) // upto 10
{
if(index >= startIdx)
{
[self.recentPicsArr addObject:[UIImage imageWithCGImage:imgRef]];
if(index == [group numberOfAssets] - 1)
{
[self addPicsToScrollV];
}
}
}
else if (group.numberOfAssets <= 10) // get less than 10 photos
{
[self.recentPicsArr addObject:[UIImage imageWithCGImage:imgRef]];
if(index + 1 == group.numberOfAssets)
{
[self addPicsToScrollV];
}
}
else
{
recentPicView.hidden = TRUE;
}
}
}];
}
failureBlock:^(NSError *error)
{
NSLog(@"You must allow the app to fetch your photos");
}
] ;
}
}