-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from carrot-ar/gn/example
Example app
- Loading branch information
Showing
31 changed files
with
2,016 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
Example/ParrotExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
Example/ParrotExample.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// AppDelegate.swift | ||
// ParrotExample | ||
// | ||
// Created by Gonzalo Nunez on 11/16/17. | ||
// Copyright © 2017 carrot. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
@UIApplicationMain | ||
class AppDelegate: UIResponder, UIApplicationDelegate { | ||
|
||
var window: UIWindow? | ||
|
||
func application( | ||
_ application: UIApplication, | ||
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool | ||
{ | ||
window = UIWindow(frame: UIScreen.main.bounds) | ||
let vc = ViewController(nibName: nil, bundle: nil) | ||
window?.rootViewController = vc | ||
window?.makeKeyAndVisible() | ||
return true | ||
} | ||
} | ||
|
93 changes: 93 additions & 0 deletions
93
Example/ParrotExample/Assets.xcassets/AppIcon.appiconset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "20x20", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "20x20", | ||
"scale" : "3x" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "29x29", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "29x29", | ||
"scale" : "3x" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "40x40", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "40x40", | ||
"scale" : "3x" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "60x60", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "60x60", | ||
"scale" : "3x" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"size" : "20x20", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"size" : "20x20", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"size" : "29x29", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"size" : "29x29", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"size" : "40x40", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"size" : "40x40", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"size" : "76x76", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"size" : "76x76", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"size" : "83.5x83.5", | ||
"scale" : "2x" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" systemVersion="17A277" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM"> | ||
<dependencies> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/> | ||
<capability name="Safe area layout guides" minToolsVersion="9.0"/> | ||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | ||
</dependencies> | ||
<scenes> | ||
<!--View Controller--> | ||
<scene sceneID="EHf-IW-A2E"> | ||
<objects> | ||
<viewController id="01J-lp-oVM" sceneMemberID="viewController"> | ||
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3"> | ||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | ||
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/> | ||
</view> | ||
</viewController> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/> | ||
</objects> | ||
<point key="canvasLocation" x="53" y="375"/> | ||
</scene> | ||
</scenes> | ||
</document> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?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>$(DEVELOPMENT_LANGUAGE)</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>APPL</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleVersion</key> | ||
<string>1</string> | ||
<key>LSRequiresIPhoneOS</key> | ||
<true/> | ||
<key>UILaunchStoryboardName</key> | ||
<string>LaunchScreen</string> | ||
<key>UIRequiredDeviceCapabilities</key> | ||
<array> | ||
<string>armv7</string> | ||
</array> | ||
<key>NSLocationWhenInUseUsageDescription</key> | ||
<string>ParrotExample needs your location in order to monitor a CLBeaconRegion</string> | ||
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key> | ||
<string>ParrotExample needs your location in order to monitor a CLBeaconRegion</string> | ||
<key>UISupportedInterfaceOrientations</key> | ||
<array> | ||
<string>UIInterfaceOrientationPortrait</string> | ||
<string>UIInterfaceOrientationLandscapeLeft</string> | ||
<string>UIInterfaceOrientationLandscapeRight</string> | ||
</array> | ||
<key>UISupportedInterfaceOrientations~ipad</key> | ||
<array> | ||
<string>UIInterfaceOrientationPortrait</string> | ||
<string>UIInterfaceOrientationPortraitUpsideDown</string> | ||
<string>UIInterfaceOrientationLandscapeLeft</string> | ||
<string>UIInterfaceOrientationLandscapeRight</string> | ||
</array> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
// | ||
// ViewController.swift | ||
// ParrotExample | ||
// | ||
// Created by Gonzalo Nunez on 11/16/17. | ||
// Copyright © 2017 carrot. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import Parrot | ||
|
||
class ViewController: UIViewController { | ||
|
||
// MARK: Lifecycle | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
view.backgroundColor = .white | ||
|
||
view.addSubview(rangeSwitch) | ||
NSLayoutConstraint.activate([ | ||
rangeSwitch.centerXAnchor.constraint(equalTo: view.centerXAnchor), | ||
rangeSwitch.centerYAnchor.constraint(equalTo: view.centerYAnchor) | ||
]) | ||
|
||
let shouldRangeLabel = UILabel(frame: .zero) | ||
shouldRangeLabel.text = "Range" | ||
shouldRangeLabel.translatesAutoresizingMaskIntoConstraints = false | ||
view.addSubview(shouldRangeLabel) | ||
NSLayoutConstraint.activate([ | ||
shouldRangeLabel.leftAnchor.constraint(equalTo: rangeSwitch.rightAnchor, constant: 8), | ||
shouldRangeLabel.centerYAnchor.constraint(equalTo: rangeSwitch.centerYAnchor) | ||
]) | ||
|
||
infoLabel.text = "Idle..." | ||
infoLabel.translatesAutoresizingMaskIntoConstraints = false | ||
view.addSubview(infoLabel) | ||
NSLayoutConstraint.activate([ | ||
infoLabel.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 8), | ||
infoLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor) | ||
]) | ||
|
||
view.addSubview(startButton) | ||
NSLayoutConstraint.activate([ | ||
startButton.centerXAnchor.constraint(equalTo: view.centerXAnchor), | ||
startButton.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -16) | ||
]) | ||
} | ||
|
||
// MARK: Private | ||
|
||
private var advertiser: BeaconAdvertiser? | ||
private var monitor: BeaconMonitor? | ||
|
||
private enum State { | ||
case wantsMonitoring | ||
case wantsAdvertising | ||
case monitoring | ||
case advertising | ||
} | ||
|
||
private var state: State = .wantsAdvertising { | ||
didSet { handleStateChange(from: oldValue) } | ||
} | ||
|
||
lazy private var rangeSwitch: UISwitch = { | ||
let uiSwitch = UISwitch(frame: .zero) | ||
uiSwitch.translatesAutoresizingMaskIntoConstraints = false | ||
uiSwitch.addTarget(self, action: #selector(handleSwitch), for: .valueChanged) | ||
return uiSwitch | ||
}() | ||
|
||
lazy private var startButton: UIButton = { | ||
let button = UIButton(type: .system) | ||
button.translatesAutoresizingMaskIntoConstraints = false | ||
button.setTitle("Start", for: .normal) | ||
button.addTarget(self, action: #selector(handleStartButton), for: .touchUpInside) | ||
return button | ||
}() | ||
|
||
private var infoLabel = UILabel(frame: .zero) | ||
|
||
@objc private func handleSwitch(sender: Any) { | ||
let shouldRange = rangeSwitch.isOn | ||
state = shouldRange ? .wantsMonitoring : .wantsAdvertising | ||
} | ||
|
||
@objc private func handleStartButton(sender: Any) { | ||
let uuid = UUID(uuidString: "CFC5128B-96FD-40FD-A4C4-D099F22E9E64")! | ||
switch state { | ||
case .wantsMonitoring: | ||
monitor = BeaconMonitor( | ||
uuid: uuid, | ||
identifier: "com.ParrotExample.Beacon", | ||
params: .none) | ||
startButton.setTitle("Stop", for: .normal) | ||
state = .monitoring | ||
monitor?.startMonitoring( | ||
onProximityUpdate: { [weak self] monitor, proximity in | ||
switch proximity { | ||
case .unknown: | ||
self?.infoLabel.text = "Unknown..." | ||
case .far: | ||
self?.infoLabel.text = "Far..." | ||
case .near: | ||
self?.infoLabel.text = "Near..." | ||
case .immediate: | ||
self?.infoLabel.text = "Immediate!" | ||
} | ||
}, | ||
onError: { [weak self] error in | ||
print("ERROR: \(error)") | ||
self?.infoLabel.text = error.localizedDescription | ||
} | ||
) | ||
case .wantsAdvertising: | ||
advertiser = BeaconAdvertiser( | ||
uuid: uuid, | ||
identifier: "com.ParrotExample.Beacon", | ||
params: .none) | ||
startButton.setTitle("Stop", for: .normal) | ||
state = .advertising | ||
advertiser?.startAdvertising { [weak self] advertiser, state in | ||
self?.infoLabel.text = "\(state)...".capitalized | ||
} | ||
case .monitoring: | ||
startButton.setTitle("Start", for: .normal) | ||
monitor?.stopMonitoring() | ||
state = .wantsMonitoring | ||
case .advertising: | ||
startButton.setTitle("Start", for: .normal) | ||
advertiser?.stopAdvertising() | ||
state = .wantsAdvertising | ||
} | ||
} | ||
|
||
private func handleStateChange(from previous: State) { | ||
switch (state, previous) { | ||
case (.wantsMonitoring, .wantsAdvertising): | ||
advertiser = nil | ||
startButton.setTitle("Start", for: .normal) | ||
self.infoLabel.text = "Idle..." | ||
case (.wantsAdvertising, .wantsMonitoring): | ||
monitor = nil | ||
startButton.setTitle("Start", for: .normal) | ||
self.infoLabel.text = "Idle..." | ||
default: | ||
break | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?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>$(DEVELOPMENT_LANGUAGE)</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>BNDL</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleVersion</key> | ||
<string>1</string> | ||
</dict> | ||
</plist> |
Oops, something went wrong.