Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用AssetLibrary从iPhone获取最后10张照片,ios 6.1.3上的Corelocation不推荐问题_Iphone_Ios_Core Location - Fatal编程技术网

使用AssetLibrary从iPhone获取最后10张照片,ios 6.1.3上的Corelocation不推荐问题

使用AssetLibrary从iPhone获取最后10张照片,ios 6.1.3上的Corelocation不推荐问题,iphone,ios,core-location,Iphone,Ios,Core Location,应用程序尝试从手机库访问照片。在ipod(5.1.something)、iPhone5(6.1.4)和所有模拟器上运行良好,但在iphone4s(6.1.3)上崩溃 所有检查(位置服务、照片库访问)都有w.r.t ios版本 控制台日志: :libMobileGestalt copySystemVersionDictionaryValue:无法从系统版本字典中查找ReleaseType 7月31日12:03:00 ABC's-iPhone awdd[296]:CoreLocation:CLCli

应用程序尝试从手机库访问照片。在ipod(5.1.something)、iPhone5(6.1.4)和所有模拟器上运行良好,但在iphone4s(6.1.3)上崩溃

所有检查(位置服务、照片库访问)都有w.r.t ios版本

控制台日志: :libMobileGestalt copySystemVersionDictionaryValue:无法从系统版本字典中查找ReleaseType

7月31日12:03:00 ABC's-iPhone awdd[296]:CoreLocation:CLClient已被弃用。很快就会过时

顺便说一句,下面的代码从照片库中获取最后10张照片。如果存在。调用此方法之前,请使用[CLLocationManager authorizationStatus]检查位置

- (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");
         }

         ] ;
    }
}
-(无效)获取最新照片
{
if(!oneTimeFetch)//阻止位置委托调用此方法。
{
oneTimeFetch=TRUE;
NSLog(@“获取最新照片”);
ReceinpicScroll.userInteractionEnabled=FALSE;
[self.recentPicsArr removeAllObjects];
如果([[[UIDevice currentDevice]systemVersion]doubleValue]>=6.0)
{
NSLog(@“IOS版本6.0及以上,需要检查照片访问”);
if([ALAssetsLibrary authorizationStatus]==AlaAuthorizationStatusAuthorized)
{
NSLog(@“允许照片访问”);
//只需在循环结束后执行代码。否则返回:)。
}
其他的
{
recentPicView.hidden=TRUE;
NSLog(@“请所有低照片访问”);
返回;
}
}
recentPicView.hidden=FALSE;
loadingAI.hidden=FALSE;
AlassetLibrary*al=[[AlassetLibrary alloc]init];
[al enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
使用block:^(设置组*组,布尔*停止)
{
[group SetAssetFilter:[AlasSetFilter allPhotos]];
[组EnumerateAssetSingBlock:^(ALAsset*资产,NSU整数索引,布尔*停止)
{
如果([group numberOfAssets]==0)
{
recentPicView.hidden=TRUE;
返回;
}
int startIdx=[group numberOfAssets]-10;//从最后10位开始
如果(资产)
{
//NSLog(@“资产索引:%d”,索引);
ALAssetRepresentation*rep=[asset defaultRepresentation];
CGImageRef imgRef=[rep fullResolutionImage];
如果(group.numberOfAssets>10)//最多10
{
如果(索引>=startIdx)
{
[self.recentPicsArr addObject:[UIImage imageWithCGImage:imgRef];
如果(索引==[组编号资产]-1)
{
[自我添加Picstov];
}
}
}

否则,如果(group.numberOfAssets因为AlAsset库要求启用位置服务,我不能忽略位置检查

由于iOS 6.0用户甚至可以阻止应用程序访问照片库,因此还需要资产库授权

我的解决方案是在以下委托中使用[self.locMgr stopUpdateLocation]:

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
    if(status == 1 || status == 2)
    { 
        NO_LOCATION_ALERT // User denied location. Don't start the activity for fetching photos
    }

    else if (status == kCLAuthorizationStatusAuthorized)
    {
       //Start fetching fotos
    }

    else
    {
        // This is for the first time, when user hasn't made any choice. So leave it blank.
    }

    [self.locMgr stopUpdatingLocation];  // SOLUTION
}

我没有使用任何不推荐的方法。我必须在plist中插入密钥吗?在链接中提到