Posts

Post not yet marked as solved
1 Replies
870 Views
Hello, I'm hoping someone can provide me with some suggestions as to how I can use a Firebase Database to store and update URLs to websites that are accessible within my app so that I do not have to upload a new version to the App Store every time a URL changes. Basically there are buttons throughout my app that open webviews using Safari Services. My problem is that many of the websites change or update their URLs, which then leads to errors when my users select the buttons to visit those websites. What I'd like to do is, when I find URLs that no longer work, to be able to update the various URLs in a Firebase Database without having to update the URLs within my app's code, requiring a full update through the App Store. Also, I currently have a Firebase Database that I've set up to store user information when they sign up, so I'm at least a little bit familiar with that aspect of Firebase. As always, thank you for your help!
Posted
by rlarock.
Last updated
.
Post marked as solved
2 Replies
1.4k Views
I have various view controllers that contain several buttons, and each button when pressed presents a view controller with a web view that displays the website. The full code I'm using, which work fine, for each is below. import UIKit import WebKit class WebViewController: UIViewController , WKNavigationDelegate, WKUIDelegate, UITextFieldDelegate { @IBOutlet weak var urlTextField: UITextField! @IBOutlet weak var himedWebView: WKWebView! @IBOutlet weak var actIndicator: UIActivityIndicatorView! @IBOutlet weak var webpageBack: UIButton! @IBOutlet weak var webpageForward: UIButton! override func viewDidLoad() { super.viewDidLoad() urlTextField.delegate = self himedWebView.navigationDelegate = self } // Do any additional setup after loading the view. override func viewDidAppear(_ animated: Bool) { super.viewDidAppear( animated ) let urlString:String = "http://www.google.com" let url:URL = URL(string: urlString)! let urlRequest:URLRequest = URLRequest(url: url) himedWebView.load(urlRequest) actIndicator.startAnimating() urlTextField.text = urlString } func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) { actIndicator.startAnimating() } func textFieldShouldReturn(_ textField: UITextField) -> Bool { let urlString:String = urlTextField.text! let url:URL = URL(string: urlString)! let urlRequest:URLRequest = URLRequest(url: url) himedWebView.load(urlRequest) urlTextField.resignFirstResponder() return true } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepare(for segue: UIStoryboardSegue, sender: Any?) { // Get the new view controller using segue.destinationViewController. // Pass the selected object to the new view controller. } */ @IBAction func fwdButtonTapped(_ sender: Any) { if himedWebView.canGoForward { himedWebView.goForward() } } @IBAction func backButtonTapped(_ sender: Any) { if himedWebView.canGoBack { himedWebView.goBack() } } func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { webpageBack.isEnabled = himedWebView.canGoBack webpageForward.isEnabled = himedWebView.canGoForward urlTextField.text = himedWebView.url?.absoluteString actIndicator.stopAnimating() actIndicator.hidesWhenStopped = true } @IBAction func webviewDone(_ sender: Any) { self.dismiss(animated: true, completion: nil) } }I want to significantly reduce the number of these individual view controllers by using a performSegue function that will access the various URLs through a single view controller w/web view using a segue identifier. I found an older post elsewhere online that asked a similar question, but I'm not sure how to integrate or replace my code with it.override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { let websiteController = segue.destinationViewController as YourVCName if segue.identifier == "website1" { websiteController.urlWebsite = "google.com" } else if segue.identifier == "website2" { websiteController.urlWebsite = "stackoverflow.com" } }Help would be greatly appreciated! Thanks,
Posted
by rlarock.
Last updated
.