简体   繁体   中英

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

Good day, I am trying to implement the UIImagePickerController inside my selectFile function. (followed this tutorial in appcoda ) but code below is a bit tweaked now based on what i want

@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. My question is how do i return(or get) the url instead? 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.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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