Organize UIImagePickerController and save the image to the album,

Source: Internet
Author: User

Organize UIImagePickerController and save the image to the album,

// This method is used on the ios8.0 system. Previously, you can use the code to create an album, manually delete it, and then use this library to create the newly deleted album, in this case, the method callback will not run the fail module, but the returned group is the cause of the nil crash. ALAssetsLibrary * assetsLibrary = [[ALAssetsLibrary alloc] init]; [assetsLibrary addAssetsGroupAlbumWithName: @ "iOSDevTip1" resultBlock: ^ (ALAssetsGroup * group12) {[groups addObject: group12];} failureBlock: nil];
// To solve the problem that an image album with the same name cannot be created through code in iOS8.0 or a later system [[PHPhotoLibrary sharedPhotoLibrary] Using mchanges: ^ {[PHAssetCollectionChangeRequest creationRequestForAssetCollectionWithTitle: @" completionHandler: ^ (BOOL success, NSError * error) {if (! Success) {NSLog (@ "--- error: % @", error. userInfo) ;}}];

Supplement

# Pragma mark ----- camera and album ----- // determine whether the device has a camera-(BOOL) isCameraAvailable {return [UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera];} // determine whether the front camera is available-(BOOL) isFrontCameraAvailable {return [UIImagePickerController isCameraDeviceAvailable: available];} // determine whether the rear camera is available-(BOOL) else {return [UIImagePickerController isCameraDeviceAvailable: supported];} // determines whether a certain multimedia type is supported: Photo Taking, video shooting-(BOOL) cameraSupportsMedia :( NSString *) paramMediaType sourceType :( required) paramSourceType {_ block BOOL result = NO; if ([paramMediaType length] = 0) {NSLog (@ "Media type is empty. "); return NO;} NSArray * availableMediaTypes = [UIImagePickerController restart: paramSourceType]; [availableMediaTypes enumerateObjectsUsingBlock: ^ (id obj, NSUInteger idx, BOOL * stop) {NSString * mediaType = (NSString *) obj; if ([mediaType isw.tostring: paramMediaType]) {result = YES; * stop = YES ;}}]; return result ;} // determine whether the camera supports recording-(BOOL) doesCameraSupportShootingVideos {return [self cameraSupportsMedia :( NSString *) kUTTypeMovie sourceType: Photo];} // determine whether the camera supports taking pictures-(BOOL) doesCameraSupportTakingPhotos {return [self cameraSupportsMedia :( NSString *) kUTTypeImage sourceType: Required] ;}# pragma mark ----- determines whether an album is available-(BOOL) isPhotoLibraryAvailable {return [UIImagePickerController isSourceTypeAvailable: available];} // You can select a video in the album-(BOOL) Resume {return [self cameraSupportsMedia :( NSString *) kUTTypeMovie sourceType: criteria];} // determines whether a photo can be selected in the album-(BOOL) canUserPickPhotosFromPhotoLibrary {return [self cameraSupportsMedia :( NSString *) kUTTypeImage sourceType: criteria];}

 

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.