 import Alamofire
 import MessageUI
 import Shared
-
-#if MOZ_CHANNEL_AURORA
-/*
- A workaround for an issue with MFMailComposerViewController:
-http://stackoverflow.com/questions/25604552/i-have-real-misunderstanding-with-mfmailcomposeviewcontroller-in-swift-ios8-in
-
- Also, MFMailComposeViewController doesn't work in the iOS 8 simulator.
-*/
-private var mailComposer: MFMailComposeViewController!
-#endif
 
 @UIApplicationMain
 class AppDelegate: UIResponder, UIApplicationDelegate {

        self.window.makeKeyAndVisible()

#if MOZ_CHANNEL_AURORA
        mailComposer = MFMailComposeViewController()
        checkForAuroraUpdate()
        registerFeedbackNotification()
#endif

    
extension AppDelegate: MFMailComposeViewControllerDelegate {
    func sendFeedbackMailWithImage(image: UIImage) {
        if (MFMailComposeViewController.canSendMail()) {
            let appVersion = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleShortVersionString") as String
            let buildNumber = NSBundle.mainBundle().objectForInfoDictionaryKey(kCFBundleVersionKey) as String

            let mailComposeViewController = MFMailComposeViewController()
            mailComposeViewController.mailComposeDelegate = self
            mailComposeViewController.setSubject("Feedback on iOS client version v\(appVersion) (\(buildNumber))")
            mailComposeViewController.setToRecipients(["ios-feedback@mozilla.com"])
            
            let imageData = UIImagePNGRepresentation(image)
            mailComposeViewController.addAttachmentData(imageData, mimeType: "image/png", fileName: "feedback.png")
            self.window.rootViewController?.presentViewController(mailComposeViewController, animated: true, completion: nil)
        }
    }
    
    func mailComposeController(mailComposeViewController: MFMailComposeViewController!, didFinishWithResult result: MFMailComposeResult, error: NSError!) {
        mailComposeViewController.dismissViewControllerAnimated(true, completion: nil)
    }
}
#endif
