Latest 3.0.0
Homepage https://github.com/tatsu/OpenSphericalCamera
License MIT
Platforms ios 9.0
Authors

OpenSphericalCamera Client in Swift

A Swift OpenSphericalCamera API library with Ricoh Theta S extension

Requirements

branch Swift(Xcode) OSC API Level THETA API Ver. Release
master 3 (8.0+) 2 & 1 2.1 & 2.0 3.0.0
osc-v2-swift2.3 2.3 (8.0+) 2 & 1 2.1 & 2.0 2.1.0
osc-v2-swift2.2 2.2+ (7.3+) 2 & 1 2.1 & 2.0 2.0.0
osc-v1-swift2.2 2.2+ (7.3+) 1 2.0 1.0.1

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate OpenSphericalCamera into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!

target '<Your Target Name>' do
  pod 'OpenSphericalCamera', '~> 3.0.0'
end

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate OpenSphericalCamera into your Xcode project using Carthage, specify it in your Cartfile:

github "tatsu/OpenSphericalCamera" ~> 3.0.0

Run carthage update to build the framework and drag the built OpenSphericalCamera.framework into your Xcode project.

Usage

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 , error == nil {
        if let jsonDic = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.mutableContainers) as! [String: Any], let results = jsonDic["results"] as? [String: Any], let 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, error == nil {
        let jsonDic = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.mutableContainers) as! [String: Any]
        if let jsonDic = jsonDic, let rawState = jsonDic["state"] as? String, let 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? [String: Any], let fileUrl = results["fileUrl"] as? String {
                    // Get file
                    self.osc.get(fileUrl) { (data, response, error) in
                        if let data = data , error == nil {
                            DispatchQueue.main.async {
                                self.previewView.image = UIImage(data: data)
                            }
                        }
                    }
                }
            case .Error:
                break // TODO
            }
        }
    }
}

Sample App

References

License

This library is licensed under MIT. Full license text is available in LICENSE.

Latest podspec

{
    "name": "OpenSphericalCamera",
    "version": "3.0.0",
    "summary": "OpenSphericalCamera API Client in Swift",
    "description": "A Swift OpenSphericalCamera API library with Ricoh Theta S extension",
    "homepage": "https://github.com/tatsu/OpenSphericalCamera",
    "license": "MIT",
    "authors": {
        "Tatsuhiko Arai": "tatsu@tatsu.com"
    },
    "platforms": {
        "ios": "9.0"
    },
    "source": {
        "git": "https://github.com/tatsu/OpenSphericalCamera.git",
        "tag": "3.0.0"
    },
    "source_files": [
        "OpenSphericalCamera",
        "OpenSphericalCamera/**/*.swift"
    ]
}

Pin It on Pinterest

Share This