I. Get a single picture idea:
- 1. Use Uiimagepickercontroller to get pictures from your system's own app (Photos \ Camera)
- 2. Set up the agent, abide by the agent agreement
- 3. Ways to implement Proxies
didFinishPickingMediaWithInfo
- (void) getimagefromipc{1. Determine if the album can be openedif (![Uiimagepickercontroller issourcetypeavailable:Uiimagepickercontrollersourcetypephotolibrary])Return2. Create a picture selection controllerUiimagepickercontroller *IPC = [[Uiimagepickercontroller alloc] init];/** typedef ns_enum (Nsinteger, Uiimagepickercontrollersourcetype) {uiimagepickercontrollersourcetypephotolibrary,/ /album Uiimagepickercontrollersourcetypecamera,//Camera capture Uiimagepickercontrollersourcetypesavedphotosalbum//albums} */3. Set Open photo album type (show all albums) Ipc.sourcetype =Uiimagepickercontrollersourcetypephotolibrary;Ipc.sourcetype = Uiimagepickercontrollersourcetypesavedphotosalbum;CameraIpc.sourcetype = Uiimagepickercontrollersourcetypecamera;4. Set Proxy ipc.delegate =Self5.modal out of this controller [self presentviewcontroller:ipc animated:YES completion:< Span class= "hljs-literal" >nil];} #pragma mark--<uiimagepickercontrollerdelegate>--< Span class= "hljs-comment" >//action after getting the picture-(void) Imagepickercontroller: (uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: ( Nsdictionary<nsstring *,id> *) info{//destruction Controller [Picker Dismissviewcontrolleranimated:yes Completion:nil]; //set picture self.imageview.image = info[ uiimagepickercontrolleroriginalimage];}
Two. Get multiple picture ideas:
1. Get the original picture of all albums
- (void) getoriginalimages{Get all Custom albums phfetchresult<phassetcollection *> *assetcollections = [phassetcollectionFetchassetcollectionswithtype:phassetcollectiontypealbumsubtype:phassetcollectionsubtypealbumregular Options:nil]; //Traverse all the custom albums for (Phassetcollection *assetcollection in assetcollections) {[ Self Enumerateassetsinassetcollection:assetcollection Original:yes]; } //Get camera roll phassetcollection *cameraroll = [phassetcollection fetchassetcollectionswithtype: Phassetcollectiontypesmartalbum subtype:phassetcollectionsubtypesmartalbumuserlibrary Options:nil]. Lastobject; //traverse the camera roll to get a larger image [self enumerateassetsinassetcollection:cameraroll original:yes];}
2. Get thumbnails from all albums
- (void) getthumbnailimages{Get all Custom albums phfetchresult<phassetcollection *> *assetcollections = [phassetcollectionfetchassetcollectionswithtype:phassetcollectiontypealbum Subtype:phassetcollectionsubtypealbumregular options:nil]; //traverse all custom albums for (phassetcollection *assetcollection in assetcollections) {[Self enumerateassetsinassetcollection: Assetcollection original:no]; } //get camera roll phassetcollection *cameraroll = [phassetcollection Fetchassetcollectionswithtype:phassetcollectiontypesmartalbum subtype: Phassetcollectionsubtypesmartalbumuserlibrary options:nil].lastobject; [Self enumerateassetsinassetcollection:cameraroll original: NO];}
3. Traverse the album
/** * Traverse all pictures in the album *@param assetcollection Photo Album *@param original If you want the original */-(voidEnumerateassetsinassetcollection: (phassetcollection *) assetcollectionOriginal: (BOOL) original{NSLog (@"Photo Album name:%@", assetcollection.localizedtitle); Phimagerequestoptions *options = [[Phimagerequestoptions alloc] init];Synchronize to get the picture, will only return 1 pictures options.synchronous = YES;//Get all Phasset objects in a photo album Phfetchresult<phasset *> *assets = [Phasset fetchassetsinassetcollection: Assetcollection Options:nil]; For (Phasset *asset in assets) { //Do you want the original cgsize size = original? Cgsizemake (Asset.pixelwidth, asset.pixelheight): Cgsizezero; //Get pictures from asset [[Phimagemanager Defaultmanager] requestimageforasset:asset targetsize:size Contentmode:phimagecontentmodedefault options:options resulthandler:^ (UIImage * _nullable result, Nsdictionary * _nullable info) {NSLog (@"%@", result);}]; }}
Ios--app Custom Albums-get pictures from your custom albums