(Swift) Uiimagepickercontroller Photo Selector Uiimagepickercontrollerreferenceurl Issues

Source: Internet
Author: User

Today, when locating a photo to choose a crash, the real-time test all iphone is working, and the ipad Air iOS8 is used to reproduce the problem. Let me summarize the bugs that I tested a day before I tested them.

Phenomenon: Click on profile picture, make photo selection, click Photos, app Flashback.

There are three ways to get pictures from IOS:

1. Directly call the camera to take pictures

2. Select from the album

3. Select from the Gallery

Uiimagepickercontrollersourcetypephotolibrary: Indicates that all photos are displayed

Uiimagepickercontrollersourcetypecamera: means picking photos from the camera

Uiimagepickercontrollersourcetypesavedphotosalbum: Indicates that only photos are selected from the album.

AllowEditing and allowsimageediting are set to Yes, which means that users are allowed to edit the picture, otherwise they are not allowed to edit.

The code is as follows:

1 @IBAction func Oncoverclick (sender:anyobject) {2         if(Uiimagepickercontroller.issourcetypeavailable (uiimagepickercontrollersourcetype.savedphotosalbum)) {3Self.coverchanging =true4 5Let Actionsheet = Uiactionsheet (Title:Localized.PHOTO_CHOSE_SOURCE,Delegate: Self, CancelButtonTitle:Localized.DIALOG_BUTTON_CANCEL, Destructivebuttontitle:nil, Otherbuttontitles: Localized.photo_from_camera, Localized.photo_from_photo)6 Actionsheet.showinview (Self.view)7         }8}
    //MARK:-Uiactionsheetdelegatefunc actionsheet (Actionsheet:uiactionsheet, Clickedbuttonatindex buttonindex:int) {flurry.logevent (/ c4>"Clicked change user avatar")        ifButtonindex = =1 {            if(Uiimagepickercontroller.issourcetypeavailable (Uiimagepickercontrollersourcetype.camera)) {Let picker =Uiimagepickercontroller () Picker.sourcetype=Uiimagepickercontrollersourcetype.camera picker.mediatypes=[Kuttypeimage] picker.Delegate= Selfifuiimagepickercontroller.iscameradeviceavailable (uiimagepickercontrollercameradevice.front) {Picke R.cameradevice=Uiimagepickercontrollercameradevice.front}Else{Picker.cameradevice=Uiimagepickercontrollercameradevice.rear} delay (0, {(), ()inchCurrentnav (). Presentviewcontroller (picker, animated:true, Completion:nil)}) }        } Else ifButtonindex = =2 {            if(Uiimagepickercontroller.issourcetypeavailable (uiimagepickercontrollersourcetype.savedphotosalbum)) { Let Picker=Uiimagepickercontroller () Picker.sourcetype=uiimagepickercontrollersourcetype.photolibrary picker.mediatypes=[Kuttypeimage] picker.allowsediting=falsePicker.Delegate=Self delay (0, {(), ()inchCurrentnav (). Presentviewcontroller (picker, animated:true, Completion:nil)}) }        }    }

The following is a bug code: for example, get the image of uiimagepickercontrolleroriginalimage in the info dictionary directly, and then use the frame assignment operation

1 func Imagepickercontroller (picker:uiimagepickercontroller, didfinishpickingmediawithinfo info: [NSOBJECT:ANYOB Ject]) {2Mbprogresshud.showhudaddedto (Self.view, animated:true, Needmask:false)3        Let img = info[uiimagepickercontrolleroriginalimage] as! UIImage4 var cropctrl:rskimagecropviewcontroller5         ifself.coverchanging {6Let width =min (Uiscreen.mainscreen (). Bounds.size.width, Uiscreen.mainscreen (). Bounds.size.height)7Cropctrl = Rskimagecropviewcontroller (image:img, CropMode:RSKImageCropMode.Custom, Cropsize:cgsizemake (width, width *Ten/ -))8}Else {9Cropctrl = Rskimagecropviewcontroller (image:img, CropMode:RSKImageCropMode.Circle, Cropsize:cgsizemake ( +, +))Ten         } OneCropctrl.Delegate= Self APicker.dismissviewcontrolleranimated (false, completion: {[unowned Self] () Voidinch -Self.presentviewcontroller (Cropctrl, animated:false, Completion:nil) -             }) the}

The code does not have a problem testing under the iphone. To test the crash directly on the ipad Air, I print out the info information as follows:

