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];}