         }
         else {
             // Otherwise use iPhone style action sheet presentation.
-            let window = UIApplication.sharedApplication().delegate!.window as! UIWindow
+            // UIWindow hack: http://stackoverflow.com/a/28902549/300224
+            let window = (UIApplication.sharedApplication().delegate!.window ?? nil)! as UIWindow
             let topVC = topViewController(presentingViewController)
-            if window?.subviews.contains(topVC.view!) {
+            if window.subviews.contains(topVC.view!) {
                 actionSheet.showInView(topVC.view)
             }
             else {

    public func dismiss() {
        if let actionSheet = self.actionSheet {
            actionSheet.dismissWithClickedButtonIndex(sources.count, animated: false)
        }
        else if imagePicker != nil {
            imagePicker.dismissViewControllerAnimated(false, completion: nil)
        }
        else {
            NSLog("Other view")
        }
    }
}

extension FDTakeController : UIActionSheetDelegate {
    public func actionSheet(actionSheet: UIActionSheet, didDismissWithButtonIndex buttonIndex: Int) {
        var aViewController: UIViewController = self.topViewController(self.presentingViewController)
        if buttonIndex == actionSheet.cancelButtonIndex {
            self.didDeny?()
        } else {

        }
        
        picker.dismissViewControllerAnimated(true, completion: nil)
    }
    
    public func imagePickerControllerDidCancel(picker: UIImagePickerController) {
        UIApplication.sharedApplication().statusBarHidden = true
        picker.dismissViewControllerAnimated(true, completion: { _ in })
        self.didCancel?()
    }
}
