Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iOS的UImagePickerController中使用块获取文件名?_Ios_Objective C_Xcode_Block - Fatal编程技术网

如何在iOS的UImagePickerController中使用块获取文件名?

如何在iOS的UImagePickerController中使用块获取文件名?,ios,objective-c,xcode,block,Ios,Objective C,Xcode,Block,我正在从相机拍摄图像并将其保存到手机图库 保存图像后,我从图库中获取最后一张照片的名称 我已经写了下面的代码,但在我点击使用照片后,它会挂起拾取器。请告诉我这有什么问题 __block PHObjectPlaceholder *placeholder; PHPhotoLibrary *objPhoto = [PHPhotoLibrary sharedPhotoLibrary]; [objPhoto performChanges:^{ PHAssetChangeR

我正在从相机拍摄图像并将其保存到手机图库

保存图像后,我从图库中获取最后一张照片的名称

我已经写了下面的代码,但在我点击使用照片后,它会挂起拾取器。请告诉我这有什么问题

    __block PHObjectPlaceholder *placeholder;
    PHPhotoLibrary *objPhoto = [PHPhotoLibrary sharedPhotoLibrary];
    [objPhoto performChanges:^{

    PHAssetChangeRequest *assets = [PHAssetChangeRequest creationRequestForAssetFromImage:info[UIImagePickerControllerOriginalImage]];
    PHObjectPlaceholder *placeholder = assets.placeholderForCreatedAsset;

    } completionHandler:^(BOOL success, NSError * _Nullable error) {

      PHAsset *asset = nil;
      PHFetchOptions *fetchOptions = [[PHFetchOptions alloc] init];
      fetchOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]];
      PHFetchResult *fetchResult = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:fetchOptions];
      if (fetchResult != nil && fetchResult.count > 0) {
        // get last photo from Photos
        asset = [fetchResult lastObject];
      }

      if (asset) {
        // get photo info from this asset
        PHImageRequestOptions * imageRequestOptions = [[PHImageRequestOptions alloc] init];
        imageRequestOptions.synchronous = YES;
        [[PHImageManager defaultManager]
         requestImageDataForAsset:asset
         options:imageRequestOptions
         resultHandler:^(NSData *imageData, NSString *dataUTI,
                         UIImageOrientation orientation,
                         NSDictionary *info)
         {
           NSLog(@"info = %@", info);
           if ([info objectForKey:@"PHImageFileURLKey"]) {
             // path looks like this -
             // file:///var/mobile/Media/DCIM/###APPLE/IMG_####.JPG
             NSURL *path = [info objectForKey:@"PHImageFileURLKey"];
             refURL = path;
              NSString *strUrl  = refURL.absoluteString;
              NSArray *parts  = [strUrl componentsSeparatedByString:@"/"];
              orignalName = fileName = [parts lastObject];

              fileName = [[[Constant sharedInstance]getCommanFunctionInstance]generateFileNameWithExtension:filextension];
             [[AppSettings sharedAppSettings]setFileExtension:filextension];
             [[AppSettings sharedAppSettings]setFileName:fileName];
             [[AppSettings sharedAppSettings]setOrignalFileName:orignalName];

             [picker dismissViewControllerAnimated:YES completion:NULL];
             [picker release];
             [self validateImage:2];

           }                                            
         }];
      }

    }];

它正在崩溃吗?没有,但速度非常慢。当我按下“使用照片”按钮时,UIImagePickerController需要5-6秒来解除使用背景线程的尝试。确保[picker DismissViewControllerInitiated:YES completion:NULL];正在主线程中执行。添加NSLog([[NSThread currentThread]description]);在解聘之前,请检查哪一个线程正在执行这一行。您能在这里发布一些代码吗?