CocoaPods trunk is moving to be read-only. Read more on the blog, there are 19 months to go.
TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Sep 2016 |
SPMSupports SPM | ✗ |
Maintained by Tatsuhiko Arai.
A Swift OpenSphericalCamera API library with Ricoh Theta S extension
import OpenSphericalCamera
// Construct OSC generic camera
let osc = OpenSphericalCamera(ipAddress: "192.168.1.1", httpPort: 80)
// Or, Ricoh THETA S camera
let osc = ThetaCamera()
// Set OSC API level 2 (for Ricoh THETA S)
self.osc.startSession { (data, response, error) in
if let data = data where error == nil {
if let jsonDic = try? NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers) as! NSDictionary, results = jsonDic["results"] as? NSDictionary, sessionId = results["sessionId"] as? String {
self.osc.setOptions(sessionId: sessionId, options: ["clientVersion": 2]) { (data, response, error) in
self.osc.closeSession(sessionId: sessionId)
}
} else {
// Assume clientVersion is equal or later than 2
}
}
}
// Take picture
self.osc.takePicture { (data, response, error) in
if let data = data where error == nil {
let jsonDic = try? NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers) as! NSDictionary
if let jsonDic = jsonDic, rawState = jsonDic["state"] as? String, state = OSCCommandState(rawValue: rawState) {
switch state {
case .InProgress:
/*
* Set execute commands' progressNeeded parameter true explicitly,
* except for getLivePreview, if you want this handler to be
* called back "inProgress". In any case, they are waiting for
* "done" or "error" internally.
*/
case .Done:
if let results = jsonDic["results"] as? NSDictionary, fileUrl = results["fileUrl"] as? String {
self.osc.get(fileUrl) { (data, response, error) in
dispatch_async(dispatch_get_main_queue()) {
self.previewView.image = UIImage(data: data!)
}
}
}
case .Error:
break // TODO
}
}
}
}
This library is licensed under MIT. Full license text is available in LICENSE.