Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 |
Tags
- 앱 꺼졌을 때 푸시 데이터 저장
- Swift flutterview
- 안드로이드 에러
- swift sms
- 스위프트 푸시
- flutter 회전
- 안드로이드 FCM
- Flutter UIKitView MethodChannel
- 안드로이드 바로가기
- 스위프트
- swift 문자
- 안드로이드 앨범
- 스위프트 테이블 뷰 셀
- FlutterView MethodChannel
- native flutter view
- 안드로이드 숏컷
- 노티피케이션 익스텐션
- flutter rotate
- silent push
- 앱 백그라운드 푸시 데이터 저장
- 푸시 데이터 저장
- NotificationService Extension
- 스위프트 웹뷰
- swift autolayout
- Swift flutterviewcontroller
- Flutter NativeView
- 스위프트 UserDefaults
- 스위프트 앨범
- 스위프트 카메라
- 플러터 뷰 컨트롤러
Archives
- Today
- Total
Things take time
[SWIFT] 6일차 : 스위프트 기본 앱 본문
1. 비디오 플레이어
import UIKit
import AVKit
import AVFoundation
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func btnPlayInternalMovie(_ sender: UIButton) {
// 내부 파일 mp4
let filePath:String? = Bundle.main.path(forResource: "FastTyping", ofType: "mp4")
// 기기 내부 파일을 URL로 사용하려면 fileURLWithPath
let url = URL(fileURLWithPath: filePath!)
playVideo(url: url)
}
@IBAction func btnPlayExternalMovie(_ sender: UIButton) {
// 외부 파일 mp4
let url = URL(string: "https://dl.dropboxusercontent.com/s/e38auz050w2mvud/Fireworks.mp4")!
playVideo(url: url)
}
private func playVideo(url: URL) {
let playerController = AVPlayerViewController()
let player = AVPlayer(url: url )
playerController.player = player
self.present(playerController, animated: true) {
// () -> Void in
player.play()
// 영상의 5초부터 재생
// player.seek(to: CMTime(seconds: 5, preferredTimescale: 1))
}
}
2. 카메라
import UIKit
import MobileCoreServices
class ViewController: UIViewController,UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@IBOutlet weak var userImageView: UIImageView!
let imagePicker = UIImagePickerController()
var isImageSave = false // 사진 저장 여부 플래그
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
imagePicker.delegate = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// 촬영 혹은 앨범에서 선택완료 시 호출되는 메소드, .. use photo, use video버튼 누르면 자동 호출됨
@available(iOS 2.0, *)
public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]){
// 미디어 타입을 판별
if let mediaType = info[UIImagePickerControllerMediaType] as? String{
if mediaType == (kUTTypeImage as String){
// 선택한 사진의 원본을 가져옴 info 클릭해서 살펴볼 것
if let captureImage = info[UIImagePickerControllerOriginalImage] as? UIImage{
if isImageSave{
// 아이폰 앨범 저장 함수
UIImageWriteToSavedPhotosAlbum(captureImage, nil, nil, nil)
}
userImageView.image = captureImage
}
}
else if mediaType == (kUTTypeMovie as String){
if isImageSave {
if let videoURL = info[UIImagePickerControllerMediaURL] as? URL{
UISaveVideoAtPathToSavedPhotosAlbum(videoURL.relativePath, nil, nil, nil)
}
}
}
}
// 찍은 후, 혹은 앨범에서 사진 가져왔을때 카메라, 앨범은 꺼야 하므로
dismiss(animated: true, completion: nil)
}
@available(iOS 2.0, *)
public func imagePickerControllerDidCancel(_ picker: UIImagePickerController){
dismiss(animated: true, completion: nil)
}
func showAlert(title: String, message:String){
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
// 사진
@IBAction func captureImageClicked(_ sender: UIButton) {
// 디바이스가 카메라를 지원하는지
if UIImagePickerController.isSourceTypeAvailable(.camera) {
isImageSave = true
imagePicker.sourceType = .camera
// import MobileCoreServices
imagePicker.mediaTypes = [kUTTypeImage as String]
imagePicker.allowsEditing = true
present(imagePicker, animated: true, completion: nil)
} else {
showAlert(title: "카메라 지원 불가", message: "지원 불가")
}
}
// 사진 앨범
@IBAction func getImageAlbumClicked(_ sender: UIButton) {
if UIImagePickerController.isSourceTypeAvailable(.photoLibrary) {
isImageSave = false
imagePicker.sourceType = .photoLibrary
// import MobileCoreServices
imagePicker.mediaTypes = [kUTTypeMovie as String]
imagePicker.allowsEditing = false
present(imagePicker, animated: true, completion: nil)
} else {
showAlert(title: "앨범 지원 불가", message: "지원 불가")
}
}
// 비디오
@IBAction func captureVideoClicked(_ sender: UIButton) {
}
// 비디오 앨범
@IBAction func getVideoAlbumClicked(_ sender: UIButton) {
}
}
'iOS (교육)' 카테고리의 다른 글
| [SWIFT] 마지막 : 스위프트 기본 앱 (0) | 2017.05.13 |
|---|---|
| [SWIFT] 5일차 : 스위프트 기본 앱 (0) | 2017.04.15 |
| [SWIFT] 4일차 : 스위프트 기본 앱 (0) | 2017.04.08 |
| [SWIFT] 3일차 : 스위프트 기본 앱 (3) | 2017.04.01 |
| [SWIFT] 2일차 : 스위프트 기본 앱 (0) | 2017.03.25 |