简体   繁体   English

如何从didFinishPickingMediaWithInfo返回NSString或NSUrl?

[英]how do i return an NSString or NSUrl from my didFinishPickingMediaWithInfo?

Good day, I am trying to implement the UIImagePickerController inside my selectFile function. 美好的一天,我正在尝试在我的selectFile函数中实现UIImagePickerController。 (followed this tutorial in appcoda ) but code below is a bit tweaked now based on what i want (在appcoda中遵循了本教程),但是下面的代码现在根据我想要的内容进行了一些调整

@implementation FileBrowser
-(void)selectFile{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = NO;
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentViewController:picker animated:YES completion:NULL];
}

#pragma mark - Image Picker Controller delegate methods

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    NSURL *refURL = [info valueForKey:UIImagePickerControllerReferenceURL];
    NSString *myURL = [refURL absoluteString]; //not in tutorial, I'm trying to grab the url/path of the image here, with an intention of returning it to "callFileBrowser"

    [picker dismissViewControllerAnimated:YES completion:NULL];
}

@end

Based on what i understood, my imagePickerController function is called when user selects an image. 根据我的理解,当用户选择图像时会调用我的imagePickerController函数。 My question is how do i return(or get) the url instead? 我的问题是我该如何返回(或获取)URL? I have a C function on the same file (but outside @implemetation), this function calls my selectFile and is supposed to return the url/path of what the user has chosen. 我在同一个文件上(但在@implemetation之外)有一个C函数,该函数调用我的selectFile并应返回用户选择的URL /路径。

char* callFileBrowser(){
[fileBrowser selectFile];
//return myURL here;
}

I hope i was able to explain everything properly. 我希望我能够正确地解释一切。 Any advice would greatly be appreciated. 任何建议将不胜感激。 thanks. 谢谢。

I don't think it is possible with the current design. 我认为当前的设计不可能。 callFileBrowser() is called to pick a image, then immediately it is required to return a value. 调用callFileBrowser()来拾取图像,然后立即需要它返回一个值。 We don't know when user will be done picking, I suggest you to post a notification in didFinishPickingMediaWithInfo when the url is ready to notify other object who needs it. 我们不知道用户将在何时完成选择,建议您在URL准备好通知需要它的其他对象时在didFinishPickingMediaWithInfo中发布通知。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM