Compare commits
123 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
22f3e5320e | |
|
|
8f31fba846 | |
|
|
206bce0e94 | |
|
|
0267cc2664 | |
|
|
389ec550b3 | |
|
|
c8605d523a | |
|
|
6ce822261d | |
|
|
c0c55be070 | |
|
|
b23f2ccbc4 | |
|
|
004876d34e | |
|
|
dd34c6468e | |
|
|
33a0e2b1e4 | |
|
|
4639a1b661 | |
|
|
e598b71173 | |
|
|
a12d5e28e9 | |
|
|
68e289a755 | |
|
|
c875a0c03d | |
|
|
cf0e3759b4 | |
|
|
bfb31dd14b | |
|
|
c0a95613f1 | |
|
|
935e352460 | |
|
|
48450d49b6 | |
|
|
9aaec6ce96 | |
|
|
fdb9d48a41 | |
|
|
818e50d6ee | |
|
|
95d2830e8a | |
|
|
57a66bc7a9 | |
|
|
21c85f2e4d | |
|
|
1e6ff8f83a | |
|
|
ab500cbb13 | |
|
|
fb22e0478f | |
|
|
8fb105dec2 | |
|
|
6cf2f90fff | |
|
|
ff11c03832 | |
|
|
5a7e61851b | |
|
|
a581855d5f | |
|
|
e55c892898 | |
|
|
d85f5afc7c | |
|
|
2500e1b231 | |
|
|
6c4094cac6 | |
|
|
3df05957a5 | |
|
|
745a1df62f | |
|
|
8a818c1b96 | |
|
|
5ded48c44c | |
|
|
050f42bbd9 | |
|
|
a10dc6338c | |
|
|
ddffdac96e | |
|
|
334ce5b7a5 | |
|
|
48c92640c5 | |
|
|
f0340013cc | |
|
|
bf9add31dd | |
|
|
bc32517b69 | |
|
|
bb3c734e1a | |
|
|
9d16f88bc8 | |
|
|
2528209921 | |
|
|
ddd1d78d3e | |
|
|
783e47033d | |
|
|
5c85fdf276 | |
|
|
8427b18ef5 | |
|
|
0c0d7a0e0d | |
|
|
5b709a0174 | |
|
|
fb81adb869 | |
|
|
05e6f145e1 | |
|
|
db9c936300 | |
|
|
c3634300ce | |
|
|
151637eb32 | |
|
|
ee971a0a59 | |
|
|
68858dfb4b | |
|
|
0c0a90fe17 | |
|
|
3ca231ed25 | |
|
|
0507f72f11 | |
|
|
d666ab665b | |
|
|
1854061a8e | |
|
|
5a643853e5 | |
|
|
7cc218f385 | |
|
|
2618a8df95 | |
|
|
9e2249197f | |
|
|
898d7cb571 | |
|
|
d367d94bea | |
|
|
7b16276fbb | |
|
|
9b2d0cbf13 | |
|
|
2d6c7be2b1 | |
|
|
ad2cec3e80 | |
|
|
19074490ac | |
|
|
89105cd142 | |
|
|
8d1cb4afec | |
|
|
60e95a75fa | |
|
|
27194c99a9 | |
|
|
b6025c0faa | |
|
|
5664f6b038 | |
|
|
41bcc315fe | |
|
|
b0ebfcd94b | |
|
|
0ea8751297 | |
|
|
2a86fe5140 | |
|
|
5def8cb543 | |
|
|
302cae8b46 | |
|
|
9fc889a748 | |
|
|
cfc19af21d | |
|
|
43910bafc0 | |
|
|
eea00d4499 | |
|
|
258984c6de | |
|
|
2c52caa865 | |
|
|
ed5c1ce95c | |
|
|
118d1a66d3 | |
|
|
31f57cb03c | |
|
|
76c1e49db8 | |
|
|
c6ce889f58 | |
|
|
ff3b954ed8 | |
|
|
c97f7807f4 | |
|
|
ed8d3ff3f8 | |
|
|
dd52b8d186 | |
|
|
420d74b51d | |
|
|
aeb9daab30 | |
|
|
ebd0295a79 | |
|
|
e2108b5f5e | |
|
|
4c8f85142c | |
|
|
d0d3434d87 | |
|
|
7388c0cc87 | |
|
|
619fb174f6 | |
|
|
d09325e792 | |
|
|
229c66aa72 | |
|
|
99d6df9f8d | |
|
|
e98520ad37 |
|
|
@ -0,0 +1,43 @@
|
|||
# Xcode
|
||||
#
|
||||
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
|
||||
|
||||
## Build generated
|
||||
build/
|
||||
DerivedData
|
||||
|
||||
## Various settings
|
||||
*.pbxuser
|
||||
!default.pbxuser
|
||||
*.mode1v3
|
||||
!default.mode1v3
|
||||
*.mode2v3
|
||||
!default.mode2v3
|
||||
*.perspectivev3
|
||||
!default.perspectivev3
|
||||
xcuserdata
|
||||
|
||||
## Other
|
||||
*.xccheckout
|
||||
*.moved-aside
|
||||
*.xcuserstate
|
||||
*.xcscmblueprint
|
||||
|
||||
## Obj-C/Swift specific
|
||||
*.hmap
|
||||
*.ipa
|
||||
|
||||
# CocoaPods
|
||||
#
|
||||
# We recommend against adding the Pods directory to your .gitignore. However
|
||||
# you should judge for yourself, the pros and cons are mentioned at:
|
||||
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
|
||||
#
|
||||
# Pods/
|
||||
|
||||
# Carthage
|
||||
#
|
||||
# Add this line if you want to avoid checking in source code from Carthage dependencies.
|
||||
# Carthage/Checkouts
|
||||
|
||||
Carthage/Build
|
||||
|
|
@ -0,0 +1,214 @@
|
|||
# Change Log
|
||||
All notable changes to this project will be documented in this file.
|
||||
This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## [3.0.0](https://github.com/imaginary-cloud/CameraManager/tree/3.0.0) - 2016-09-16
|
||||
### Changed
|
||||
|
||||
- Syntax update for Swift 3.0.
|
||||
|
||||
## [2.2.4](https://github.com/imaginary-cloud/CameraManager/tree/2.2.4) - 2016-07-06
|
||||
### Added
|
||||
|
||||
- Add error checking.
|
||||
|
||||
### Changed
|
||||
|
||||
- Fixes completion typos and suggests renamed functions.
|
||||
|
||||
|
||||
## [2.2.3](https://github.com/imaginary-cloud/CameraManager/tree/2.2.3) - 2016-05-12
|
||||
### Changed
|
||||
|
||||
- Fixed zoom in StillImage Mode.
|
||||
|
||||
- Minor refactoring
|
||||
|
||||
## [2.2.2](https://github.com/imaginary-cloud/CameraManager/tree/2.2.2) - 2016-03-07
|
||||
### Added
|
||||
|
||||
- `CHANGELOG.md` file.
|
||||
|
||||
## [2.2.1](https://github.com/imaginary-cloud/CameraManager/tree/2.2.1) - 2016-03-02
|
||||
### Added
|
||||
|
||||
- Initial support for the Swift Package Manager.
|
||||
|
||||
## [2.2.0](https://github.com/imaginary-cloud/CameraManager/tree/2.2.0) - 2016-02-19
|
||||
### Added
|
||||
|
||||
- Zoom support.
|
||||
|
||||
### Changed
|
||||
|
||||
- Fixed spelling of `embeddingView`.
|
||||
|
||||
## [2.1.3](https://github.com/imaginary-cloud/CameraManager/tree/2.1.3) - 2016-01-08
|
||||
### Changed
|
||||
|
||||
- No sound in video with more than 10 seconds fixed.
|
||||
|
||||
- Fixed `NewCameraOutputMode` not passed during init.
|
||||
|
||||
## [2.1.2](https://github.com/imaginary-cloud/CameraManager/tree/2.1.2) - 2015-12-24
|
||||
### Added
|
||||
|
||||
- Property `cameraIsReady`.
|
||||
|
||||
- Completion block `addPreviewLayerToView`.
|
||||
|
||||
## [2.1.1](https://github.com/imaginary-cloud/CameraManager/tree/2.1.1) - 2015-12-11
|
||||
### Added
|
||||
|
||||
- Ability to disable responding to device orientation changes.
|
||||
|
||||
## [2.1.0](https://github.com/imaginary-cloud/CameraManager/tree/2.1) - 2015-11-20
|
||||
### Added
|
||||
|
||||
- Properties `recordedDuration` and `recordedFileSize`.
|
||||
|
||||
## [2.0.2](https://github.com/imaginary-cloud/CameraManager/tree/2.0.2) - 2015-11-17
|
||||
### Fixed
|
||||
|
||||
- iOS 9.0.1 bug.
|
||||
|
||||
## [2.0.1](https://github.com/imaginary-cloud/CameraManager/tree/2.0.1) - 2015-09-17
|
||||
### Changed
|
||||
|
||||
- Syntax updates.
|
||||
|
||||
## [2.0.0](https://github.com/imaginary-cloud/CameraManager/tree/2.0.0) - 2015-07-30
|
||||
### Changed
|
||||
|
||||
- Syntax update for Swift 2.0.
|
||||
|
||||
## [1.0.14](https://github.com/imaginary-cloud/CameraManager/tree/1.0.14) - 2015-07-17
|
||||
### Changed
|
||||
|
||||
- Small fixes.
|
||||
|
||||
## [1.0.13](https://github.com/imaginary-cloud/CameraManager/tree/1.0.13) - 2015-05-12
|
||||
### Added
|
||||
|
||||
- Support for installing via Carthage.
|
||||
|
||||
- Property `hasFlash`.
|
||||
|
||||
### Changed
|
||||
|
||||
- Syntax update for Swift 1.2.
|
||||
|
||||
## [1.0.12](https://github.com/imaginary-cloud/CameraManager/tree/1.0.12) - 2015-03-23
|
||||
### Added
|
||||
|
||||
- Incremental flash mode.
|
||||
|
||||
- Content localization.
|
||||
|
||||
### Changed
|
||||
|
||||
- Torch is set to correct state according to the current flash mode.
|
||||
|
||||
- `README.md` update.
|
||||
|
||||
## [1.0.11](https://github.com/imaginary-cloud/CameraManager/tree/1.0.11) - 2015-03-20
|
||||
### Added
|
||||
|
||||
- Property `showAccessPermissionPopupAutomatically`, to determine if you want the user to be asked about camera permissions automatically or manually.
|
||||
|
||||
- Error handling in capture completion blocks.
|
||||
|
||||
## [1.0.10](https://github.com/imaginary-cloud/CameraManager/tree/1.0.10) - 2015-03-19
|
||||
### Added
|
||||
|
||||
- Camera state returned when adding the preview layer.
|
||||
|
||||
### Changed
|
||||
|
||||
- `README.md` update.
|
||||
|
||||
## [1.0.9](https://github.com/imaginary-cloud/CameraManager/tree/1.0.9) - 2015-03-10
|
||||
### Changed
|
||||
|
||||
- CameraManager class made public.
|
||||
|
||||
## [1.0.8](https://github.com/imaginary-cloud/CameraManager/tree/1.0.8) - 2015-02-24
|
||||
### Fixed
|
||||
|
||||
- Wrong orientation when camera preview starts in landscape mode.
|
||||
|
||||
- Crash when trying to capture a still image.
|
||||
|
||||
- Orientation detection failure after stop and resume of a capture session.
|
||||
|
||||
- Bug which prevented from recording audio.
|
||||
|
||||
## [1.0.7](https://github.com/imaginary-cloud/CameraManager/tree/1.0.7) - 2014-10-30
|
||||
### Added
|
||||
|
||||
- Version compatible with XCode 6.1.
|
||||
|
||||
### Changed
|
||||
|
||||
- `README.md` update.
|
||||
|
||||
- Swift syntax updates to resolve compile errors.
|
||||
|
||||
## [1.0.6](https://github.com/imaginary-cloud/CameraManager/tree/1.0.6) - 2014-10-28
|
||||
### Added
|
||||
|
||||
- Check for valid capture session.
|
||||
|
||||
### Changed
|
||||
|
||||
- Fixed video orientation change.
|
||||
|
||||
## [1.0.5](https://github.com/imaginary-cloud/CameraManager/tree/1.0.5) - 2014-10-22
|
||||
### Changed
|
||||
|
||||
- Enhanced Camera lifecyle.
|
||||
|
||||
- Orientation observers only added if needed.
|
||||
|
||||
## [1.0.4](https://github.com/imaginary-cloud/CameraManager/tree/1.0.4) - 2014-10-16
|
||||
### Added
|
||||
|
||||
- Restart session.
|
||||
|
||||
### Changed
|
||||
|
||||
- `README.md` update.
|
||||
|
||||
## [1.0.3](https://github.com/imaginary-cloud/CameraManager/tree/1.0.3) - 2014-10-15
|
||||
### Added
|
||||
|
||||
- Property `writeFilesToPhoneLibrary` to conditionally write to user library.
|
||||
|
||||
### Changed
|
||||
|
||||
- Resources only recreated when needed.
|
||||
|
||||
- `README.md` update.
|
||||
|
||||
## [1.0.2](https://github.com/imaginary-cloud/CameraManager/tree/1.0.2) - 2014-10-15
|
||||
### Added
|
||||
|
||||
- `CameraManager.podspec` file.
|
||||
|
||||
## [1.0.1](https://github.com/imaginary-cloud/CameraManager/tree/1.0.1) - 2014-10-15
|
||||
### Changed
|
||||
|
||||
- Optional initializer for `addPreviewLayerToView`.
|
||||
|
||||
## [1.0.0](https://github.com/imaginary-cloud/CameraManager/tree/1.0.0) - 2014-10-15
|
||||
### Added
|
||||
|
||||
- Front and back camera selection.
|
||||
|
||||
- Support for multiple flash modes.
|
||||
|
||||
- Video recording, with or without mic.
|
||||
|
||||
- Support for multiple camera output quality.
|
||||
|
||||
- Preview layer follows interface orientation changes.
|
||||
|
|
@ -1,13 +1,13 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = "CameraManager"
|
||||
s.version = "1.0.4"
|
||||
s.summary = "This is a simple class to provide all the configurations you need to create custom camera view in your app. Just drag, drop and use."
|
||||
s.version = "3.0.0"
|
||||
s.summary = "This is a simple Swift class to provide all the configurations you need to create custom camera view in your app. Just drag, drop and use."
|
||||
s.requires_arc = true
|
||||
s.homepage = "https://github.com/imaginary-cloud/CameraManager"
|
||||
s.license = 'MIT'
|
||||
s.author = { "nelanelanela" => "nterlecka@imaginarycloud.com" }
|
||||
s.source = { :git => "https://github.com/imaginary-cloud/CameraManager.git", :tag => "1.0.4" }
|
||||
s.author = { "torrao" => "rtorrao@imaginarycloud.com" }
|
||||
s.source = { :git => "https://github.com/imaginary-cloud/CameraManager.git", :tag => "3.0.0" }
|
||||
s.social_media_url = 'http://www.imaginarycloud.com/'
|
||||
s.platform = :ios, '7.0'
|
||||
s.requires_arc = true
|
||||
s.platform = :ios, '8.0'
|
||||
s.source_files = 'camera/CameraManager.swift'
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
//
|
||||
// CameraManager.h
|
||||
// CameraManager
|
||||
//
|
||||
// Created by Lex Tang on 4/9/15.
|
||||
// Copyright (c) 2015 imaginaryCloud. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
//! Project version number for CameraManager.
|
||||
FOUNDATION_EXPORT double CameraManagerVersionNumber;
|
||||
|
||||
//! Project version string for CameraManager.
|
||||
FOUNDATION_EXPORT const unsigned char CameraManagerVersionString[];
|
||||
|
||||
// In this header, you should import all the public headers of your framework using statements like #import <CameraManager/PublicHeader.h>
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>$(CURRENT_PROJECT_VERSION)</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string></string>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
// Package.swift
|
||||
//
|
||||
// Copyright © 2016 ImaginaryCloud, imaginarycloud.com. This library is licensed under the MIT license.
|
||||
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "CameraManager",
|
||||
targets: [
|
||||
Target(name: "camera", dependencies: [.Target(name: "CameraManager")])
|
||||
]
|
||||
)
|
||||
3
Podfile
3
Podfile
|
|
@ -1,3 +0,0 @@
|
|||
platform :ios, '7.1'
|
||||
|
||||
pod 'CameraManager', :git => 'https://gist.github.com/2204678.git'
|
||||
161
README.md
161
README.md
|
|
@ -1,86 +1,177 @@
|
|||
|
||||
####Camera Manager
|
||||
# Camera Manager
|
||||
[](https://github.com/imaginary-cloud/CameraManager) [](https://github.com/Carthage/Carthage)
|
||||
|
||||
V1.0.4 (16-Oct-2014)
|
||||
|
||||
####About
|
||||
This is a simple swift class to provide all the configurations you need to create custom camera view in your app.
|
||||
This is a simple Swift class to provide all the configurations you need to create custom camera view in your app.
|
||||
It follows orientation change and updates UI accordingly, supports front and rear camera selection, pinch to zoom, different flash modes, inputs and outputs.
|
||||
Just drag, drop and use.
|
||||
|
||||
####Installation with CocoaPods
|
||||
Now it's compatible with latest Swift syntax if you're using any Swift version prior to 2.0 make sure to use one of the previously tagged releases.
|
||||
|
||||
The easiest way to install the CameraManager is with: [CocoaPods](http://cocoapods.org)
|
||||
## Installation with CocoaPods
|
||||
|
||||
## Podfile
|
||||
The easiest way to install the CameraManager is with: [CocoaPods](http://cocoapods.org)
|
||||
|
||||
### Podfile
|
||||
|
||||
If you want Swift 3.0 syntax use:
|
||||
|
||||
```ruby
|
||||
platform :ios, '7.0'
|
||||
pod 'CameraManager', '~> 1.0’
|
||||
use_frameworks!
|
||||
|
||||
pod 'CameraManager', '~> 3.0'
|
||||
```
|
||||
|
||||
####How to use
|
||||
To use it you just add the preview layer to your desired view
|
||||
If you want Swift 2.0 syntax use:
|
||||
|
||||
```ruby
|
||||
use_frameworks!
|
||||
|
||||
pod 'CameraManager', '~> 2.2'
|
||||
```
|
||||
|
||||
If you want Swift 1.2 syntax use:
|
||||
|
||||
```ruby
|
||||
use_frameworks!
|
||||
|
||||
pod 'CameraManager', '~> 1.0.14'
|
||||
```
|
||||
|
||||
## Installation with Swift Package Manager
|
||||
|
||||
The [Swift Package Manager](https://swift.org/package-manager/) is a tool for managing the distribution of Swift code.
|
||||
|
||||
Add `CameraManager` as a dependency in your `Package.swift` file:
|
||||
|
||||
```
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
dependencies: [
|
||||
.Package(url: "https://github.com/imaginary-cloud/CameraManager", majorVersion: 2, minor: 2)
|
||||
]
|
||||
)
|
||||
```
|
||||
|
||||
## Installation with Carthage
|
||||
|
||||
[Carthage](https://github.com/Carthage/Carthage) is another dependency management tool written in Swift.
|
||||
|
||||
Add the following line to your Cartfile:
|
||||
|
||||
If you want Swift 3.0 syntax use:
|
||||
|
||||
```
|
||||
github "imaginary-cloud/CameraManager" >= 3.0
|
||||
```
|
||||
|
||||
If you want Swift 2.0 syntax use:
|
||||
|
||||
```
|
||||
github "imaginary-cloud/CameraManager" >= 2.2
|
||||
```
|
||||
|
||||
If you want Swift 1.2 syntax use:
|
||||
|
||||
```
|
||||
github "imaginary-cloud/CameraManager" >= 1.0
|
||||
```
|
||||
|
||||
And run `carthage update` to build the dynamic framework.
|
||||
|
||||
## How to use
|
||||
To use it you just add the preview layer to your desired view, you'll get back the state of the camera if it's unavailable, ready or the user denied access to it. Have in mind that in order to retain the AVCaptureSession you will need to retain cameraManager instance somewhere, ex. as an instance constant.
|
||||
```swift
|
||||
CameraManager.sharedInstance.addPreeviewLayerToView(self.cameraView)
|
||||
let cameraManager = CameraManager()
|
||||
cameraManager.addPreviewLayerToView(self.cameraView)
|
||||
```
|
||||
You can set input device to front or back camera:
|
||||
```swift
|
||||
CameraManager.sharedInstance.cameraDevice = .Front
|
||||
CameraManager.sharedInstance.cameraDevice = .Back
|
||||
cameraManager.cameraDevice = .Front
|
||||
cameraManager.cameraDevice = .Back
|
||||
```
|
||||
|
||||
You can set output format to Image, video or video with audio:
|
||||
```swift
|
||||
CameraManager.sharedInstance.cameraOutputMode = .StillImage
|
||||
CameraManager.sharedInstance.cameraOutputMode = .VideoWithMic
|
||||
CameraManager.sharedInstance.cameraOutputMode = .VideoOnly
|
||||
cameraManager.cameraOutputMode = .StillImage
|
||||
cameraManager.cameraOutputMode = .VideoWithMic
|
||||
cameraManager.cameraOutputMode = .VideoOnly
|
||||
```
|
||||
|
||||
You can set the quality:
|
||||
```swift
|
||||
CameraManager.sharedInstance.cameraOutputQuality = .Low
|
||||
CameraManager.sharedInstance.cameraOutputQuality = .Medium
|
||||
CameraManager.sharedInstance.cameraOutputQuality = .High
|
||||
cameraManager.cameraOutputQuality = .Low
|
||||
cameraManager.cameraOutputQuality = .Medium
|
||||
cameraManager.cameraOutputQuality = .High
|
||||
```
|
||||
|
||||
And flash mode:
|
||||
And flash mode (it will also set corresponding torch mode for video shoot):
|
||||
```swift
|
||||
CameraManager.sharedInstance.flashMode = .Off
|
||||
CameraManager.sharedInstance.flashMode = .On
|
||||
CameraManager.sharedInstance.flashMode = .Auto
|
||||
cameraManager.flashMode = .Off
|
||||
cameraManager.flashMode = .On
|
||||
cameraManager.flashMode = .Auto
|
||||
```
|
||||
|
||||
To check if the device supports flash call:
|
||||
```swift
|
||||
cameraManager.hasFlash
|
||||
```
|
||||
|
||||
To change flash mode to the next available one you can use this handy function which will also return current value for you to update the UI accordingly:
|
||||
```swift
|
||||
cameraManager.changeFlashMode()
|
||||
```
|
||||
|
||||
|
||||
You can specify if you want to save the files to phone library:
|
||||
```swift
|
||||
CameraManager.sharedInstance.writeFilesToPhoneLibrary = true
|
||||
cameraManager.writeFilesToPhoneLibrary = true
|
||||
```
|
||||
|
||||
You can specify if you want the user to be asked about camera permissions automatically when you first try to use the camera or manually:
|
||||
```swift
|
||||
cameraManager.showAccessPermissionPopupAutomatically = false
|
||||
```
|
||||
|
||||
You can even setUp your custom block to handle error messages:
|
||||
It can be customized to be presented on the Window root view controller, for example.
|
||||
```swift
|
||||
CameraManager.sharedInstance.showErrorBlock = { (erTitle: String, erMessage: String) -> Void in
|
||||
UIAlertView(title: erTitle, message: erMessage, delegate: nil, cancelButtonTitle: "OK").show()
|
||||
cameraManager.showErrorBlock = { (erTitle: String, erMessage: String) -> Void in
|
||||
var alertController = UIAlertController(title: erTitle, message: erMessage, preferredStyle: .Alert)
|
||||
alertController.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: { (alertAction) -> Void in
|
||||
}))
|
||||
|
||||
let topController = UIApplication.sharedApplication().keyWindow?.rootViewController
|
||||
|
||||
if (topController != nil) {
|
||||
topController?.presentViewController(alertController, animated: true, completion: { () -> Void in
|
||||
//
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
To shoot image all you need to do is call:
|
||||
```swift
|
||||
CameraManager.sharedInstance.capturePictureWithCompletition({ (image) -> Void in
|
||||
cameraManager.capturePictureWithCompletion({ (image, error) -> Void in
|
||||
self.myImage = image
|
||||
})
|
||||
```
|
||||
|
||||
To record video you do:
|
||||
```swift
|
||||
CameraManager.sharedInstance.startRecordingVideo()
|
||||
CameraManager.sharedInstance.stopRecordingVideo({ (videoURL) -> Void in
|
||||
cameraManager.startRecordingVideo()
|
||||
cameraManager.stopVideoRecording({ (videoURL, error) -> Void in
|
||||
NSFileManager.defaultManager().copyItemAtURL(videoURL, toURL: self.myVideoURL, error: &error)
|
||||
})
|
||||
```
|
||||
|
||||
####Support
|
||||
## Support
|
||||
|
||||
Supports iOS 7 and above
|
||||
Supports iOS 8 and above. Xcode 7.0 is required to build the latest code written in Swift 2.0.
|
||||
|
||||
####License
|
||||
## License
|
||||
|
||||
Copyright © 2014 ImaginaryCloud, imaginarycloud.com. This plugin is licensed under the MIT license.
|
||||
Copyright © 2016 ImaginaryCloud, imaginarycloud.com. This library is licensed under the MIT license.
|
||||
|
|
|
|||
|
|
@ -12,9 +12,37 @@
|
|||
454C1F4C19E82E2500C81915 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 454C1F4A19E82E2500C81915 /* Main.storyboard */; };
|
||||
454C1F4E19E82E2500C81915 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 454C1F4D19E82E2500C81915 /* Images.xcassets */; };
|
||||
454C1F5119E82E2500C81915 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 454C1F4F19E82E2500C81915 /* LaunchScreen.xib */; };
|
||||
454C1F6719E8316A00C81915 /* CameraManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 454C1F6619E8316A00C81915 /* CameraManager.swift */; };
|
||||
45A23C181A656BDC00FB48F3 /* ImageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45A23C171A656BDC00FB48F3 /* ImageViewController.swift */; };
|
||||
D71DE8861AD677A7001E62F1 /* CameraManager.h in Headers */ = {isa = PBXBuildFile; fileRef = D71DE8851AD677A7001E62F1 /* CameraManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
D71DE8981AD677A8001E62F1 /* CameraManager.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D71DE8811AD677A7001E62F1 /* CameraManager.framework */; };
|
||||
D71DE8991AD677A8001E62F1 /* CameraManager.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = D71DE8811AD677A7001E62F1 /* CameraManager.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||
D71DE8A11AD677EF001E62F1 /* CameraManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 454C1F6619E8316A00C81915 /* CameraManager.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
D71DE8961AD677A8001E62F1 /* PBXContainerItemProxy */ = {
|
||||
isa = PBXContainerItemProxy;
|
||||
containerPortal = 454C1F3919E82E2500C81915 /* Project object */;
|
||||
proxyType = 1;
|
||||
remoteGlobalIDString = D71DE8801AD677A7001E62F1;
|
||||
remoteInfo = CameraManager;
|
||||
};
|
||||
/* End PBXContainerItemProxy section */
|
||||
|
||||
/* Begin PBXCopyFilesBuildPhase section */
|
||||
D71DE89D1AD677A8001E62F1 /* Embed Frameworks */ = {
|
||||
isa = PBXCopyFilesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
dstPath = "";
|
||||
dstSubfolderSpec = 10;
|
||||
files = (
|
||||
D71DE8991AD677A8001E62F1 /* CameraManager.framework in Embed Frameworks */,
|
||||
);
|
||||
name = "Embed Frameworks";
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXCopyFilesBuildPhase section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
454C1F4119E82E2500C81915 /* camera.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = camera.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
454C1F4519E82E2500C81915 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
|
|
@ -23,11 +51,23 @@
|
|||
454C1F4B19E82E2500C81915 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
|
||||
454C1F4D19E82E2500C81915 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
|
||||
454C1F5019E82E2500C81915 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = "<group>"; };
|
||||
454C1F6619E8316A00C81915 /* CameraManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CameraManager.swift; sourceTree = "<group>"; };
|
||||
454C1F6619E8316A00C81915 /* CameraManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = CameraManager.swift; path = ../camera/CameraManager.swift; sourceTree = "<group>"; };
|
||||
45A23C171A656BDC00FB48F3 /* ImageViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageViewController.swift; sourceTree = "<group>"; };
|
||||
D71DE8811AD677A7001E62F1 /* CameraManager.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CameraManager.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
D71DE8841AD677A7001E62F1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
D71DE8851AD677A7001E62F1 /* CameraManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CameraManager.h; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
454C1F3E19E82E2500C81915 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
D71DE8981AD677A8001E62F1 /* CameraManager.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
D71DE87D1AD677A7001E62F1 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
|
|
@ -41,6 +81,7 @@
|
|||
isa = PBXGroup;
|
||||
children = (
|
||||
454C1F4319E82E2500C81915 /* camera */,
|
||||
D71DE8821AD677A7001E62F1 /* CameraManager */,
|
||||
454C1F4219E82E2500C81915 /* Products */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -49,6 +90,7 @@
|
|||
isa = PBXGroup;
|
||||
children = (
|
||||
454C1F4119E82E2500C81915 /* camera.app */,
|
||||
D71DE8811AD677A7001E62F1 /* CameraManager.framework */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -57,8 +99,7 @@
|
|||
isa = PBXGroup;
|
||||
children = (
|
||||
454C1F4619E82E2500C81915 /* AppDelegate.swift */,
|
||||
454C1F6619E8316A00C81915 /* CameraManager.swift */,
|
||||
454C1F4819E82E2500C81915 /* ViewController.swift */,
|
||||
45A23C191A656BE600FB48F3 /* Example app view controllers */,
|
||||
454C1F4A19E82E2500C81915 /* Main.storyboard */,
|
||||
454C1F4D19E82E2500C81915 /* Images.xcassets */,
|
||||
454C1F4F19E82E2500C81915 /* LaunchScreen.xib */,
|
||||
|
|
@ -75,8 +116,46 @@
|
|||
name = "Supporting Files";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
45A23C191A656BE600FB48F3 /* Example app view controllers */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
454C1F4819E82E2500C81915 /* ViewController.swift */,
|
||||
45A23C171A656BDC00FB48F3 /* ImageViewController.swift */,
|
||||
);
|
||||
name = "Example app view controllers";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
D71DE8821AD677A7001E62F1 /* CameraManager */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D71DE8851AD677A7001E62F1 /* CameraManager.h */,
|
||||
454C1F6619E8316A00C81915 /* CameraManager.swift */,
|
||||
D71DE8831AD677A7001E62F1 /* Supporting Files */,
|
||||
);
|
||||
path = CameraManager;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
D71DE8831AD677A7001E62F1 /* Supporting Files */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D71DE8841AD677A7001E62F1 /* Info.plist */,
|
||||
);
|
||||
name = "Supporting Files";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXHeadersBuildPhase section */
|
||||
D71DE87E1AD677A7001E62F1 /* Headers */ = {
|
||||
isa = PBXHeadersBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
D71DE8861AD677A7001E62F1 /* CameraManager.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXHeadersBuildPhase section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
454C1F4019E82E2500C81915 /* camera */ = {
|
||||
isa = PBXNativeTarget;
|
||||
|
|
@ -85,27 +164,54 @@
|
|||
454C1F3D19E82E2500C81915 /* Sources */,
|
||||
454C1F3E19E82E2500C81915 /* Frameworks */,
|
||||
454C1F3F19E82E2500C81915 /* Resources */,
|
||||
D71DE89D1AD677A8001E62F1 /* Embed Frameworks */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
D71DE8971AD677A8001E62F1 /* PBXTargetDependency */,
|
||||
);
|
||||
name = camera;
|
||||
productName = camera;
|
||||
productReference = 454C1F4119E82E2500C81915 /* camera.app */;
|
||||
productType = "com.apple.product-type.application";
|
||||
};
|
||||
D71DE8801AD677A7001E62F1 /* CameraManager */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = D71DE89A1AD677A8001E62F1 /* Build configuration list for PBXNativeTarget "CameraManager" */;
|
||||
buildPhases = (
|
||||
D71DE87C1AD677A7001E62F1 /* Sources */,
|
||||
D71DE87D1AD677A7001E62F1 /* Frameworks */,
|
||||
D71DE87E1AD677A7001E62F1 /* Headers */,
|
||||
D71DE87F1AD677A7001E62F1 /* Resources */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
);
|
||||
name = CameraManager;
|
||||
productName = CameraManager;
|
||||
productReference = D71DE8811AD677A7001E62F1 /* CameraManager.framework */;
|
||||
productType = "com.apple.product-type.framework";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
|
||||
/* Begin PBXProject section */
|
||||
454C1F3919E82E2500C81915 /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastUpgradeCheck = 0600;
|
||||
LastSwiftUpdateCheck = 0700;
|
||||
LastUpgradeCheck = 0800;
|
||||
ORGANIZATIONNAME = imaginaryCloud;
|
||||
TargetAttributes = {
|
||||
454C1F4019E82E2500C81915 = {
|
||||
CreatedOnToolsVersion = 6.0.1;
|
||||
DevelopmentTeam = QM7HJTY23M;
|
||||
LastSwiftMigration = 0800;
|
||||
};
|
||||
D71DE8801AD677A7001E62F1 = {
|
||||
CreatedOnToolsVersion = 6.3;
|
||||
LastSwiftMigration = 0800;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
@ -123,6 +229,7 @@
|
|||
projectRoot = "";
|
||||
targets = (
|
||||
454C1F4019E82E2500C81915 /* camera */,
|
||||
D71DE8801AD677A7001E62F1 /* CameraManager */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
|
|
@ -138,6 +245,13 @@
|
|||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
D71DE87F1AD677A7001E62F1 /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXResourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
|
|
@ -146,13 +260,29 @@
|
|||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
454C1F4919E82E2500C81915 /* ViewController.swift in Sources */,
|
||||
454C1F6719E8316A00C81915 /* CameraManager.swift in Sources */,
|
||||
45A23C181A656BDC00FB48F3 /* ImageViewController.swift in Sources */,
|
||||
454C1F4719E82E2500C81915 /* AppDelegate.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
D71DE87C1AD677A7001E62F1 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
D71DE8A11AD677EF001E62F1 /* CameraManager.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXTargetDependency section */
|
||||
D71DE8971AD677A8001E62F1 /* PBXTargetDependency */ = {
|
||||
isa = PBXTargetDependency;
|
||||
target = D71DE8801AD677A7001E62F1 /* CameraManager */;
|
||||
targetProxy = D71DE8961AD677A8001E62F1 /* PBXContainerItemProxy */;
|
||||
};
|
||||
/* End PBXTargetDependency section */
|
||||
|
||||
/* Begin PBXVariantGroup section */
|
||||
454C1F4A19E82E2500C81915 /* Main.storyboard */ = {
|
||||
isa = PBXVariantGroup;
|
||||
|
|
@ -186,16 +316,20 @@
|
|||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
CODE_SIGN_IDENTITY = "iPhone Developer: Luis Diniz (HUX544ZBSL)";
|
||||
"CODE_SIGN_ENTITLEMENTS[sdk=iphoneos*]" = "";
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||
COPY_PHASE_STRIP = NO;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
ENABLE_TESTABILITY = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||
GCC_DYNAMIC_NO_PIC = NO;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = (
|
||||
"DEBUG=1",
|
||||
|
|
@ -211,7 +345,6 @@
|
|||
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
||||
MTL_ENABLE_DEBUG_INFO = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
PROVISIONING_PROFILE = "4d0a483e-6fa4-454e-a019-6ce6d8c6f307";
|
||||
SDKROOT = iphoneos;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
|
|
@ -231,8 +364,10 @@
|
|||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||
|
|
@ -240,6 +375,7 @@
|
|||
ENABLE_NS_ASSERTIONS = NO;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
|
|
@ -248,8 +384,8 @@
|
|||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
PROVISIONING_PROFILE = "4d0a483e-6fa4-454e-a019-6ce6d8c6f307";
|
||||
SDKROOT = iphoneos;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
VALIDATE_PRODUCT = YES;
|
||||
};
|
||||
|
|
@ -259,9 +395,13 @@
|
|||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
DEVELOPMENT_TEAM = "";
|
||||
INFOPLIST_FILE = camera/Info.plist;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = cameraDemo;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
|
|
@ -269,9 +409,66 @@
|
|||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
DEVELOPMENT_TEAM = "";
|
||||
INFOPLIST_FILE = camera/Info.plist;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = cameraDemo;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
D71DE89B1AD677A8001E62F1 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
DEFINES_MODULE = YES;
|
||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
||||
DYLIB_CURRENT_VERSION = 1;
|
||||
DYLIB_INSTALL_NAME_BASE = "@rpath";
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = (
|
||||
"DEBUG=1",
|
||||
"$(inherited)",
|
||||
);
|
||||
INFOPLIST_FILE = CameraManager/Info.plist;
|
||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "com.imaginarycloud.$(PRODUCT_NAME:rfc1034identifier)";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_VERSION = 3.0;
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
VERSION_INFO_PREFIX = "";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
D71DE89C1AD677A8001E62F1 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
|
||||
COPY_PHASE_STRIP = NO;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
DEFINES_MODULE = YES;
|
||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
||||
DYLIB_CURRENT_VERSION = 1;
|
||||
DYLIB_INSTALL_NAME_BASE = "@rpath";
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
INFOPLIST_FILE = CameraManager/Info.plist;
|
||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "com.imaginarycloud.$(PRODUCT_NAME:rfc1034identifier)";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_VERSION = 3.0;
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
VERSION_INFO_PREFIX = "";
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
|
|
@ -296,6 +493,15 @@
|
|||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
D71DE89A1AD677A8001E62F1 /* Build configuration list for PBXNativeTarget "CameraManager" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
D71DE89B1AD677A8001E62F1 /* Debug */,
|
||||
D71DE89C1AD677A8001E62F1 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
rootObject = 454C1F3919E82E2500C81915 /* Project object */;
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@
|
|||
<key>IDESourceControlWCCIdentifierKey</key>
|
||||
<string>E1D0A3AE6B49B031DF6A25973E5414F28D2A575A</string>
|
||||
<key>IDESourceControlWCCName</key>
|
||||
<string>camera</string>
|
||||
<string>CameraManager</string>
|
||||
</dict>
|
||||
</array>
|
||||
</dict>
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -0,0 +1,80 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0800"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "D71DE8801AD677A7001E62F1"
|
||||
BuildableName = "CameraManager.framework"
|
||||
BlueprintName = "CameraManager"
|
||||
ReferencedContainer = "container:camera.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "D71DE8801AD677A7001E62F1"
|
||||
BuildableName = "CameraManager.framework"
|
||||
BlueprintName = "CameraManager"
|
||||
ReferencedContainer = "container:camera.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "D71DE8801AD677A7001E62F1"
|
||||
BuildableName = "CameraManager.framework"
|
||||
BlueprintName = "CameraManager"
|
||||
ReferencedContainer = "container:camera.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0600"
|
||||
LastUpgradeVersion = "0700"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
|
@ -62,6 +62,8 @@
|
|||
ReferencedContainer = "container:camera.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
|
|
@ -71,8 +73,10 @@
|
|||
buildConfiguration = "Debug"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable>
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "454C1F4019E82E2500C81915"
|
||||
|
|
@ -90,7 +94,8 @@
|
|||
useCustomWorkingDirectory = "NO"
|
||||
buildConfiguration = "Release"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable>
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "454C1F4019E82E2500C81915"
|
||||
|
|
|
|||
|
|
@ -12,6 +12,11 @@
|
|||
</dict>
|
||||
<key>SuppressBuildableAutocreation</key>
|
||||
<dict>
|
||||
<key>453228F21AC2AD9A00A7EE76</key>
|
||||
<dict>
|
||||
<key>primary</key>
|
||||
<true/>
|
||||
</dict>
|
||||
<key>454C1F4019E82E2500C81915</key>
|
||||
<dict>
|
||||
<key>primary</key>
|
||||
|
|
@ -22,6 +27,11 @@
|
|||
<key>primary</key>
|
||||
<true/>
|
||||
</dict>
|
||||
<key>D71DE8801AD677A7001E62F1</key>
|
||||
<dict>
|
||||
<key>primary</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
|
|||
|
|
@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||
var window: UIWindow?
|
||||
|
||||
|
||||
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
|
||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
|
||||
// Override point for customization after application launch.
|
||||
return true
|
||||
}
|
||||
|
||||
func applicationWillResignActive(application: UIApplication) {
|
||||
func applicationWillResignActive(_ application: UIApplication) {
|
||||
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
||||
}
|
||||
|
||||
func applicationDidEnterBackground(application: UIApplication) {
|
||||
func applicationDidEnterBackground(_ application: UIApplication) {
|
||||
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
||||
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
|
||||
}
|
||||
|
||||
func applicationWillEnterForeground(application: UIApplication) {
|
||||
func applicationWillEnterForeground(_ application: UIApplication) {
|
||||
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
|
||||
}
|
||||
|
||||
func applicationDidBecomeActive(application: UIApplication) {
|
||||
func applicationDidBecomeActive(_ application: UIApplication) {
|
||||
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||
}
|
||||
|
||||
func applicationWillTerminate(application: UIApplication) {
|
||||
func applicationWillTerminate(_ application: UIApplication) {
|
||||
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6214" systemVersion="14A314h" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6207"/>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
|
||||
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
|
|
@ -11,16 +12,16 @@
|
|||
<rect key="frame" x="0.0" y="0.0" width="480" height="480"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2014 imaginaryCloud. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
|
||||
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2016 imaginaryCloud. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
|
||||
<rect key="frame" x="20" y="439" width="441" height="21"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="camera" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX">
|
||||
<rect key="frame" x="20" y="140" width="441" height="43"/>
|
||||
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
|
||||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
</subviews>
|
||||
|
|
|
|||
|
|
@ -1,13 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6245" systemVersion="13E28" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8191" systemVersion="14F27" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="bhK-VL-qY4">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6238"/>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8154"/>
|
||||
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--View Controller-->
|
||||
<!--Camera-->
|
||||
<scene sceneID="tne-QT-ifu">
|
||||
<objects>
|
||||
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="camera" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<viewController title="Camera" id="BYZ-38-t0r" customClass="ViewController" customModule="camera" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<layoutGuides>
|
||||
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
|
||||
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
|
||||
|
|
@ -21,34 +23,6 @@
|
|||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<color key="tintColor" red="0.54901963470000004" green="0.77647066119999997" blue="0.2470588386" alpha="1" colorSpace="deviceRGB"/>
|
||||
</view>
|
||||
<imageView hidden="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="yyS-3g-UqL">
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
|
||||
</imageView>
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="sT4-CC-oh5">
|
||||
<rect key="frame" x="496" y="20" width="88" height="33"/>
|
||||
<color key="backgroundColor" red="0.98039221759999995" green="0.0078431377190000002" blue="0.52156865600000002" alpha="1" colorSpace="deviceRGB"/>
|
||||
<state key="normal" title="Front">
|
||||
<color key="titleColor" red="1" green="0.87630701789999998" blue="0.35755069969999997" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
|
||||
</state>
|
||||
<connections>
|
||||
<action selector="changeCameraDevice:" destination="BYZ-38-t0r" eventType="touchUpInside" id="KDu-mr-jHd"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="19j-xT-Ttb">
|
||||
<rect key="frame" x="16" y="20" width="88" height="33"/>
|
||||
<color key="backgroundColor" red="0.54901963470000004" green="0.77647066119999997" blue="0.2470588386" alpha="1" colorSpace="deviceRGB"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" constant="88" id="7mm-eo-7Ng"/>
|
||||
<constraint firstAttribute="height" constant="33" id="jff-rD-TUp"/>
|
||||
</constraints>
|
||||
<state key="normal" title="Flash off">
|
||||
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
|
||||
</state>
|
||||
<connections>
|
||||
<action selector="changeFlashMode:" destination="BYZ-38-t0r" eventType="touchUpInside" id="e2b-Lg-iqO"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="FSo-n8-ZwV">
|
||||
<rect key="frame" x="275" y="530" width="50" height="50"/>
|
||||
<color key="backgroundColor" red="0.54901963470000004" green="0.77647066119999997" blue="0.2470588386" alpha="1" colorSpace="deviceRGB"/>
|
||||
|
|
@ -69,50 +43,178 @@
|
|||
<action selector="recordButtonTapped:" destination="BYZ-38-t0r" eventType="touchUpInside" id="Ggq-m1-AQB"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="3WP-Xo-FaJ">
|
||||
<rect key="frame" x="256" y="20" width="88" height="33"/>
|
||||
<color key="backgroundColor" red="1" green="0.87630701789999998" blue="0.35755069969999997" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<state key="normal" title="Video">
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="rd3-ei-B9P">
|
||||
<rect key="frame" x="4" y="84" width="592" height="512"/>
|
||||
<color key="backgroundColor" red="1" green="0.0" blue="0.46666669849999998" alpha="0.5" colorSpace="deviceRGB"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="27"/>
|
||||
<state key="normal">
|
||||
<color key="titleColor" red="0.36078432199999999" green="0.36078432199999999" blue="0.36078432199999999" alpha="1" colorSpace="deviceRGB"/>
|
||||
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
|
||||
</state>
|
||||
<connections>
|
||||
<action selector="outputModeButtonTapped:" destination="BYZ-38-t0r" eventType="touchUpInside" id="Bgy-rQ-cfF"/>
|
||||
<action selector="askForCameraPermissions:" destination="BYZ-38-t0r" eventType="touchUpInside" id="gbn-Ql-Lnv"/>
|
||||
</connections>
|
||||
</button>
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="jaF-q9-Eli">
|
||||
<rect key="frame" x="0.0" y="20" width="600" height="60"/>
|
||||
<subviews>
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="19j-xT-Ttb">
|
||||
<rect key="frame" x="0.0" y="0.0" width="150" height="60"/>
|
||||
<color key="backgroundColor" red="0.67058825489999996" green="0.67058825489999996" blue="0.67058825489999996" alpha="0.70000000000000007" colorSpace="deviceRGB"/>
|
||||
<state key="normal" title="Flash off">
|
||||
<color key="titleColor" red="0.0" green="0.50196081400000003" blue="1" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
|
||||
</state>
|
||||
<connections>
|
||||
<action selector="changeFlashMode:" destination="BYZ-38-t0r" eventType="touchUpInside" id="e2b-Lg-iqO"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="3WP-Xo-FaJ">
|
||||
<rect key="frame" x="150" y="0.0" width="150" height="60"/>
|
||||
<color key="backgroundColor" red="1" green="0.0" blue="0.46666669849999998" alpha="0.70000000000000007" colorSpace="deviceRGB"/>
|
||||
<state key="normal" title="Video">
|
||||
<color key="titleColor" red="0.0" green="0.50196081400000003" blue="1" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
|
||||
</state>
|
||||
<connections>
|
||||
<action selector="outputModeButtonTapped:" destination="BYZ-38-t0r" eventType="touchUpInside" id="Bgy-rQ-cfF"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="sT4-CC-oh5">
|
||||
<rect key="frame" x="300" y="0.0" width="150" height="60"/>
|
||||
<color key="backgroundColor" red="0.67058825489999996" green="0.67058825489999996" blue="0.67058825489999996" alpha="0.70000000000000007" colorSpace="deviceRGB"/>
|
||||
<state key="normal" title="Back">
|
||||
<color key="titleColor" red="0.0" green="0.50196081400000003" blue="1" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
|
||||
</state>
|
||||
<connections>
|
||||
<action selector="changeCameraDevice:" destination="BYZ-38-t0r" eventType="touchUpInside" id="KDu-mr-jHd"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="JCk-74-YkH">
|
||||
<rect key="frame" x="450" y="0.0" width="150" height="60"/>
|
||||
<color key="backgroundColor" red="1" green="0.0" blue="0.46666669849999998" alpha="0.70000000000000007" colorSpace="deviceRGB"/>
|
||||
<state key="normal" title="High">
|
||||
<color key="titleColor" red="0.0" green="0.50196081400000003" blue="1" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
|
||||
</state>
|
||||
<connections>
|
||||
<action selector="changeCameraQuality:" destination="BYZ-38-t0r" eventType="touchUpInside" id="Bt4-RC-Mrl"/>
|
||||
</connections>
|
||||
</button>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
|
||||
<constraints>
|
||||
<constraint firstItem="19j-xT-Ttb" firstAttribute="width" secondItem="3WP-Xo-FaJ" secondAttribute="width" id="0JS-OH-a4X"/>
|
||||
<constraint firstItem="3WP-Xo-FaJ" firstAttribute="leading" secondItem="19j-xT-Ttb" secondAttribute="trailing" id="7Y0-vo-2GG"/>
|
||||
<constraint firstItem="sT4-CC-oh5" firstAttribute="width" secondItem="3WP-Xo-FaJ" secondAttribute="width" id="Anx-2O-O5g"/>
|
||||
<constraint firstItem="19j-xT-Ttb" firstAttribute="top" secondItem="jaF-q9-Eli" secondAttribute="top" id="Faq-Kx-fdW"/>
|
||||
<constraint firstAttribute="bottom" secondItem="3WP-Xo-FaJ" secondAttribute="bottom" id="Jk9-HY-RKV"/>
|
||||
<constraint firstItem="JCk-74-YkH" firstAttribute="top" secondItem="jaF-q9-Eli" secondAttribute="top" id="Jxn-jp-3u1"/>
|
||||
<constraint firstItem="19j-xT-Ttb" firstAttribute="width" secondItem="jaF-q9-Eli" secondAttribute="width" multiplier="1:4" id="R5r-hS-YXf"/>
|
||||
<constraint firstAttribute="trailing" secondItem="JCk-74-YkH" secondAttribute="trailing" id="U8V-vs-AHd"/>
|
||||
<constraint firstAttribute="bottom" secondItem="sT4-CC-oh5" secondAttribute="bottom" id="X9n-5F-9S6"/>
|
||||
<constraint firstAttribute="bottom" secondItem="19j-xT-Ttb" secondAttribute="bottom" id="XIm-83-qDg"/>
|
||||
<constraint firstItem="19j-xT-Ttb" firstAttribute="leading" secondItem="jaF-q9-Eli" secondAttribute="leading" id="YKC-TE-A4C"/>
|
||||
<constraint firstItem="sT4-CC-oh5" firstAttribute="top" secondItem="jaF-q9-Eli" secondAttribute="top" id="dt8-f3-OG0"/>
|
||||
<constraint firstItem="sT4-CC-oh5" firstAttribute="leading" secondItem="3WP-Xo-FaJ" secondAttribute="trailing" id="f9i-42-p49"/>
|
||||
<constraint firstAttribute="bottom" secondItem="JCk-74-YkH" secondAttribute="bottom" id="jye-Mv-9Rq"/>
|
||||
<constraint firstItem="JCk-74-YkH" firstAttribute="leading" secondItem="sT4-CC-oh5" secondAttribute="trailing" id="mhQ-5m-h5c"/>
|
||||
<constraint firstAttribute="height" constant="60" id="mlL-sQ-rnK"/>
|
||||
<constraint firstItem="3WP-Xo-FaJ" firstAttribute="top" secondItem="jaF-q9-Eli" secondAttribute="top" id="oeK-QK-BDl"/>
|
||||
</constraints>
|
||||
</view>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Tap here to enable camera access and take great pictures" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="2bK-wq-6Rf">
|
||||
<rect key="frame" x="4" y="84" width="592" height="512"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="25"/>
|
||||
<color key="textColor" red="0.36078432199999999" green="0.36078432199999999" blue="0.36078432199999999" alpha="1" colorSpace="deviceRGB"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<gestureRecognizers/>
|
||||
<constraints>
|
||||
<constraint firstItem="yyS-3g-UqL" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="2RH-Jf-TPm"/>
|
||||
<constraint firstItem="19j-xT-Ttb" firstAttribute="height" secondItem="3WP-Xo-FaJ" secondAttribute="height" id="3Fa-ID-yp6"/>
|
||||
<constraint firstItem="19j-xT-Ttb" firstAttribute="width" secondItem="3WP-Xo-FaJ" secondAttribute="width" id="8aO-Xm-KH2"/>
|
||||
<constraint firstItem="2bK-wq-6Rf" firstAttribute="top" secondItem="rd3-ei-B9P" secondAttribute="top" id="0KQ-L2-vRf"/>
|
||||
<constraint firstAttribute="trailing" secondItem="jaF-q9-Eli" secondAttribute="trailing" id="2fZ-BE-g5j"/>
|
||||
<constraint firstItem="2bK-wq-6Rf" firstAttribute="top" secondItem="jaF-q9-Eli" secondAttribute="bottom" constant="4" id="8fE-gJ-Hi7"/>
|
||||
<constraint firstItem="EI2-CK-oqA" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="E1I-Yh-igT"/>
|
||||
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="yyS-3g-UqL" secondAttribute="bottom" id="INX-TM-tak"/>
|
||||
<constraint firstAttribute="trailing" secondItem="yyS-3g-UqL" secondAttribute="trailing" id="JEu-x6-qah"/>
|
||||
<constraint firstItem="rd3-ei-B9P" firstAttribute="bottom" secondItem="EI2-CK-oqA" secondAttribute="bottom" constant="-4" id="GKS-w4-B8J"/>
|
||||
<constraint firstItem="2bK-wq-6Rf" firstAttribute="bottom" secondItem="rd3-ei-B9P" secondAttribute="bottom" id="J9p-Wn-xC4"/>
|
||||
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="EI2-CK-oqA" secondAttribute="bottom" id="JW8-WC-69E"/>
|
||||
<constraint firstItem="19j-xT-Ttb" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" id="K6V-FG-8Ms"/>
|
||||
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="FSo-n8-ZwV" secondAttribute="bottom" constant="20" id="KgN-t9-iTh"/>
|
||||
<constraint firstAttribute="trailing" secondItem="sT4-CC-oh5" secondAttribute="trailing" constant="16" id="Q92-5b-7Z7"/>
|
||||
<constraint firstItem="yyS-3g-UqL" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="top" id="SyJ-SX-ooI"/>
|
||||
<constraint firstItem="jaF-q9-Eli" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="top" constant="20" id="Tv6-Ak-cSA"/>
|
||||
<constraint firstItem="EI2-CK-oqA" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="top" id="Y9T-eB-SQS"/>
|
||||
<constraint firstItem="3WP-Xo-FaJ" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" id="aur-kS-Ri3"/>
|
||||
<constraint firstAttribute="centerX" secondItem="3WP-Xo-FaJ" secondAttribute="centerX" id="c8T-oR-vKi"/>
|
||||
<constraint firstItem="2bK-wq-6Rf" firstAttribute="trailing" secondItem="rd3-ei-B9P" secondAttribute="trailing" id="add-TX-ds6"/>
|
||||
<constraint firstAttribute="trailing" secondItem="rd3-ei-B9P" secondAttribute="trailing" constant="4" id="dJE-jw-ZNY"/>
|
||||
<constraint firstAttribute="centerX" secondItem="FSo-n8-ZwV" secondAttribute="centerX" id="dQf-Ne-km4"/>
|
||||
<constraint firstItem="19j-xT-Ttb" firstAttribute="width" secondItem="sT4-CC-oh5" secondAttribute="width" id="dei-D3-qWh"/>
|
||||
<constraint firstItem="sT4-CC-oh5" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" id="i1Z-3m-ytG"/>
|
||||
<constraint firstItem="jaF-q9-Eli" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="eAr-PL-deK"/>
|
||||
<constraint firstAttribute="trailing" secondItem="EI2-CK-oqA" secondAttribute="trailing" id="m1R-4g-dGU"/>
|
||||
<constraint firstItem="19j-xT-Ttb" firstAttribute="height" secondItem="sT4-CC-oh5" secondAttribute="height" id="mpG-Ir-vxB"/>
|
||||
<constraint firstItem="19j-xT-Ttb" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" constant="16" id="uuM-vU-IPX"/>
|
||||
<constraint firstItem="rd3-ei-B9P" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" constant="4" id="n5z-dZ-b1l"/>
|
||||
<constraint firstItem="2bK-wq-6Rf" firstAttribute="leading" secondItem="rd3-ei-B9P" secondAttribute="leading" id="vNM-yq-5jd"/>
|
||||
</constraints>
|
||||
</view>
|
||||
<navigationItem key="navigationItem" id="EiR-i7-mkA"/>
|
||||
<nil key="simulatedTopBarMetrics"/>
|
||||
<connections>
|
||||
<outlet property="askForPermissionsButton" destination="rd3-ei-B9P" id="Itb-t1-HpD"/>
|
||||
<outlet property="askForPermissionsLabel" destination="2bK-wq-6Rf" id="GdV-Gq-uSS"/>
|
||||
<outlet property="cameraButton" destination="FSo-n8-ZwV" id="ITk-de-2LY"/>
|
||||
<outlet property="cameraView" destination="EI2-CK-oqA" id="bUS-Rk-omr"/>
|
||||
<outlet property="imageView" destination="yyS-3g-UqL" id="CZo-cW-NXH"/>
|
||||
<outlet property="flashModeButton" destination="19j-xT-Ttb" id="hjy-cj-bcm"/>
|
||||
</connections>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="709" y="102"/>
|
||||
</scene>
|
||||
<!--Image-->
|
||||
<scene sceneID="EDW-uZ-RNP">
|
||||
<objects>
|
||||
<viewController storyboardIdentifier="ImageVC" title="Image" id="xF2-bQ-3ri" customClass="ImageViewController" customModule="camera" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<layoutGuides>
|
||||
<viewControllerLayoutGuide type="top" id="LQz-Um-h4k"/>
|
||||
<viewControllerLayoutGuide type="bottom" id="qVT-yr-0bo"/>
|
||||
</layoutGuides>
|
||||
<view key="view" contentMode="scaleToFill" id="Qhk-xW-6b1">
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="v1g-94-paQ">
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
|
||||
</imageView>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<constraints>
|
||||
<constraint firstItem="v1g-94-paQ" firstAttribute="leading" secondItem="Qhk-xW-6b1" secondAttribute="leading" id="AJ6-Mx-ha2"/>
|
||||
<constraint firstItem="qVT-yr-0bo" firstAttribute="top" secondItem="v1g-94-paQ" secondAttribute="bottom" id="QTs-sj-GPP"/>
|
||||
<constraint firstAttribute="trailing" secondItem="v1g-94-paQ" secondAttribute="trailing" id="SFa-Zd-kVH"/>
|
||||
<constraint firstItem="v1g-94-paQ" firstAttribute="top" secondItem="Qhk-xW-6b1" secondAttribute="top" id="jLa-Hd-QGr"/>
|
||||
</constraints>
|
||||
</view>
|
||||
<connections>
|
||||
<outlet property="imageView" destination="v1g-94-paQ" id="x8J-Uk-fu3"/>
|
||||
</connections>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="caE-Sy-maH" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="1460" y="97"/>
|
||||
</scene>
|
||||
<!--Navigation Controller-->
|
||||
<scene sceneID="s7F-c8-PK8">
|
||||
<objects>
|
||||
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="bhK-VL-qY4" sceneMemberID="viewController">
|
||||
<toolbarItems/>
|
||||
<navigationBar key="navigationBar" contentMode="scaleToFill" id="Gas-AK-MC9">
|
||||
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</navigationBar>
|
||||
<nil name="viewControllers"/>
|
||||
<connections>
|
||||
<segue destination="BYZ-38-t0r" kind="relationship" relationship="rootViewController" id="gVy-l9-gbi"/>
|
||||
</connections>
|
||||
</navigationController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="atD-jO-HGu" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="-103" y="102"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,653 @@
|
|||
//
|
||||
// CameraManager.swift
|
||||
// camera
|
||||
//
|
||||
// Created by Natalia Terlecka on 10/10/14.
|
||||
// Copyright (c) 2014 imaginaryCloud. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import AVFoundation
|
||||
import AssetsLibrary
|
||||
|
||||
private let _singletonSharedInstance = CameraManager()
|
||||
|
||||
enum CameraDevice {
|
||||
case Front, Back
|
||||
}
|
||||
|
||||
enum CameraFlashMode: Int {
|
||||
case Off, On, Auto
|
||||
}
|
||||
|
||||
enum CameraOutputMode {
|
||||
case StillImage, VideoWithMic, VideoOnly
|
||||
}
|
||||
|
||||
enum CameraOutputQuality {
|
||||
case Low, Medium, High
|
||||
}
|
||||
|
||||
/// Class for handling iDevices custom camera usage
|
||||
class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
|
||||
|
||||
/// Capture session to customize camera settings.
|
||||
var captureSession: AVCaptureSession?
|
||||
|
||||
/// Property to determine if the manager should show the error for the user. If you want to show the errors yourself set this to false. If you want to add custom error UI set showErrorBlock property. Default value is true.
|
||||
var showErrorsToUsers = true
|
||||
|
||||
/// A block creating UI to present error message to the user.
|
||||
var showErrorBlock:(erTitle: String, erMessage: String) -> Void = { (erTitle: String, erMessage: String) -> Void in
|
||||
UIAlertView(title: erTitle, message: erMessage, delegate: nil, cancelButtonTitle: "OK").show()
|
||||
}
|
||||
|
||||
/// Property to determine if manager should write the resources to the phone library. Default value is true.
|
||||
var writeFilesToPhoneLibrary = true
|
||||
|
||||
/// The Bool property to determin if current device has front camera.
|
||||
var hasFrontCamera: Bool = {
|
||||
let devices = AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo)
|
||||
for device in devices {
|
||||
let captureDevice = device as AVCaptureDevice
|
||||
if (captureDevice.position == .Front) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}()
|
||||
|
||||
/// Property to change camera device between front and back.
|
||||
var cameraDevice: CameraDevice {
|
||||
get {
|
||||
return _cameraDevice
|
||||
}
|
||||
set(newCameraDevice) {
|
||||
if let validCaptureSession = self.captureSession {
|
||||
validCaptureSession.beginConfiguration()
|
||||
let inputs = validCaptureSession.inputs as [AVCaptureInput]
|
||||
|
||||
switch newCameraDevice {
|
||||
case .Front:
|
||||
if self.hasFrontCamera {
|
||||
if let validBackDevice = self.rearCamera? {
|
||||
if contains(inputs, validBackDevice) {
|
||||
validCaptureSession.removeInput(validBackDevice)
|
||||
}
|
||||
}
|
||||
if let validFrontDevice = self.frontCamera? {
|
||||
if !contains(inputs, validFrontDevice) {
|
||||
validCaptureSession.addInput(validFrontDevice)
|
||||
}
|
||||
}
|
||||
}
|
||||
case .Back:
|
||||
if let validFrontDevice = self.frontCamera? {
|
||||
if contains(inputs, validFrontDevice) {
|
||||
validCaptureSession.removeInput(validFrontDevice)
|
||||
}
|
||||
}
|
||||
if let validBackDevice = self.rearCamera? {
|
||||
if !contains(inputs, validBackDevice) {
|
||||
validCaptureSession.addInput(validBackDevice)
|
||||
}
|
||||
}
|
||||
}
|
||||
validCaptureSession.commitConfiguration()
|
||||
}
|
||||
_cameraDevice = newCameraDevice
|
||||
}
|
||||
}
|
||||
|
||||
/// Property to change camera flash mode.
|
||||
var flashMode: CameraFlashMode {
|
||||
get {
|
||||
return _flashMode
|
||||
}
|
||||
set(newflashMode) {
|
||||
if newflashMode != _flashMode {
|
||||
self.captureSession?.beginConfiguration()
|
||||
let devices = AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo)
|
||||
for device in devices {
|
||||
let captureDevice = device as AVCaptureDevice
|
||||
if (captureDevice.position == AVCaptureDevicePosition.Back) {
|
||||
let avFlashMode = AVCaptureFlashMode(rawValue: newflashMode.rawValue)
|
||||
if (captureDevice.isFlashModeSupported(avFlashMode!)) {
|
||||
captureDevice.lockForConfiguration(nil)
|
||||
captureDevice.flashMode = avFlashMode!
|
||||
captureDevice.unlockForConfiguration()
|
||||
}
|
||||
}
|
||||
}
|
||||
self.captureSession?.commitConfiguration()
|
||||
|
||||
_flashMode = newflashMode
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Property to change camera output quality.
|
||||
var cameraOutputQuality: CameraOutputQuality {
|
||||
get {
|
||||
return _cameraOutputQuality
|
||||
}
|
||||
set(newCameraOutputQuality) {
|
||||
if newCameraOutputQuality != _cameraOutputQuality {
|
||||
if let validCaptureSession = self.captureSession? {
|
||||
validCaptureSession.beginConfiguration()
|
||||
switch (newCameraOutputQuality) {
|
||||
case CameraOutputQuality.Low:
|
||||
validCaptureSession.sessionPreset = AVCaptureSessionPresetLow
|
||||
case CameraOutputQuality.Medium:
|
||||
validCaptureSession.sessionPreset = AVCaptureSessionPresetMedium
|
||||
case CameraOutputQuality.High:
|
||||
validCaptureSession.sessionPreset = AVCaptureSessionPresetHigh
|
||||
}
|
||||
validCaptureSession.commitConfiguration()
|
||||
|
||||
_cameraOutputQuality = newCameraOutputQuality
|
||||
} else {
|
||||
self._show("Camera error", message: "No valid capture session found, I can't take any pictures or videos.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Property to change camera output.
|
||||
var cameraOutputMode: CameraOutputMode {
|
||||
get {
|
||||
return _cameraOutputMode
|
||||
}
|
||||
set(newCameraOutputMode) {
|
||||
if newCameraOutputMode != _cameraOutputMode {
|
||||
self._setupOutputMode(newCameraOutputMode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private weak var embedingView: UIView?
|
||||
private var videoCompletition: ((videoURL: NSURL) -> Void)?
|
||||
|
||||
private var sessionQueue: dispatch_queue_t = dispatch_queue_create("CameraSessionQueue", DISPATCH_QUEUE_SERIAL)
|
||||
|
||||
private var frontCamera: AVCaptureInput?
|
||||
private var rearCamera: AVCaptureInput?
|
||||
private var mic: AVCaptureDeviceInput?
|
||||
private var stillImageOutput: AVCaptureStillImageOutput?
|
||||
private var movieOutput: AVCaptureMovieFileOutput?
|
||||
private var previewLayer: AVCaptureVideoPreviewLayer?
|
||||
private var library: ALAssetsLibrary?
|
||||
|
||||
private var cameraIsSetup = false
|
||||
private var cameraIsObservingDeviceOrientation = false
|
||||
|
||||
private var _cameraDevice = CameraDevice.Back
|
||||
private var _flashMode = CameraFlashMode.Off
|
||||
private var _cameraOutputMode = CameraOutputMode.StillImage
|
||||
private var _cameraOutputQuality = CameraOutputQuality.High
|
||||
|
||||
private var tempFilePath: NSURL = {
|
||||
let tempPath = NSTemporaryDirectory().stringByAppendingPathComponent("tempMovie").stringByAppendingPathExtension("mp4")
|
||||
if NSFileManager.defaultManager().fileExistsAtPath(tempPath!) {
|
||||
NSFileManager.defaultManager().removeItemAtPath(tempPath!, error: nil)
|
||||
}
|
||||
return NSURL(fileURLWithPath: tempPath!)!
|
||||
}()
|
||||
|
||||
/// CameraManager singleton instance to use the camera.
|
||||
class var sharedInstance: CameraManager {
|
||||
return _singletonSharedInstance
|
||||
}
|
||||
|
||||
deinit {
|
||||
self.stopAndRemoveCaptureSession()
|
||||
self._stopFollowingDeviceOrientation()
|
||||
}
|
||||
|
||||
/**
|
||||
Inits a capture session and adds a preview layer to the given view. Preview layer bounds will automaticaly be set to match given view. Default session is initialized with still image output.
|
||||
|
||||
:param: view The view you want to add the preview layer to
|
||||
:param: cameraOutputMode The mode you want capturesession to run image / video / video and microphone
|
||||
*/
|
||||
func addPreviewLayerToView(view: UIView)
|
||||
{
|
||||
self.addPreviewLayerToView(view, newCameraOutputMode: _cameraOutputMode)
|
||||
}
|
||||
func addPreviewLayerToView(view: UIView, newCameraOutputMode: CameraOutputMode)
|
||||
{
|
||||
if let validEmbedingView = self.embedingView? {
|
||||
if let validPreviewLayer = self.previewLayer? {
|
||||
validPreviewLayer.removeFromSuperlayer()
|
||||
}
|
||||
}
|
||||
if self.cameraIsSetup {
|
||||
self._addPreeviewLayerToView(view)
|
||||
self.cameraOutputMode = newCameraOutputMode
|
||||
} else {
|
||||
self._setupCamera({ Void -> Void in
|
||||
self._addPreeviewLayerToView(view)
|
||||
self.cameraOutputMode = newCameraOutputMode
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Stops running capture session but all setup devices, inputs and outputs stay for further reuse.
|
||||
*/
|
||||
func stopCaptureSession()
|
||||
{
|
||||
self.captureSession?.stopRunning()
|
||||
self._stopFollowingDeviceOrientation()
|
||||
}
|
||||
|
||||
/**
|
||||
Resumes capture session.
|
||||
*/
|
||||
func resumeCaptureSession()
|
||||
{
|
||||
if let validCaptureSession = self.captureSession? {
|
||||
if !validCaptureSession.running && self.cameraIsSetup {
|
||||
validCaptureSession.startRunning()
|
||||
self._startFollowingDeviceOrientation()
|
||||
}
|
||||
} else {
|
||||
if self.cameraIsSetup {
|
||||
self.stopAndRemoveCaptureSession()
|
||||
}
|
||||
self._setupCamera({Void -> Void in
|
||||
if let validEmbedingView = self.embedingView? {
|
||||
self._addPreeviewLayerToView(validEmbedingView)
|
||||
}
|
||||
self._startFollowingDeviceOrientation()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Stops running capture session and removes all setup devices, inputs and outputs.
|
||||
*/
|
||||
func stopAndRemoveCaptureSession()
|
||||
{
|
||||
self.stopCaptureSession()
|
||||
self.cameraDevice = .Back
|
||||
self.cameraIsSetup = false
|
||||
self.previewLayer = nil
|
||||
self.captureSession = nil
|
||||
self.frontCamera = nil
|
||||
self.rearCamera = nil
|
||||
self.mic = nil
|
||||
self.stillImageOutput = nil
|
||||
self.movieOutput = nil
|
||||
}
|
||||
|
||||
/**
|
||||
Captures still image from currently running capture session.
|
||||
|
||||
:param: imageCompletition Completition block containing the captured UIImage
|
||||
*/
|
||||
func capturePictureWithCompletition(imageCompletition: UIImage -> Void)
|
||||
{
|
||||
if self.cameraIsSetup {
|
||||
if self.cameraOutputMode == .StillImage {
|
||||
dispatch_async(self.sessionQueue, {
|
||||
self._getStillImageOutput().captureStillImageAsynchronouslyFromConnection(self._getStillImageOutput().connectionWithMediaType(AVMediaTypeVideo), completionHandler: { [weak self] (sample: CMSampleBuffer!, error: NSError!) -> Void in
|
||||
if (error? != nil) {
|
||||
dispatch_async(dispatch_get_main_queue(), {
|
||||
if let weakSelf = self {
|
||||
weakSelf._show("error", message: error.localizedDescription)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sample)
|
||||
if let weakSelf = self {
|
||||
if weakSelf.writeFilesToPhoneLibrary {
|
||||
if let validLibrary = weakSelf.library? {
|
||||
validLibrary.writeImageDataToSavedPhotosAlbum(imageData, metadata:nil, completionBlock: {
|
||||
(picUrl, error) -> Void in
|
||||
if (error? != nil) {
|
||||
dispatch_async(dispatch_get_main_queue(), {
|
||||
weakSelf._show("error", message: error.localizedDescription)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
imageCompletition(UIImage(data: imageData)!)
|
||||
}
|
||||
})
|
||||
})
|
||||
} else {
|
||||
self._show("Capture session output mode video", message: "I can't take any picture")
|
||||
}
|
||||
} else {
|
||||
self._show("No capture session setup", message: "I can't take any picture")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Starts recording a video with or without voice as in the session preset.
|
||||
*/
|
||||
func startRecordingVideo()
|
||||
{
|
||||
if self.cameraOutputMode != .StillImage {
|
||||
self._getMovieOutput().startRecordingToOutputFileURL(self.tempFilePath, recordingDelegate: self)
|
||||
} else {
|
||||
self._show("Capture session output still image", message: "I can only take pictures")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Stop recording a video. Save it to the cameraRoll and give back the url.
|
||||
*/
|
||||
func stopRecordingVideo(completition:(videoURL: NSURL) -> Void)
|
||||
{
|
||||
if let runningMovieOutput = self.movieOutput {
|
||||
if runningMovieOutput.recording {
|
||||
self.videoCompletition = completition
|
||||
runningMovieOutput.stopRecording()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// PRAGMA MARK - AVCaptureFileOutputRecordingDelegate
|
||||
|
||||
func captureOutput(captureOutput: AVCaptureFileOutput!, didStartRecordingToOutputFileAtURL fileURL: NSURL!, fromConnections connections: [AnyObject]!)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
func captureOutput(captureOutput: AVCaptureFileOutput!, didFinishRecordingToOutputFileAtURL outputFileURL: NSURL!, fromConnections connections: [AnyObject]!, error: NSError!)
|
||||
{
|
||||
if (error != nil) {
|
||||
self._show("Unable to save video to the iPhone", message: error.localizedDescription)
|
||||
} else {
|
||||
if let validLibrary = self.library? {
|
||||
if self.writeFilesToPhoneLibrary {
|
||||
validLibrary.writeVideoAtPathToSavedPhotosAlbum(outputFileURL, completionBlock: { (assetURL: NSURL?, error: NSError?) -> Void in
|
||||
if (error != nil) {
|
||||
self._show("Unable to save video to the iPhone.", message: error!.localizedDescription)
|
||||
} else {
|
||||
if let validAssetURL = assetURL {
|
||||
self._executeVideoCompletitionWithURL(validAssetURL)
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
self._executeVideoCompletitionWithURL(outputFileURL)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PRAGMA MARK - CameraManager()
|
||||
|
||||
private func _executeVideoCompletitionWithURL(url: NSURL)
|
||||
{
|
||||
if let validCompletition = self.videoCompletition {
|
||||
validCompletition(videoURL: url)
|
||||
self.videoCompletition = nil
|
||||
}
|
||||
}
|
||||
|
||||
private func _getMovieOutput() -> AVCaptureMovieFileOutput
|
||||
{
|
||||
var shouldReinitializeMovieOutput = self.movieOutput == nil
|
||||
if !shouldReinitializeMovieOutput {
|
||||
if let connection = self.movieOutput!.connectionWithMediaType(AVMediaTypeVideo) {
|
||||
shouldReinitializeMovieOutput = shouldReinitializeMovieOutput || !connection.active
|
||||
}
|
||||
}
|
||||
|
||||
if shouldReinitializeMovieOutput {
|
||||
self.movieOutput = AVCaptureMovieFileOutput()
|
||||
|
||||
self.captureSession?.beginConfiguration()
|
||||
self.captureSession?.addOutput(self.movieOutput)
|
||||
self.captureSession?.commitConfiguration()
|
||||
}
|
||||
return self.movieOutput!
|
||||
}
|
||||
|
||||
private func _getStillImageOutput() -> AVCaptureStillImageOutput
|
||||
{
|
||||
var shouldReinitializeStillImageOutput = self.stillImageOutput == nil
|
||||
if !shouldReinitializeStillImageOutput {
|
||||
if let connection = self.stillImageOutput!.connectionWithMediaType(AVMediaTypeVideo) {
|
||||
shouldReinitializeStillImageOutput = shouldReinitializeStillImageOutput || !connection.active
|
||||
}
|
||||
}
|
||||
if shouldReinitializeStillImageOutput {
|
||||
self.stillImageOutput = AVCaptureStillImageOutput()
|
||||
|
||||
self.captureSession?.beginConfiguration()
|
||||
self.captureSession?.addOutput(self.stillImageOutput)
|
||||
self.captureSession?.commitConfiguration()
|
||||
}
|
||||
return self.stillImageOutput!
|
||||
}
|
||||
|
||||
@objc private func _orientationChanged()
|
||||
{
|
||||
var currentConnection: AVCaptureConnection?;
|
||||
switch self.cameraOutputMode {
|
||||
case .StillImage:
|
||||
currentConnection = self.stillImageOutput?.connectionWithMediaType(AVMediaTypeVideo)
|
||||
case .VideoOnly, .VideoWithMic:
|
||||
currentConnection = self._getMovieOutput().connectionWithMediaType(AVMediaTypeVideo)
|
||||
}
|
||||
if let validPreviewLayer = self.previewLayer? {
|
||||
if let validPreviewLayerConnection = validPreviewLayer.connection? {
|
||||
if validPreviewLayerConnection.supportsVideoOrientation {
|
||||
validPreviewLayerConnection.videoOrientation = self._currentVideoOrientation()
|
||||
}
|
||||
}
|
||||
if let validOutputLayerConnection = currentConnection? {
|
||||
if validOutputLayerConnection.supportsVideoOrientation {
|
||||
validOutputLayerConnection.videoOrientation = self._currentVideoOrientation()
|
||||
}
|
||||
}
|
||||
dispatch_async(dispatch_get_main_queue(), { () -> Void in
|
||||
if let validEmbedingView = self.embedingView? {
|
||||
validPreviewLayer.frame = validEmbedingView.bounds
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private func _currentVideoOrientation() -> AVCaptureVideoOrientation
|
||||
{
|
||||
switch UIDevice.currentDevice().orientation {
|
||||
case .LandscapeLeft:
|
||||
return .LandscapeRight
|
||||
case .LandscapeRight:
|
||||
return .LandscapeLeft
|
||||
default:
|
||||
return .Portrait
|
||||
}
|
||||
}
|
||||
|
||||
private func _setupCamera(completition: Void -> Void)
|
||||
{
|
||||
if self._checkIfCameraIsAvailable() {
|
||||
self.captureSession = AVCaptureSession()
|
||||
|
||||
dispatch_async(sessionQueue, {
|
||||
if let validCaptureSession = self.captureSession? {
|
||||
validCaptureSession.beginConfiguration()
|
||||
validCaptureSession.sessionPreset = AVCaptureSessionPresetHigh
|
||||
self._addVideoInput()
|
||||
self._setupOutputs()
|
||||
self._setupOutputMode(self._cameraOutputMode)
|
||||
self.cameraOutputQuality = self._cameraOutputQuality
|
||||
self._setupPreviewLayer()
|
||||
validCaptureSession.commitConfiguration()
|
||||
validCaptureSession.startRunning()
|
||||
self._startFollowingDeviceOrientation()
|
||||
self.cameraIsSetup = true
|
||||
|
||||
completition()
|
||||
}
|
||||
})
|
||||
} else {
|
||||
self._show("Camera unavailable", message: "The device does not have a camera")
|
||||
}
|
||||
}
|
||||
|
||||
private func _startFollowingDeviceOrientation()
|
||||
{
|
||||
if !self.cameraIsObservingDeviceOrientation {
|
||||
NSNotificationCenter.defaultCenter().addObserver(self, selector: "_orientationChanged", name: UIDeviceOrientationDidChangeNotification, object: nil)
|
||||
self.cameraIsObservingDeviceOrientation = true
|
||||
}
|
||||
}
|
||||
|
||||
private func _stopFollowingDeviceOrientation()
|
||||
{
|
||||
if self.cameraIsObservingDeviceOrientation {
|
||||
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIDeviceOrientationDidChangeNotification, object: nil)
|
||||
self.cameraIsObservingDeviceOrientation = false
|
||||
}
|
||||
}
|
||||
|
||||
private func _addPreeviewLayerToView(view: UIView)
|
||||
{
|
||||
self.embedingView = view
|
||||
dispatch_async(dispatch_get_main_queue(), { () -> Void in
|
||||
self.previewLayer?.frame = view.layer.bounds
|
||||
view.clipsToBounds = true
|
||||
view.layer.addSublayer(self.previewLayer)
|
||||
})
|
||||
}
|
||||
|
||||
private func _checkIfCameraIsAvailable() -> Bool
|
||||
{
|
||||
let deviceHasCamera = UIImagePickerController.isCameraDeviceAvailable(UIImagePickerControllerCameraDevice.Rear) || UIImagePickerController.isCameraDeviceAvailable(UIImagePickerControllerCameraDevice.Front)
|
||||
return deviceHasCamera
|
||||
}
|
||||
|
||||
private func _addVideoInput()
|
||||
{
|
||||
var error: NSError?
|
||||
|
||||
if (self.frontCamera? == nil) || (self.rearCamera? == nil) {
|
||||
var videoFrontDevice: AVCaptureDevice?
|
||||
var videoBackDevice: AVCaptureDevice?
|
||||
for device: AnyObject in AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo) {
|
||||
if device.position == AVCaptureDevicePosition.Back {
|
||||
videoBackDevice = device as? AVCaptureDevice
|
||||
} else if device.position == AVCaptureDevicePosition.Front {
|
||||
videoFrontDevice = device as? AVCaptureDevice
|
||||
}
|
||||
}
|
||||
if (self.frontCamera? == nil) {
|
||||
if let validVideoFrontDevice = videoFrontDevice? {
|
||||
self.frontCamera = AVCaptureDeviceInput.deviceInputWithDevice(validVideoFrontDevice, error: &error) as AVCaptureDeviceInput
|
||||
}
|
||||
}
|
||||
if (self.rearCamera? == nil) {
|
||||
if let validVideoBackDevice = videoBackDevice? {
|
||||
self.rearCamera = AVCaptureDeviceInput.deviceInputWithDevice(validVideoBackDevice, error: &error) as AVCaptureDeviceInput
|
||||
}
|
||||
}
|
||||
if let validError = error? {
|
||||
self._show("Device setup error occured", message: validError.localizedDescription)
|
||||
}
|
||||
}
|
||||
self.cameraDevice = _cameraDevice
|
||||
}
|
||||
|
||||
private func _setupMic()
|
||||
{
|
||||
if (self.mic == nil) {
|
||||
var error: NSError?
|
||||
let micDevice:AVCaptureDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeAudio);
|
||||
self.mic = AVCaptureDeviceInput.deviceInputWithDevice(micDevice, error: &error) as? AVCaptureDeviceInput;
|
||||
if let errorHappened = error? {
|
||||
self.mic = nil
|
||||
self._show("Mic error", message: errorHappened.description)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func _setupOutputMode(newCameraOutputMode: CameraOutputMode)
|
||||
{
|
||||
self.captureSession?.beginConfiguration()
|
||||
|
||||
if (_cameraOutputMode != newCameraOutputMode) {
|
||||
// remove current setting
|
||||
switch _cameraOutputMode {
|
||||
case .StillImage:
|
||||
if let validStillImageOutput = self.stillImageOutput? {
|
||||
self.captureSession?.removeOutput(validStillImageOutput)
|
||||
}
|
||||
case .VideoOnly, .VideoWithMic:
|
||||
if let validMovieOutput = self.movieOutput? {
|
||||
self.captureSession?.removeOutput(validMovieOutput)
|
||||
}
|
||||
if _cameraOutputMode == .VideoWithMic {
|
||||
if let validMic = self.mic? {
|
||||
self.captureSession?.removeInput(validMic)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// configure new devices
|
||||
switch newCameraOutputMode {
|
||||
case .StillImage:
|
||||
if (self.stillImageOutput == nil) {
|
||||
self._setupOutputs()
|
||||
}
|
||||
if let validStillImageOutput = self.stillImageOutput? {
|
||||
self.captureSession?.addOutput(validStillImageOutput)
|
||||
}
|
||||
case .VideoOnly, .VideoWithMic:
|
||||
self.captureSession?.addOutput(self._getMovieOutput())
|
||||
|
||||
if newCameraOutputMode == .VideoWithMic {
|
||||
if (self.mic == nil) {
|
||||
self._setupMic()
|
||||
}
|
||||
if let validMic = self.mic? {
|
||||
self.captureSession?.addInput(validMic)
|
||||
}
|
||||
}
|
||||
}
|
||||
self.captureSession?.commitConfiguration()
|
||||
_cameraOutputMode = newCameraOutputMode;
|
||||
self._orientationChanged()
|
||||
}
|
||||
|
||||
private func _setupOutputs()
|
||||
{
|
||||
if (self.stillImageOutput == nil) {
|
||||
self.stillImageOutput = AVCaptureStillImageOutput()
|
||||
}
|
||||
if (self.movieOutput == nil) {
|
||||
self.movieOutput = AVCaptureMovieFileOutput()
|
||||
}
|
||||
if self.library == nil {
|
||||
self.library = ALAssetsLibrary()
|
||||
}
|
||||
}
|
||||
|
||||
private func _setupPreviewLayer()
|
||||
{
|
||||
if let validCaptureSession = self.captureSession? {
|
||||
self.previewLayer = AVCaptureVideoPreviewLayer(session: validCaptureSession)
|
||||
self.previewLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill
|
||||
}
|
||||
}
|
||||
|
||||
private func _show(title: String, message: String)
|
||||
{
|
||||
if self.showErrorsToUsers {
|
||||
dispatch_async(dispatch_get_main_queue(), { () -> Void in
|
||||
self.showErrorBlock(erTitle: title, erMessage: message)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>BaseBundlePath</key>
|
||||
<string>/Applications/TextMate.app/Contents/Library/QuickLook/TextMateQL.qlgenerator</string>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
//
|
||||
// ImageViewController.swift
|
||||
// camera
|
||||
//
|
||||
// Created by Natalia Terlecka on 13/01/15.
|
||||
// Copyright (c) 2015 imaginaryCloud. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class ImageViewController: UIViewController {
|
||||
|
||||
var image: UIImage?
|
||||
@IBOutlet weak var imageView: UIImageView!
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
self.navigationController?.navigationBar.isHidden = false
|
||||
|
||||
if let validImage = self.image {
|
||||
self.imageView.image = validImage
|
||||
}
|
||||
}
|
||||
|
||||
override func didReceiveMemoryWarning() {
|
||||
super.didReceiveMemoryWarning()
|
||||
// Dispose of any resources that can be recreated.
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -2,12 +2,18 @@
|
|||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>NSPhotoLibraryUsageDescription</key>
|
||||
<string>CameraManager will access your photo library to save pictures/video.</string>
|
||||
<key>NSMicrophoneUsageDescription</key>
|
||||
<string>CameraManager will use your microphone to record audio for videos.</string>
|
||||
<key>NSCameraUsageDescription</key>
|
||||
<string>CameraManager will use your camera to take pictures/video.</string>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.dotzar.camera</string>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
|
|
@ -15,7 +21,7 @@
|
|||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<string>1.0.14</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
|
|
|
|||
|
|
@ -7,81 +7,171 @@
|
|||
//
|
||||
|
||||
import UIKit
|
||||
import CameraManager
|
||||
|
||||
class ViewController: UIViewController {
|
||||
|
||||
let cameraManager = CameraManager.sharedInstance
|
||||
// MARK: - Constants
|
||||
|
||||
let cameraManager = CameraManager()
|
||||
|
||||
// MARK: - @IBOutlets
|
||||
|
||||
@IBOutlet weak var cameraView: UIView!
|
||||
@IBOutlet weak var imageView: UIImageView!
|
||||
|
||||
@IBOutlet weak var cameraButton: UIButton!
|
||||
@IBOutlet weak var flashModeButton: UIButton!
|
||||
|
||||
override func viewDidLoad()
|
||||
@IBOutlet weak var askForPermissionsButton: UIButton!
|
||||
@IBOutlet weak var askForPermissionsLabel: UILabel!
|
||||
|
||||
|
||||
// MARK: - UIViewController
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
cameraManager.showAccessPermissionPopupAutomatically = false
|
||||
|
||||
askForPermissionsButton.isHidden = true
|
||||
askForPermissionsLabel.isHidden = true
|
||||
|
||||
let currentCameraState = cameraManager.currentCameraStatus()
|
||||
|
||||
if currentCameraState == .notDetermined {
|
||||
askForPermissionsButton.isHidden = false
|
||||
askForPermissionsLabel.isHidden = false
|
||||
} else if (currentCameraState == .ready) {
|
||||
addCameraToView()
|
||||
}
|
||||
if !cameraManager.hasFlash {
|
||||
flashModeButton.isEnabled = false
|
||||
flashModeButton.setTitle("No flash", for: UIControlState())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
|
||||
navigationController?.navigationBar.isHidden = true
|
||||
cameraManager.resumeCaptureSession()
|
||||
}
|
||||
|
||||
override func viewWillDisappear(_ animated: Bool) {
|
||||
super.viewWillDisappear(animated)
|
||||
cameraManager.stopCaptureSession()
|
||||
}
|
||||
|
||||
|
||||
// MARK: - ViewController
|
||||
|
||||
fileprivate func addCameraToView()
|
||||
{
|
||||
super.viewDidLoad()
|
||||
self.cameraManager.addPreviewLayerToView(self.cameraView, newCameraOutputMode: CameraOutputMode.VideoWithMic)
|
||||
self.cameraManager.cameraDevice = .Front
|
||||
self.imageView.hidden = true
|
||||
CameraManager.sharedInstance.showErrorBlock = { (erTitle: String, erMessage: String) -> Void in
|
||||
UIAlertView(title: erTitle, message: erMessage, delegate: nil, cancelButtonTitle: "OK").show()
|
||||
cameraManager.addPreviewLayerToView(cameraView, newCameraOutputMode: CameraOutputMode.videoWithMic)
|
||||
cameraManager.showErrorBlock = { [weak self] (erTitle: String, erMessage: String) -> Void in
|
||||
|
||||
let alertController = UIAlertController(title: erTitle, message: erMessage, preferredStyle: .alert)
|
||||
alertController.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: { (alertAction) -> Void in }))
|
||||
|
||||
self?.present(alertController, animated: true, completion: nil)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - @IBActions
|
||||
|
||||
@IBAction func changeFlashMode(_ sender: UIButton)
|
||||
{
|
||||
switch (cameraManager.changeFlashMode()) {
|
||||
case .off:
|
||||
sender.setTitle("Flash Off", for: UIControlState())
|
||||
case .on:
|
||||
sender.setTitle("Flash On", for: UIControlState())
|
||||
case .auto:
|
||||
sender.setTitle("Flash Auto", for: UIControlState())
|
||||
}
|
||||
}
|
||||
|
||||
@IBAction func changeFlashMode(sender: UIButton)
|
||||
{
|
||||
self.cameraManager.flashMode = CameraFlashMode.fromRaw((self.cameraManager.flashMode.toRaw()+1)%3)!
|
||||
switch (self.cameraManager.flashMode) {
|
||||
case .Off:
|
||||
sender.setTitle("Flash Off", forState: UIControlState.Normal)
|
||||
case .On:
|
||||
sender.setTitle("Flash On", forState: UIControlState.Normal)
|
||||
case .Auto:
|
||||
sender.setTitle("Flash Auto", forState: UIControlState.Normal)
|
||||
}
|
||||
}
|
||||
|
||||
@IBAction func recordButtonTapped(sender: UIButton)
|
||||
{
|
||||
switch (self.cameraManager.cameraOutputMode) {
|
||||
case .StillImage:
|
||||
self.cameraManager.capturePictureWithCompletition({ (image) -> Void in
|
||||
|
||||
@IBAction func recordButtonTapped(_ sender: UIButton) {
|
||||
|
||||
switch (cameraManager.cameraOutputMode) {
|
||||
case .stillImage:
|
||||
cameraManager.capturePictureWithCompletion({ (image, error) -> Void in
|
||||
if let errorOccured = error {
|
||||
self.cameraManager.showErrorBlock("Error occurred", errorOccured.localizedDescription)
|
||||
}
|
||||
else {
|
||||
let vc: ImageViewController? = self.storyboard?.instantiateViewController(withIdentifier: "ImageVC") as? ImageViewController
|
||||
if let validVC: ImageViewController = vc {
|
||||
if let capturedImage = image {
|
||||
validVC.image = capturedImage
|
||||
self.navigationController?.pushViewController(validVC, animated: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
case .VideoWithMic, .VideoOnly:
|
||||
sender.selected = !sender.selected
|
||||
sender.setTitle(" ", forState: UIControlState.Selected)
|
||||
sender.backgroundColor = sender.selected ? UIColor.redColor() : UIColor.greenColor()
|
||||
if sender.selected {
|
||||
self.cameraManager.startRecordingVideo()
|
||||
case .videoWithMic, .videoOnly:
|
||||
sender.isSelected = !sender.isSelected
|
||||
sender.setTitle(" ", for: UIControlState.selected)
|
||||
sender.backgroundColor = sender.isSelected ? UIColor.red : UIColor.green
|
||||
if sender.isSelected {
|
||||
cameraManager.startRecordingVideo()
|
||||
} else {
|
||||
self.cameraManager.stopRecordingVideo({ (videoURL) -> Void in
|
||||
println(videoURL)
|
||||
cameraManager.stopVideoRecording({ (videoURL, error) -> Void in
|
||||
if let errorOccured = error {
|
||||
self.cameraManager.showErrorBlock("Error occurred", errorOccured.localizedDescription)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@IBAction func outputModeButtonTapped(sender: UIButton)
|
||||
{
|
||||
self.cameraManager.cameraOutputMode = self.cameraManager.cameraOutputMode == CameraOutputMode.VideoWithMic ? CameraOutputMode.StillImage : CameraOutputMode.VideoWithMic
|
||||
switch (self.cameraManager.cameraOutputMode) {
|
||||
case .StillImage:
|
||||
self.cameraButton.selected = false
|
||||
self.cameraButton.backgroundColor = UIColor.greenColor()
|
||||
sender.setTitle("Image", forState: UIControlState.Normal)
|
||||
case .VideoWithMic, .VideoOnly:
|
||||
sender.setTitle("Video", forState: UIControlState.Normal)
|
||||
@IBAction func outputModeButtonTapped(_ sender: UIButton) {
|
||||
|
||||
cameraManager.cameraOutputMode = cameraManager.cameraOutputMode == CameraOutputMode.videoWithMic ? CameraOutputMode.stillImage : CameraOutputMode.videoWithMic
|
||||
switch (cameraManager.cameraOutputMode) {
|
||||
case .stillImage:
|
||||
cameraButton.isSelected = false
|
||||
cameraButton.backgroundColor = UIColor.green
|
||||
sender.setTitle("Image", for: UIControlState())
|
||||
case .videoWithMic, .videoOnly:
|
||||
sender.setTitle("Video", for: UIControlState())
|
||||
}
|
||||
}
|
||||
|
||||
@IBAction func changeCameraDevice(sender: UIButton)
|
||||
{
|
||||
self.cameraManager.cameraDevice = self.cameraManager.cameraDevice == CameraDevice.Front ? CameraDevice.Back : CameraDevice.Front
|
||||
switch (self.cameraManager.cameraDevice) {
|
||||
case .Front:
|
||||
sender.setTitle("Front", forState: UIControlState.Normal)
|
||||
case .Back:
|
||||
sender.setTitle("Back", forState: UIControlState.Normal)
|
||||
@IBAction func changeCameraDevice(_ sender: UIButton) {
|
||||
|
||||
cameraManager.cameraDevice = cameraManager.cameraDevice == CameraDevice.front ? CameraDevice.back : CameraDevice.front
|
||||
switch (cameraManager.cameraDevice) {
|
||||
case .front:
|
||||
sender.setTitle("Front", for: UIControlState())
|
||||
case .back:
|
||||
sender.setTitle("Back", for: UIControlState())
|
||||
}
|
||||
}
|
||||
|
||||
@IBAction func askForCameraPermissions(_ sender: UIButton) {
|
||||
|
||||
cameraManager.askUserForCameraPermission({ permissionGranted in
|
||||
self.askForPermissionsButton.isHidden = true
|
||||
self.askForPermissionsLabel.isHidden = true
|
||||
self.askForPermissionsButton.alpha = 0
|
||||
self.askForPermissionsLabel.alpha = 0
|
||||
if permissionGranted {
|
||||
self.addCameraToView()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@IBAction func changeCameraQuality(_ sender: UIButton) {
|
||||
|
||||
switch (cameraManager.changeQualityMode()) {
|
||||
case .high:
|
||||
sender.setTitle("High", for: UIControlState())
|
||||
case .low:
|
||||
sender.setTitle("Low", for: UIControlState())
|
||||
case .medium:
|
||||
sender.setTitle("Medium", for: UIControlState())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue