Skip to content

Commit

Permalink
Fix Bug where Disabled EmoitonKit was causing Crash due to missing Ca…
Browse files Browse the repository at this point in the history
…mera Capabilities

Squashed commit of the following:
Author: Lara Marie Reimer <laramarie@reimer.io>

  - Refactor
  - Make sure to check if enabled before starting thinking aloud and emotionkit
  • Loading branch information
jpbernius committed Nov 23, 2018
1 parent 747a404 commit 7111a70
Show file tree
Hide file tree
Showing 19 changed files with 101 additions and 43 deletions.
2 changes: 1 addition & 1 deletion CUU.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'CUU'
s.version = '2.0.3'
s.version = '2.0.4'
s.summary = 'CUU is a framework to help analyzing the usage of your applications.'

# This description is used to generate tags and improve search results.
Expand Down
8 changes: 8 additions & 0 deletions CUU/Classes/CUU.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,12 @@ public class CUU {

featureKit.handleAdditionalCrumbActionsForFeatures(with: actionCrumb)
}

static func isActivated(for kit: CUUStartOption) -> Bool {
if let options = UserDefaults.standard.array(forKey: CUUConstants.CUUUserDefaultsKeys.optionsKey) as? [Int] {
let values = options.map({ CUUStartOption(rawValue: $0) })
return values.contains(kit)
}
return false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ open class CUUActivityViewController: UIActivityViewController {

override open func viewDidLoad() {
super.viewDidLoad()
emotionsKitSetupTracking()

if CUU.isActivated(for: .Emotions) {
emotionsKitSetupTracking()
}
}

override open func viewDidAppear(_ animated: Bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ open class CUUCloudSharingController: UICloudSharingController {

override open func viewDidLoad() {
super.viewDidLoad()
emotionsKitSetupTracking()

if CUU.isActivated(for: .Emotions) {
emotionsKitSetupTracking()
}
}

override open func viewDidAppear(_ animated: Bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ open class CUUCollectionViewController: UICollectionViewController {

override open func viewDidLoad() {
super.viewDidLoad()
emotionsKitSetupTracking()

if CUU.isActivated(for: .Emotions) {
emotionsKitSetupTracking()
}
}

override open func viewDidAppear(_ animated: Bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ open class CUUDocumentBrowserViewController: UIDocumentBrowserViewController {

override open func viewDidLoad() {
super.viewDidLoad()
emotionsKitSetupTracking()

if CUU.isActivated(for: .Emotions) {
emotionsKitSetupTracking()
}
}

override open func viewDidAppear(_ animated: Bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ open class CUUDocumentPickerViewController: UIDocumentPickerViewController {

override open func viewDidLoad() {
super.viewDidLoad()
emotionsKitSetupTracking()

if CUU.isActivated(for: .Emotions) {
emotionsKitSetupTracking()
}
}

override open func viewDidAppear(_ animated: Bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ open class CUUImagePickerController: UIImagePickerController {

override open func viewDidLoad() {
super.viewDidLoad()
emotionsKitSetupTracking()

if CUU.isActivated(for: .Emotions) {
emotionsKitSetupTracking()
}
}

override open func viewDidAppear(_ animated: Bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ open class CUUNavigationController: UINavigationController {

override open func viewDidLoad() {
super.viewDidLoad()
emotionsKitSetupTracking()

if CUU.isActivated(for: .Emotions) {
emotionsKitSetupTracking()
}
}

override open func viewDidAppear(_ animated: Bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ open class CUUPageViewController: UIPageViewController {

override open func viewDidLoad() {
super.viewDidLoad()
emotionsKitSetupTracking()

if CUU.isActivated(for: .Emotions) {
emotionsKitSetupTracking()
}
}

override open func viewDidAppear(_ animated: Bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ open class CUUReferenceLibraryViewController: UIReferenceLibraryViewController {

override open func viewDidLoad() {
super.viewDidLoad()
emotionsKitSetupTracking()

if CUU.isActivated(for: .Emotions) {
emotionsKitSetupTracking()
}
}

override open func viewDidAppear(_ animated: Bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ open class CUUSearchContainerViewController: UISearchContainerViewController {

override open func viewDidLoad() {
super.viewDidLoad()
emotionsKitSetupTracking()

if CUU.isActivated(for: .Emotions) {
emotionsKitSetupTracking()
}
}

override open func viewDidAppear(_ animated: Bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ open class CUUSearchController: UISearchController {

override open func viewDidLoad() {
super.viewDidLoad()
emotionsKitSetupTracking()

if CUU.isActivated(for: .Emotions) {
emotionsKitSetupTracking()
}
}

override open func viewDidAppear(_ animated: Bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ open class CUUSplitViewController: UISplitViewController {

override open func viewDidLoad() {
super.viewDidLoad()
emotionsKitSetupTracking()

if CUU.isActivated(for: .Emotions) {
emotionsKitSetupTracking()
}
}

override open func viewDidAppear(_ animated: Bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ open class CUUTabBarController: UITabBarController {

override open func viewDidLoad() {
super.viewDidLoad()
emotionsKitSetupTracking()

if CUU.isActivated(for: .Emotions) {
emotionsKitSetupTracking()
}
}

override open func viewDidAppear(_ animated: Bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ open class CUUTableViewController: UITableViewController {

override open func viewDidLoad() {
super.viewDidLoad()
emotionsKitSetupTracking()

if CUU.isActivated(for: .Emotions) {
emotionsKitSetupTracking()
}
}

override open func viewDidAppear(_ animated: Bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ open class CUUVideoEditorController: UIVideoEditorController {

override open func viewDidLoad() {
super.viewDidLoad()
emotionsKitSetupTracking()

if CUU.isActivated(for: .Emotions) {
emotionsKitSetupTracking()
}
}

override open func viewDidAppear(_ animated: Bool) {
Expand Down
7 changes: 5 additions & 2 deletions CUU/Classes/CUUCore/ViewControllers/CUUViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ open class CUUViewController: UIViewController {

override open func viewDidLoad() {
super.viewDidLoad()
emotionsKitSetupTracking()

if CUU.isActivated(for: .Emotions) {
emotionsKitSetupTracking()
}
}

override open func viewDidAppear(_ animated: Bool) {
Expand Down Expand Up @@ -93,4 +96,4 @@ extension CUUViewController: ARSessionDelegate {
self.emotionsKitResetTracking()
}
}
}
}
52 changes: 27 additions & 25 deletions CUU/Classes/ThinkingAloudKit/ThinkingAloudController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,33 @@ class ThinkingAloudController : ThinkingAloudStartViewControllerDelegate, Thinki
@objc func crumbReceived(notification: NSNotification) {
let payload = notification.userInfo

let featureArray = CUUUserManager.sharedManager.completedThinkingAloudFeatures
if let payload = payload,
let feature = payload["feature"] as? CUUFeature,
let isFirst = payload["isFirst"] as? Bool,
let isLast = payload["isLast"] as? Bool,
let crumbId = payload["crumbId"] as? String {
if (!featureArray.contains(String(feature.id))) {
if !isActive && isFirst && !isLast {
DispatchQueue.main.asyncAfter(deadline: .now()) {
self.currentFeature = feature
self.previousCrumbId = crumbId
self.start()
}
} else {
if let currentFeature = currentFeature {
if feature.id == currentFeature.id {
if (isLast) {
guard let id = previousCrumbId else { return }
stop(for: id)
previousCrumbId = crumbId
} else {
guard let id = previousCrumbId else { return }
stopRecording(isLast: false, for: id)
previousCrumbId = crumbId
startRecording()
if CUU.isActivated(for: .ThinkingAloud) {
let featureArray = CUUUserManager.sharedManager.completedThinkingAloudFeatures
if let payload = payload,
let feature = payload["feature"] as? CUUFeature,
let isFirst = payload["isFirst"] as? Bool,
let isLast = payload["isLast"] as? Bool,
let crumbId = payload["crumbId"] as? String {
if (!featureArray.contains(String(feature.id))) {
if !isActive && isFirst && !isLast {
DispatchQueue.main.asyncAfter(deadline: .now()) {
self.currentFeature = feature
self.previousCrumbId = crumbId
self.start()
}
} else {
if let currentFeature = currentFeature {
if feature.id == currentFeature.id {
if (isLast) {
guard let id = previousCrumbId else { return }
stop(for: id)
previousCrumbId = crumbId
} else {
guard let id = previousCrumbId else { return }
stopRecording(isLast: false, for: id)
previousCrumbId = crumbId
startRecording()
}
}
}
}
Expand Down

0 comments on commit 7111a70

Please sign in to comment.