[iOS/Swift] 카메라로 동영상 촬영하기

2022. 5. 21. 21:39·iOS/Swift

먼저 영상 촬영과 저장을 위해 권한 설정을 해야한다.

import UIKit

class ViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }
    
    @IBAction func videoButton(_ sender: UIButton) {
        let camera = UIImagePickerController()
        camera.delegate = self
        camera.sourceType = .camera
        camera.mediaTypes = UIImagePickerController.availableMediaTypes(for: .camera) ?? []
        self.present(camera, animated: true, completion: nil)
    }
}

extension ViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
        
        //동영상 저장
        if let url = info[.mediaURL] as? URL, UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(url.path) {
                    UISaveVideoAtPathToSavedPhotosAlbum(url.path, self, #selector(savedVideo), nil)
                }
        picker.dismiss(animated: true, completion: nil)
    }
    
    @objc func savedVideo(_ videoPath: String, didFinishSavingWithError error: Error?, contextInfo: UnsafeMutableRawPointer?) {
                if let error = error {
                    print(error)
                    return
                }
                print("success")
            }
    
}

 

'iOS > Swift' 카테고리의 다른 글

[Swift] UI 구현 시 Storyboard와 Code Base 비교  (0) 2022.10.26
[iOS/Swift] Alamofire로 서버(FastAPI)에 동영상 업로드하기  (0) 2022.05.23
[iOS] Charts 라이브러리 설치방법 및 사용방법  (0) 2022.03.03
[iOS] Swift 라이브러리 typing animation  (0) 2021.08.23
[iOS/Swift] Xcode Simulator 키보드 안보일때  (0) 2021.05.08
'iOS/Swift' 카테고리의 다른 글
  • [Swift] UI 구현 시 Storyboard와 Code Base 비교
  • [iOS/Swift] Alamofire로 서버(FastAPI)에 동영상 업로드하기
  • [iOS] Charts 라이브러리 설치방법 및 사용방법
  • [iOS] Swift 라이브러리 typing animation
🥭Mango
🥭Mango
  • 🥭Mango
    AppleMango🥭
    🥭Mango
  • 전체
    오늘
    어제
    • 분류 전체보기
      • iOS
        • Swift
        • SwiftUI
        • RxSwift
      • Algorithm
        • C
        • Python
        • Swift
      • Computer Science
        • 컴퓨터 네트워크
        • OS
      • ...
      • 개발 타임캡슐
        • Python
        • Flutter
        • Android
        • Kotlin
        • Java
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    14503 파이썬
    6118
    파이썬 토마토
    Code Base
    스택
    Custom Map Marker
    코틀린
    typing animation
    토마토
    1613 역사
    코틀린 상속
    파이썬 정렬
    Apple Login
    1613 파이썬
    14503 로봇청소기
    Swift Hello World!
    백준 소수
    swiftUI tabview
    SwiftUI Apple Login
    IOS
    백준 토마토
    SwiftUI
    MapMarker
    swiftUI Gradients
    역사 파이썬
    파이썬 1459
    파이썬 14503
    파이썬
    1차원 뿌요뿌요
    파이썬 6118
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.2
🥭Mango
[iOS/Swift] 카메라로 동영상 촬영하기
상단으로

티스토리툴바