["uiimagepickercontrollerreferenceurl": Assets-library://asset/asset. Jpg?id=7136137d-8d6c-409d-a4a4-7520924f4ad4&ext=jpg, "Uiimagepickercontrollermediatype": Public.image]

Here's a look at the output of the normal print info information:

["uiimagepickercontrolleroriginalimage": <UIImage:0x188a1010> size {480, 640} Orientation 3 scale 1.000000, "Uiimagepickercontrollermediametadata": {

Dpiheight = 72;

Dpiwidth = 72;

Orientation = 6;

' {Exif} ' = {

Aperturevalue = "2.526068811667588";

Brightnessvalue = "4.991759637258034";

ColorSpace = 1;

datetimedigitized = "2015:10:15 15:32:42";

datetimeoriginal = "2015:10:15 15:32:42";

Exposurebiasvalue = 0;

Exposuremode = 0;

Exposureprogram = 2;

Exposuretime = "0.007518796992481203";

Fnumber = "2.4";

Flash = 32;

Focallenin35mmfilm = 35;

FocalLength = "1.85";

Isospeedratings = (

125

);

Lensmake = Apple;

Lensmodel = "IPad 2 front camera 1.85mm f/2.4";

Lensspecification = (

"1.85",

"1.85",

"2.4",

"2.4"

);

Meteringmode = 5;

Pixelxdimension = 640;

Pixelydimension = 480;

Scenetype = 1;

Sensingmethod = 2;

Shutterspeedvalue = "7.059855806488952";

subsectimedigitized = 674;

Subsectimeoriginal = 674;

whitebalance = 0;

};

' {makerapple} ' = {

1 = 2;

3 = {

Epoch = 0;

Flags = 1;

timescale = 1000000000;

value = 9309095690750;

};

4 = 1;

5 = 200;

6 = 224;

7 = 1;

8 = (

"0.006874616",

"-0.2249842",

"-0.9852664"

);

};

' {TIFF} ' = {

DateTime = "2015:10:15 15:32:42";

make = Apple;

Model = "IPad 2";

Software = "8.3";

XResolution = 72;

YResolution = 72;

};

}, "Uiimagepickercontrollermediatype": Public.image]

As can be seen from here, the direct value is a big problem.

So I do the following, judging the value, if the last imge still have no value, the box prompts the user to re-select the photo. The code is as follows:

Import Required:

Import Assetslibrary

1    //MARK:-Imagecrop2 func Imagepickercontroller (picker:uiimagepickercontroller, didfinishpickingmediawithinfo info: [String:anyobje CT]) {3Mbprogresshud.showhudaddedto (Self.view, animated:true, Needmask:false)4var img =UIImage ()5         ifInfo[uiimagepickercontrolleroriginalimage]! =Nil {6img = info[uiimagepickercontrolleroriginalimage] as!UIImage7 Self.showrskimagecropcontroller (picker, img:img)8}Else ifInfo[uiimagepickercontrollerreferenceurl]! =Nil {9             Let ImageUrl = Info[uiimagepickercontrollerreferenceurl] as! NSURL10 Let assetlibrary = Alassetslibrary () assetlibrary.assetforurl (IMAGEURL, Resultblock: {( Asset:alasset?) Void In12 if let imageref = asset?. Defaultrepresentation (). Fullscreenimage () {img = UIImage (cgimage:imageref as!                     CGIMAGEREF) Self.showrskimagecropcontroller (picker, img:img)} else {16 Let Imageactionsheet = Uiactionsheet (Title:Localized.PHOTO_CHOSE_ERROR, Delegate:nil, cancelbuttontitle:local Ized. Dialog_button_cancel, DestructiveButtonTitle:Localized.DIALOG_BUTTON_OK) Imageactionsheet.showinview (Picker.view)}19}) {(Error:nserror?), Void In20 let Imageact Ionsheet = Uiactionsheet (Title:Localized.PHOTO_CHOSE_ERROR, Delegate:nil, cancelButtonTitle:Localized.DIALOG_ Button_cancel, DestructivebuTtonTitle:Localized.DIALOG_BUTTON_OK) Imageactionsheet.showinview (Picker.view) 22}  at         } -     } -  - func Showrskimagecropcontroller (picker:uiimagepickercontroller,img:uiimage) { - var cropctrl:rskimagecropviewcontroller -         ifself.coverchanging { inLet width =min (Uiscreen.mainscreen (). Bounds.size.width, Uiscreen.mainscreen (). Bounds.size.height) -Cropctrl = Rskimagecropviewcontroller (image:img, CropMode:RSKImageCropMode.Custom, Cropsize:cgsizemake (width, width *Ten/ -)) to}Else { +Cropctrl = Rskimagecropviewcontroller (image:img, CropMode:RSKImageCropMode.Circle, Cropsize:cgsizemake ( +, +)) -         } theCropctrl.Delegate= Self *Picker.dismissviewcontrolleranimated (false, completion: {[unowned Self] () Voidinch $Self.presentviewcontroller (Cropctrl, animated:false, Completion:nil)Panax Notoginseng             }) -}

Refer to the following links:

Link 1:http://www.bubuko.com/infodetail-846042.html

Link 2:http://www.cnblogs.com/liangxing/archive/2013/01/05/2846136.html

Link 3:http://blog.csdn.net/mideveloper/article/details/12997453

(Swift) Uiimagepickercontroller Photo Selector Uiimagepickercontrollerreferenceurl Issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.