2016-04-19 7 views

Antwort

1

Versuchen Sie dies.

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

- (void)loadThumbnails 
{ 
    photosArray = [[NSMutableArray alloc] init]; 
    ALAssetsLibrary *assetLibrary = [self defaultAssetsLibrary]; 
    [assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) { 
     if (group) 
     { 
      if ([[group valueForProperty:ALAssetsGroupPropertyName] isEqualToString:@"Camera Roll"]) 
       [self getContentFrom:group withAssetFilter:[ALAssetsFilter allPhotos]]; 
     } 
    } failureBlock:^(NSError *error) { 
     NSLog(@"Error Description %@",[error description]); 
    }]; 
} 

- (void) getContentFrom:(ALAssetsGroup *) group withAssetFilter:(ALAssetsFilter *)filter 
{ 
    [group setAssetsFilter:filter]; 
    [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { 

     if (result) { 

      NSMutableDictionary *tempDictionary = [[NSMutableDictionary alloc] init]; 
      [tempDictionary setObject:result forKey:@"thumbnail"]; 
      [tempDictionary setObject:@"0" forKey:@"selected"]; 

      [photosArray addObject:tempDictionary]; 
     } else { 
      //Finish load Assets 
      photosArray = [[[photosArray reverseObjectEnumerator] allObjects] mutableCopy]; 
      [collectionViewMedia reloadData]; 
     } 
    }]; 
} 

Für Get Berechtigungen

+ (void)requestPermissions:(GalleryPermission)callback 
{ 
    PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus]; 
    switch (status) 
    { 
     case PHAuthorizationStatusAuthorized: 
      callback(YES); 
      break; 
     case PHAuthorizationStatusNotDetermined: 
     { 
      [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus authorizationStatus) 
      { 
       if (authorizationStatus == PHAuthorizationStatusAuthorized) 
        callback(YES); 
       else 
        callback(NO); 
      }]; 
      break; 
     } 
     default: 
      callback(NO); 
      break; 
    } 
} 
+0

ALAsset veraltet ..will es machbar sein? –

+0

Ja, aber nur für die Erlangung der Berechtigungen für die Fotogalerie. Der Weg, um Berechtigungen in der Antwort zu erhalten. (aktualisiert) – jose920405

Verwandte Themen