- 我打開了,獲取僵尸對象,報的錯是
PUUIImageViewController retain
.
#pragma mark 修改頭像
- (void)avatarChangeOnClicked {
UIAlertController *alterController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *cameraAction = [UIAlertAction actionWithTitle:@"相機(jī)" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[self openCamera];
}];
UIAlertAction *albumAction = [UIAlertAction actionWithTitle:@"相冊" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[self openAlbum];
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}];
[alterController addAction:cameraAction];
[alterController addAction:albumAction];
[alterController addAction:cancelAction];
[self presentViewController:alterController animated:YES completion:nil];
}
- (void)openCamera {
[self openImagePickerController:UIImagePickerControllerSourceTypeCamera];
}
- (void)openAlbum {
// 如果想自己寫一個圖片選擇控制器椭蹄,得利用AssetsLibrary.framework坊萝,利用這個框架可以獲得手機(jī)上的所有相冊圖片
// UIImagePickerControllerSourceTypePhotoLibrary > UIImagePickerControllerSourceTypeSavedPhotosAlbum
[self openImagePickerController:UIImagePickerControllerSourceTypePhotoLibrary];
}
- (void)openImagePickerController:(UIImagePickerControllerSourceType)type {
if (![UIImagePickerController isSourceTypeAvailable:type]) return;
if (type == UIImagePickerControllerSourceTypeCamera) {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
if ([[AVCaptureDevice class] respondsToSelector:@selector(authorizationStatusForMediaType:)]) {
AVAuthorizationStatus authorizationStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if (authorizationStatus == AVAuthorizationStatusRestricted
|| authorizationStatus == AVAuthorizationStatusDenied) {
// 沒有權(quán)限
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil
message:@"沒有權(quán)限訪問相機(jī)宋下,您可以在 (設(shè)置 > 隱私 > 相機(jī))打開應(yīng)用訪問權(quán)限咙好,即可自定義圖片!"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
return;
}
}
}
}
UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
ipc.delegate = self;
ipc.allowsEditing = YES;
ipc.sourceType = type;
[self presentViewController:ipc animated:YES completion:nil];
}
#pragma mark - UIImagePickerControllerDelegate
/**
* 從UIImagePickerController選擇完圖片后就調(diào)用(拍照完畢或者選擇相冊圖片完畢)
*/
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
/*
==<PUUIAlbumListViewController: 0x1360eae00>
==<PUUIPhotosAlbumViewController: 0x135a3a000>
==<PUUIImageViewController: 0x137574330>
-[PUUIImageViewController retain]
*/
for (UIViewController *vc in [picker viewControllers]) {
Class class = NSClassFromString(@"PUUIImageViewController");
if ([vc isKindOfClass:class]) {
[self addChildViewController:vc];
}
}
[picker dismissViewControllerAnimated:YES completion:nil];
// info中就包含了選擇的圖片
UIImage *editImage = info[UIImagePickerControllerEditedImage];
self.avatarImageView.image = editImage;
// 上傳頭像
[self avatarChangeFromImage:editImage];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:nil];
}