Ios 代码突然停止工作-数组未填充

Ios 代码突然停止工作-数组未填充,ios,objective-c,photosframework,Ios,Objective C,Photosframework,这段代码在两周前运行良好…突然它停止了工作,我不知道为什么 以下是在viewDidLoad中调用的相关方法: if(!self.currentProject.assets){ [self fetchAssets]; [self fetchImagesFromAssets:nil]; }else { NSArray *assets = [NSKeyedUnarchiver unarchiveObjectWithData:self.curren

这段代码在两周前运行良好…突然它停止了工作,我不知道为什么

以下是在viewDidLoad中调用的相关方法:

if(!self.currentProject.assets){
        [self fetchAssets];
        [self fetchImagesFromAssets:nil];
    }else {
        NSArray *assets = [NSKeyedUnarchiver unarchiveObjectWithData:self.currentProject.assets];
        [self fetchImagesFromAssets:assets.mutableCopy];
    }
在viewDidLoad中调用:

if(!self.currentProject.assets){
        [self fetchAssets];
        [self fetchImagesFromAssets:nil];
    }else {
        NSArray *assets = [NSKeyedUnarchiver unarchiveObjectWithData:self.currentProject.assets];
        [self fetchImagesFromAssets:assets.mutableCopy];
    }
方法:

-(void) fetchAssets{
    self.assets = [[PHFetchResult alloc]init];
    NSLog(@"Album Name:%@",self.albumName);


    if (self.albumName.length > 0) {


        PHFetchResult *userAlbums = [PHAssetCollection fetchAssetCollectionsWithLocalIdentifiers:@[self.albumName]    options:nil];
        PHAssetCollection *collection = userAlbums[0];

        if (!_isProUser) {

            PHFetchOptions *onlyImagesOptions = [PHFetchOptions new];
            onlyImagesOptions.predicate = [NSPredicate predicateWithFormat:@"mediaType = %i", PHAssetMediaTypeImage];

            NSLog(@"Collection:%@", collection.localIdentifier);

            self.assets = [PHAsset fetchAssetsInAssetCollection:collection options:onlyImagesOptions];

        }
        else
        {
            self.assets = [PHAsset fetchAssetsInAssetCollection:collection options:nil];
        }

    }else{

        PHFetchOptions *options = [PHFetchOptions new];
        options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]];

        if(!_isProUser){
            options.predicate = [NSPredicate predicateWithFormat:@"mediaType = %i", PHAssetMediaTypeImage];
        }

        self.assets = [PHAsset fetchAssetsWithOptions:options];
    }
}

-(void) fetchImagesFromAssets:(NSMutableArray*)assets{

    if (assets == nil) {
        assets = [[NSMutableArray alloc]init];
        for (int i = (int)self.firstPhotoIndex; i < (int)self.lastPhotoIndex; i++) {
            [assets addObject:[self.assets objectAtIndex:i]];
        }
    }
    self.photosToVideofy = [[NSMutableArray alloc]init];
    NSLog(@"Assets:%lu",(unsigned long)assets.count);

    for (PHAsset *asset in assets)
    {
        if (!_isProUser) {
            [asset requestContentEditingInputWithOptions:nil
                                       completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
                                           NSURL *imageURL = contentEditingInput.fullSizeImageURL;
                                           NSLog(@"ImageURL:%@", imageURL);
                                           [self.photosToVideofy addObject:imageURL];
                                       }];


        }else{


            if (asset.mediaType == PHAssetMediaTypeVideo) {

                [self generateImagesFromAsset:asset];


            }else if (asset.mediaType == PHAssetMediaTypeImage){

                [asset requestContentEditingInputWithOptions:nil
                                           completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
                                               NSURL *imageURL = contentEditingInput.fullSizeImageURL;
                                               [self.photosToVideofy addObject:imageURL];
                                           NSLog(@"ImageURL:%@", imageURL);
                                           }];
            }
        }
    }

    assets = nil;

    NSLog(@"There are %lu photos to Videofy", (unsigned long)self.photosToVideofy.count);
}

-(void) generateImagesFromAsset:(PHAsset *)phAsset{
    NSLog(@"Generating images from video...");
    [[PHImageManager defaultManager]requestAVAssetForVideo:phAsset options:nil resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {

        AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc]initWithAsset:asset];
        generator.requestedTimeToleranceAfter =  kCMTimeZero;
        generator.requestedTimeToleranceBefore =  kCMTimeZero;
        generator.maximumSize = self.size;
        int j = 1;
        for (Float64 i = 0; i < CMTimeGetSeconds(asset.duration) *  _FPS ; i++){
            @autoreleasepool {
                CMTime time = CMTimeMake(i, _FPS);
                NSError *err;
                CMTime actualTime;
                CGImageRef image = [generator copyCGImageAtTime:time actualTime:&actualTime error:&err];
                UIImage *generatedImage = [[UIImage alloc] initWithCGImage:image];
                [self saveImage: generatedImage withIndex:self.generatedPhotoIndex]; // Saves the image on document directory and not memory
                CGImageRelease(image);
            }
            j++;
            self.generatedPhotoIndex++;
        }
    }];
}

-(void) saveImage:(UIImage*)image withIndex:(int)index{
    NSData *pngData = UIImagePNGRepresentation(image);
    NSString *path = [self documentsPathForFileName:[NSString stringWithFormat:@"image%i.png",index]];
    NSURL *url = [NSURL URLWithString:path];
    [pngData writeToFile:path atomically:YES]; //Write the file
    NSLog(@"URL:%@",url);
    [self.photosToVideofy addObject:url];

}

-(NSString *)documentsPathForFileName:(NSString *)name{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
    NSString *documentsPath = [paths objectAtIndex:0];

    return [documentsPath stringByAppendingPathComponent:name];
}
关于为什么会发生这种情况以及如何解决它,有什么想法吗?
在iPhone4S和iPad4上测试时,我会准确地检查url返回的内容。。。上面说有169项资产,但可能不是视频格式之类的?如果它们是视频格式,那么可能会有更深层次的含义issue@RyanOfCourse这些资源是直接从照片库中获取的Phaset对象图像和视频