不要在iOS上返回图片的名称

时间:2015-11-02 16:16:12

标签: ios objective-c uiimage uiimagepickercontroller delegation

我对委托UIImagePickerController有问题,所以我只能返回路径图片 - 没有关于图片名称的信息。

以下是代码:

-(void)imagePickerController:(UIImagePickerController *)picker
    didFinishPickingMediaWithInfo:(NSDictionary *)info
    editingInfo:(NSDictionary *)editingInfo
     {
    NSString *mediaType = info[UIImagePickerControllerMediaType];

    [self dismissViewControllerAnimated:YES completion:nil];

    if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
        UIImage *image = info[UIImagePickerControllerOriginalImage];
     _imageView.image = image;
        if (_newMedia)
            UIImageWriteToSavedPhotosAlbum(image,
                                           self,
                                           @selector(image:finishedSavingWithError:contextInfo:),
                                           nil);
        NSURL *imagePath = [editingInfo objectForKey:@"UIImagePickerControllerReferenceURL"];
        NSString *imageName = [imagePath lastPathComponent];
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *localFilePath = [documentsDirectory stringByAppendingPathComponent:imageName];
        NSLog(@"%@",localFilePath);
    }
    [self upload];
}

应用程序返回以下结果:

  

2015-11-02 17:05:01.512 AppTest [903:300310] localFilePath./var/mobile/Containers/Data/Application/39F58494-7645-4CA4-B96F-744257FE6AD3/Documents

整个应用程序在一个ViewController上运行。 请帮忙。

0 个答案:

没有答案