// // ExternalWebViewController.swift // Vendoo // // Created by Okechi Onyeje on 12/29/16. // Copyright © 2016 Okechi Onyeje. All rights reserved. // import UIKit enum WebContent { case FAQ case GetStarted } class ExternalWebViewController: UIViewController, UIWebViewDelegate { @IBOutlet weak var webView: UIWebView! @IBOutlet weak var webViewSelector: UISegmentedControl! //var activity: UIActivityIndicatorView! //contanst urls for the various app web documents on hosted website final let privPolicy = "http://vendoo.co/privacy-policy/" final let termsCond = "http://vendoo.co/terms-conditions/" final let getStarted = "http://vendoo.co" var allowLoad = true var currIndex: Int! var contentStringUrlType: String? var content: WebContent! var url: NSURL! //controller selection override func viewDidLoad() { super.viewDidLoad() contentStringUrlType = (NSUserDefaults.standardUserDefaults().objectForKey("whichContent") as? String) //content = ((contentStringUrlType == "FAQ") ? WebContent.FAQ : WebContent.GetStarted) self.webView.delegate = self self.webView.dataDetectorTypes = UIDataDetectorTypes.None // Do any additional setup after loading the view. //self.activity = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.Gray) //self.activity.color = UIColor.purpleColor() //self.activity.backgroundColor = UIColor.grayColor() //self.activity.frame = self.webView.frame; content = ((contentStringUrlType == "FAQ") ? WebContent.FAQ : WebContent.GetStarted) if (self.content == WebContent.FAQ){ webViewSelector.hidden = false webViewSelector.enabled = true if(webViewSelector.selectedSegmentIndex == 0){ url = NSURL (string: termsCond) }else{ url = NSURL (string: privPolicy) } currIndex = webViewSelector.selectedSegmentIndex }else{ webViewSelector.hidden = true webViewSelector.enabled = false url = NSURL (string: getStarted); } let requestObj = NSURLRequest(URL: url!); webView.loadRequest(requestObj); } /* // MARK: - WebView */ func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool { return allowLoad } func webViewDidFinishLoad(webView: UIWebView) { allowLoad = false } /* //MARK: - SegmentControl */ @IBAction func segSwitcher(sender: UISegmentedControl) { if(!(self.currIndex == self.webViewSelector.selectedSegmentIndex)){ if (self.webViewSelector.selectedSegmentIndex == 0){ let requestObj = NSURLRequest(URL: NSURL (string: termsCond)!); webView.loadRequest(requestObj); }else{ let requestObj = NSURLRequest(URL: NSURL (string: privPolicy)!); webView.loadRequest(requestObj); } self.currIndex = self.webViewSelector.selectedSegmentIndex self.allowLoad = true } } @IBAction func navigateBack(sender: UIButton) { let storyboard = UIStoryboard(name: "Main", bundle: nil) let vc = storyboard.instantiateViewControllerWithIdentifier("Reveal View Controller") self.presentViewController(vc, animated: true, completion: { NSUserDefaults.standardUserDefaults().removeObjectForKey("whichContent") //self.parentViewController!.dismissViewControllerAnimated(true, completion: nil) }) } /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { // Get the new view controller using segue.destinationViewController. // Pass the selected object to the new view controller. } */ }