1

应用程序尝试访问手机库中的照片。在 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");
         }

         ] ;
    }
}
4

1 回答 1

0

由于 AlAsset 库需要启用位置服务,所以我不能忽略位置检查。

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

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

- (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
}
于 2013-08-02T05:51:06.617 回答