ios - UIImage from UIImagePickerControllerSourceTypeCamera has no filename -
i using imagepickercontroller take picture both gallery , using device camera.
my problem if image selected gallery can "filename", if instead use camera acquire image "filename" equal "(null)".
i need "filename" because uploading picture server , .php file using requires filename uploaded image.
this code using
- (ibaction)addpicture:(id)sender { [[[uiactionsheet alloc] initwithtitle:@"select from:" delegate:self cancelbuttontitle:@"cancel" destructivebuttontitle:nil otherbuttontitles:@"gallery", @"camera", nil] showinview:self.view]; } - (void)actionsheet:(uiactionsheet *)actionsheet diddismisswithbuttonindex:(nsinteger)buttonindex { if (buttonindex == 0) { uiimagepickercontroller *picker = [[uiimagepickercontroller alloc] init]; picker.mediatypes = [[nsarray alloc] initwithobjects: (nsstring *)kuttypeimage, nil]; picker.delegate = self; picker.allowsediting = yes; picker.sourcetype = uiimagepickercontrollersourcetypephotolibrary; [self presentviewcontroller:picker animated:yes completion:null]; } else if (buttonindex == 1) { if (![uiimagepickercontroller issourcetypeavailable:uiimagepickercontrollersourcetypecamera]) { [[[uialertview alloc] initwithtitle:@"error" message:@"device has no camera." delegate:nil cancelbuttontitle:@"ok" otherbuttontitles: nil] show]; } else { uiimagepickercontroller *picker = [[uiimagepickercontroller alloc] init]; picker.mediatypes = [[nsarray alloc] initwithobjects: (nsstring *)kuttypeimage, nil]; picker.delegate = self; picker.allowsediting = yes; picker.sourcetype = uiimagepickercontrollersourcetypecamera; [self presentviewcontroller:picker animated:yes completion:null]; } } } - (void)imagepickercontroller:(uiimagepickercontroller *)picker didfinishpickingmediawithinfo:(nsdictionary *)info { uiimage *chosenimage = [info[uiimagepickercontrollereditedimage] imagewithrenderingmode:uiimagerenderingmodealwaysoriginal]; nsurl *imageurl = [info valueforkey:uiimagepickercontrollerreferenceurl]; [_selectedimageview setimage:chosenimage]; [picker dismissviewcontrolleranimated:yes completion:null]; alassetslibraryassetforurlresultblock resultblock = ^(alasset *myasset) { alassetrepresentation *representation = [myasset defaultrepresentation]; nsstring * filename = [representation filename]; selectedimagename = [nsstring stringwithformat:@"%@", filename]; nslog(@"%@", selectedimagename); }; alassetslibrary* assetslibrary = [[alassetslibrary alloc] init]; [assetslibrary assetforurl:imageurl resultblock:resultblock failureblock:nil]; }
this output get, image gallery:
img_3383.png
image camera:
(null)
anyone knows how "filename" image taken device camera?
Comments
Post a Comment