开发者

iPhone: Not getting image path URL in didFinishPickingImage

I'm trying to get image path after picked from photo album using the below code. But it always gives image path as NULL/crash. What is the reason? Could someone help me?

    -(IBAction) LaunchAlbum :(id) sender
{
    // Updated - overlay code.
    MyAppDelegate *appDelegate = (MyAppDelegate *)[UIApplication sharedApplication].delegate;

    appDelegate.pickerController = [[UIImagePickerController alloc] init];
    appDelegate.pickerController.delegate = self;
    //appDelegate.pickerController.allowsEditing = NO;
    //appDelegate.pickerController.mediaTypes 开发者_JAVA技巧= [NSArray arrayWithObject:@"public.image"];

    appDelegate.pickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentModalViewController:appDelegate.pickerController animated:YES];
    [ appDelegate.pickerController release];
}
    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
imageUrl = [info valueForKey:@"UIImagePickerControllerReferenceURL"]; // CRASH
selectedImage = [imageUrl path];
    NSLog(@"selectedImage: %@", selectedImage);
}


You want:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
   NSURL* imageUrl = [info valueForKey:UIImagePickerControllerMediaURL];
   selectedImage = [imageUrl path];
   NSLog(@"selectedImage: %@", selectedImage);
}

There were several problems with what you were trying:

  1. imagePickerController:didFinishPickingImage:editingInfo: is deprecated
  2. Keys like UIImagePickerControllerMediaURL are constants that should be used as is, not quoted as strings.
  3. You probably want UIImagePickerControllerMediaURL instead of UIImagePickerControllerReferenceURL


From UIImagePickerController class reference:
editingInfo
A dictionary containing any relevant editing information. If editing is disabled, this parameter is nil. The keys for this dictionary are listed in “Editing information keys.”

Uncomment line appDelegate.pickerController.allowsEditing = NO;
and editInfo will not be nil.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