         if (prefItemType == "PSChildPaneSpecifier") {
           let prefItemFile = prefItem["File"]  as? String
           loadDefaults(&appDefaults, fromSettingsPage: prefItemFile!, inSettingsBundleAt: settingsBundleURL)
-        }
-        else if (prefItemKey != nil) && (prefItemDefaultValue != nil) {
+        } else if (prefItemKey != nil) && (prefItemDefaultValue != nil) {
           appDefaults[prefItemKey!] = prefItemDefaultValue
         }
       }

import AVFoundation
import GoogleCast

let kPrefPreloadTime: String = "preload_time_sec"

let kPrefEnableAnalyticsLogging: String = "enable_analytics_logging"

let kPrefEnableSDKLogging: String = "enable_sdk_logging"

let kPrefAppVersion: String = "app_version"

let kPrefSDKVersion: String = "sdk_version"

let kPrefReceiverAppID: String = "receiver_app_id"

let kPrefCustomReceiverSelectedValue: String = "use_custom_receiver_app_id"

let kPrefCustomReceiverAppID: String = "custom_receiver_app_id"

let kPrefEnableMediaNotifications: String = "enable_media_notifications"

let kApplicationID: String? = nil

let appDelegate = (UIApplication.shared.delegate as? AppDelegate)

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GCKLoggerDelegate, GCKSessionManagerListener, GCKUIImagePicker {
  var enableSDKLogging = false
  var mediaNotificationsEnabled = false
  var firstUserDefaultsSync = false

    if (prefApplicationID == kPrefCustomReceiverSelectedValue) {
      prefApplicationID = userDefaults.string(forKey: kPrefCustomReceiverAppID)
    }
    if prefApplicationID == nil {
      let message: String = "You don't seem to have an application ID.\n" +
      "Please fix the app settings."
      showAlert(withTitle: "Invalid Receiver Application ID", message: message)
      return nil
    } else {
      let appIdRegex = try? NSRegularExpression(pattern: "\\b[0-9A-F]{8}\\b", options: [])
      let rangeToCheck = NSRange(location: 0, length: (prefApplicationID?.characters.count ?? 0))
      let numberOfMatches = appIdRegex?.numberOfMatches(in: prefApplicationID!,
                                                        options: [],
                                                        range: rangeToCheck)
      if numberOfMatches == 0 {
        let message: String = "\"\(prefApplicationID)\" is not a valid application ID\n" +
        "Please fix the app settings (should be 8 hex digits, in CAPS)"
        showAlert(withTitle: "Invalid Receiver Application ID", message: message)
        return nil
      }
    }
    return prefApplicationID
  }

  func syncWithUserDefaults() {
    let userDefaults = UserDefaults.standard
    // Forcing no logging from the SDK
    enableSDKLogging = false
    let mediaNotificationsEnabled = userDefaults.bool(forKey: kPrefEnableMediaNotifications)
    GCKLogger.sharedInstance().delegate?.logMessage?("Notifications on? \(mediaNotificationsEnabled)", fromFunction: #function)
    if firstUserDefaultsSync || (self.mediaNotificationsEnabled != mediaNotificationsEnabled) {
      self.mediaNotificationsEnabled = mediaNotificationsEnabled
      if useCastContainerViewController {
        let castContainerVC = (window?.rootViewController as? GCKUICastContainerViewController)
        castContainerVC?.miniMediaControlsItemEnabled = mediaNotificationsEnabled
      }
      else {
        let rootContainerVC = (window?.rootViewController as? RootContainerViewController)
        rootContainerVC?.miniMediaControlsViewEnabled = mediaNotificationsEnabled
      }
    }
    firstUserDefaultsSync = false
  }
}

// MARK: - GCKLoggerDelegate
extension AppDelegate: GCKLoggerDelegate {
  func logMessage(_ message: String, fromFunction function: String) {
    if enableSDKLogging {
      // Send SDK's log messages directly to the console.
      print("\(function)  \(message)")
    }
  }

}

// MARK: - GCKSessionManagerListener
extension AppDelegate: GCKSessionManagerListener {

  func sessionManager(_ sessionManager: GCKSessionManager, didEnd session: GCKSession, withError error: Error?) {
    if error == nil {
      Toast.displayMessage("Session ended", for: 3, in: (window?.rootViewController?.view)!)
    } else {
      let message = "Session ended unexpectedly:\n\(error?.localizedDescription)"
      showAlert(withTitle: "Session error", message: message)
    }
