NSAssetLibrary适用于模拟器,但不适用于设备

时间:2015-10-14 12:05:15

标签: ios

我想从照片库中取出所有图像我写作。以下代码适用于模拟器,但不适用于设备。请帮帮我。谢谢。

-(void)getImagesFromDevice
{
    arrOfImages = [[NSMutableArray alloc]init];
    if (_isForAvtars)
    {

    }
    else
    {
        ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];//ALAssetsGroupAll
        NSLog(@"Authirization status:%ld",(long)[ALAssetsLibrary authorizationStatus]);
        [library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop)
         {
             [group setAssetsFilter:[ALAssetsFilter allPhotos]];
             if (group != nil)
             {
                 NSLog(@"Gruop is not nil");
                 NSLog(@"name %@",[group valueForProperty:ALAssetsGroupPropertyName]);
                 int a = (int)[group numberOfAssets];
                 NSLog(@"%d",a);
                 [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop)
                  {
                      if(result == nil)
                      {
                          return;
                      }
                      UIImage *img = [UIImage imageWithCGImage:[[result defaultRepresentation] fullScreenImage] scale:1.0 orientation:(UIImageOrientation)[[result valueForProperty:@"ALAssetPropertyOrientation"] intValue]];
                      if (img != nil)
                      {
                        NSLog(@"Add image");
                        [arrOfImages addObject:img];
                      }
                  }];
             }
             else
             {
                 NSLog(@"Gruop is nil");
                 [collectionviewPhotosVideos reloadData];
             }

         }
                             failureBlock: ^(NSError *error)
         {
             NSLog(@"No groups");
         }
         ];
    }

0 个答案:

没有答案