2017-11-30 2 views
0

스마트 폴더 (즐겨 찾기, 스크린 샷 등 갤러리에서 모든 앨범 이름 목록을 가져 오려는 앱을 만들고 있습니다.이 앱은 ALAsset을 순서대로 사용한 오래된 앱입니다. 우리의 응용 프로그램에서 갤러리에 액세스 할 수 있습니다. ALAsset을 사용하여 갤러리에서 스마트 폴더에 액세스하는 방법

우리가 ALAssetLibrary를 사용하여뿐만 아니라 스마트 폴더에 액세스 할 수있는 어떤 방법이 있습니까?

답변

0

을이 코드가 도움이됩니다.

#import <AssetsLibrary/AssetsLibrary.h> 

    @property (nonatomic, strong) ALAssetsLibrary *_assetsLibrary; 

    - (ALAssetsLibrary *)defaultAssetsLibrary { 
     static dispatch_once_t pred = 0; 
     static ALAssetsLibrary *library = nil; 
     dispatch_once(&pred, ^{ 
      library = [[ALAssetsLibrary alloc] init]; 
     }); 
     return library; 
    } 

    -(void) getgalleryPic 
    { 
     if (self.photos == nil) { 
      self.photos = [[NSMutableArray alloc] init]; 
     }else 
     { 
      [self.photos removeAllObjects]; 
     } 

     PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus]; 

     if (status == PHAuthorizationStatusAuthorized) { 
      // Access has been granted. 
      NSMutableArray *collector = [[NSMutableArray alloc] initWithCapacity:0]; 
      ALAssetsLibrary *library = [self defaultAssetsLibrary]; 

      [library enumerateGroupsWithTypes:ALAssetsGroupAll 
            usingBlock:^(ALAssetsGroup *group, BOOL *stop) 
      { 
       [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop) 
        { 
         if (asset) { 
          [collector addObject:asset]; 
         }else 
         { 
          self.photos = [[[collector reverseObjectEnumerator] allObjects] mutableCopy]; 
          NSLog(@"photo lenght %lu",(unsigned long)[self.photos count]); 
          [_collectionVW reloadData]; 
         } 
        }]; 
      } 
           failureBlock:^(NSError *error) { NSLog(@"Boom!!!");} 
      ]; 
     } 

     else if (status == PHAuthorizationStatusDenied) { 
      // Access has been denied. 
     } 

     else if (status == PHAuthorizationStatusNotDetermined) { 

      // Access has not been determined. 
      [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) { 

       if (status == PHAuthorizationStatusAuthorized) { 
        // Access has been granted. 
        NSMutableArray *collector = [[NSMutableArray alloc] initWithCapacity:0]; 
        ALAssetsLibrary *library = [self defaultAssetsLibrary]; 

        [library enumerateGroupsWithTypes:ALAssetsGroupAll 
              usingBlock:^(ALAssetsGroup *group, BOOL *stop) 
        { 
         [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop) 
          { 
           if (asset) { 
            [collector addObject:asset]; 
           }else 
           { 
            self.photos = [[[collector reverseObjectEnumerator] allObjects] mutableCopy]; 
            NSLog(@"photo lenght %lu",(unsigned long)[self.photos count]); 
            [_collectionVW reloadData]; 
           } 
          }]; 
        } 
             failureBlock:^(NSError *error) { NSLog(@"Boom!!!");} 
        ]; 
       } 

       else { 
        // Access has been denied. 
       } 
      }]; 
     } else if (status == PHAuthorizationStatusRestricted) { 
      // Restricted access - normally won't happen. 
     } 


    } 
관련 문제