UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"照片选取" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; UIAlertAction *actionAlbum = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) { UIImagePickerController *Imagepicker = [[UIImagePickerController alloc] init]; Imagepicker.delegate =self; Imagepicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; [self presentViewController:Imagepicker animated:YES completion:nil]; } else{ [self.view makeToast:@"相册未发现" duration:CLEAR_TIME position:[NSValue valueWithCGPoint:CGPointMake([UIScreen mainScreen].bounds.size.width/2.f, [UIScreen mainScreen].bounds.size.height-160)]]; } }]; UIAlertAction *actionCamera = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { UIImagePickerController *picker =[[UIImagePickerController alloc] init]; picker.delegate =self;// picker.allowsEditing = YES; picker.sourceType = UIImagePickerControllerSourceTypeCamera; [self presentViewController:picker animated:YES completion:^{ }]; } else{ [self.view makeToast:@"摄像头未发现" duration:CLEAR_TIME position:[NSValue valueWithCGPoint:CGPointMake([UIScreen mainScreen].bounds.size.width/2.f, [UIScreen mainScreen].bounds.size.height-160)]]; } }]; [alertController addAction:actionCancel]; [alertController addAction:actionAlbum]; [alertController addAction:actionCamera]; [self presentViewController:alertController animated:YES completion:nil];