iOS----------調用系統照相機和相簿,
iOS 10 以後記得在plist裡面添加擷取拍照和相簿許可權,iOS 10 以後記得在plist裡面添加擷取拍照和相簿許可權,iOS 10 以後記得在plist裡面添加擷取拍照和相簿許可權,iOS 10 以後記得在plist裡面添加擷取拍照和相簿許可權,iOS 10 以後記得在plist裡面添加擷取拍照和相簿許可權,iOS 10 以後記得在plist裡面添加擷取拍照和相簿許可權,iOS 10 以後記得在plist裡面添加擷取拍照和相簿許可權,iOS 10 以後記得在plist裡面添加擷取拍照和相簿許可權,iOS 10 以後記得在plist裡面添加擷取拍照和相簿許可權,iOS 10 以後記得在plist裡面添加擷取拍照和相簿許可權,iOS 10 以後記得在plist裡面添加擷取拍照和相簿許可權,iOS 10 以後記得在plist裡面添加擷取拍照和相簿許可權,iOS 10 以後記得在plist裡面添加擷取拍照和相簿許可權,iOS 10 以後記得在plist裡面添加擷取拍照和相簿許可權。
/**
* 調用照相機
*/
- (void)openCamera
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES; //可編輯
//判斷是否可以開啟照相機
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
//網路攝影機
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:nil];
}
else
{
NSLog(@"沒有網路攝影機");
}
}
/**
* 開啟相簿
*/
-(void)openPhotoLibrary
{
// Supported orientations has no common orientation with the application, and [PUUIAlbumListViewController shouldAutorotate] is returning YES
// 進入相簿
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
imagePicker.allowsEditing = YES;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate = self;
[self presentViewController:imagePicker animated:YES completion:^{
NSLog(@"開啟相簿");
}];
}
else
{
NSLog(@"不能開啟相簿");
}
}
#pragma mark - UIImagePickerControllerDelegate
// 拍照完成回調
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(nullable NSDictionary<NSString *,id> *)editingInfo NS_DEPRECATED_IOS(2_0, 3_0)
{
NSLog(@"finish..");
if(picker.sourceType == UIImagePickerControllerSourceTypeCamera)
{
//圖片存入相簿
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
}
[self dismissViewControllerAnimated:YES completion:nil];
}
//進入拍攝頁面點擊取消按鈕
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:nil];
}