devdanbee
@devdanbee
Reviews Written
1
Average Rating
5.0
Posts
Q&A
ํน์ ๊ฐ์ํ์ค๋ ์ฌ์ฉํ์ จ๋ Xcode ๋ฒ์ ์ ์ ์ ์์๊น์?
์ด๋ป๊ฒ ๊ณ ์ณ์ผ Runํ์๋ ์ ์์ ์ผ๋ก ์๋ ๋ ๊น์...?
- 0
- 4
- 395
Q&A
ํน์ ๊ฐ์ํ์ค๋ ์ฌ์ฉํ์ จ๋ Xcode ๋ฒ์ ์ ์ ์ ์์๊น์?
๋ช๊ฐ์ง๋ fix ๋๋ฌ์ ๊ณ ์ณ์ ์กฐ๊ธ ์์ ๋์์๊ฑฐ์์. ์ง๊ธ ์๋ฌ๊ฐ 8๊ฐ ๋ฉ๋๋ค ใ ใ
- 0
- 4
- 395
Q&A
ํน์ ๊ฐ์ํ์ค๋ ์ฌ์ฉํ์ จ๋ Xcode ๋ฒ์ ์ ์ ์ ์์๊น์?
์ฑ๋๋ฆฌ๊ฒ์ดํธ // // AppDelegate.swift // MyWebBrowser // // Created by ๋ฐ๋จ๋น on 15/05/2019. // Copyright ยฉ 2019 ๋ฐ๋จ๋น. All rights reserved. // import UIKit /// ๋ง์ง๋ง ํ์ด์ง ์ฃผ์๋ฅผ UserDefaults์์ ๊ด๋ฆฌํ๊ธฐ ์ํ ํค ๊ฐ let lastPageURLDefaultKey: String = "lastURL" @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { // MARK: - Properties var window: UIWindow? var lastPageURL: URL? // MARK: - Methods func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. self.lastPageURL = UserDefaults.standard.url(forKey: lastPageURLDefaultKey) return true } func applicationWillResignActive(_ application: UIApplication) { let userDefaults: UserDefaults userDefaults = UserDefaults.standard UserDefaults.set(self.lastPageURL, forKey: lastPageURLDefaultKey) userDefaults.synchronize() } func applicationDidEnterBackground(_ application: UIApplication) { } func applicationWillEnterForeground(_ application: UIApplication) { // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. } func applicationDidBecomeActive(_ application: UIApplication) { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } func applicationWillTerminate(_ application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } }
- 0
- 4
- 395
Q&A
ํน์ ๊ฐ์ํ์ค๋ ์ฌ์ฉํ์ จ๋ Xcode ๋ฒ์ ์ ์ ์ ์์๊น์?
๋ทฐ ์ปจํธ๋กค๋ฌ // // ViewController.swift // MyWebBrowser // // Created by ๋ฐ๋จ๋น on 15/05/2019. // Copyright ยฉ 2019 ๋ฐ๋จ๋น. All rights reserved. // import UIKit import WebKit class ViewController: UIViewController { //MARK: - Properties //MARK: IBOutlets @IBOutlet var webView: WKWebView! @IBOutlet var activityIndicator: UIActivityIndicatorView! //MARK: - Methods //MARK: Life Cycle override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. self.webView.navigationDelegate = self as? WKNavigationDelegate } override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) let firstPageURL: URL? if let lastURL: URL = UserDefaults.standard.url(forKey: lastPageURLDefaultKey) { firstPageURL = lastURL } else { firstPageURL = URL(string: "https://www.google.com") } guard let pageURL: URL = firstPageURL else { return } let urlRequest: URLRequest = URLRequest(url: pageURL) self.webView.load(urlRequest) } // MARK: IBActions @IBAction func goBack(_ sender: UIBarButtonItem) { self.webView.goBack() } @IBAction func goForward(_ sender: UIBarButtonItem) { self.webView.goForward() } @IBAction func refresh(_ sender: UIBarButtonItem) { self.webView.reload() //MARK: Custom Methods func showNetworkingIndicators() { self.activityIndicator.isHidden = false self.activityIndicator.startAnimating() UIApplication.shared.isNetworkActivityIndicatorVisible = true func hideNetworkingIndicators() { self.activityIndicator.isHidden = true self.activityIndicator.stopAnimating() UIApplication.shared.isNetworkActivityIndicatorVisible = false } } extension ViewController: WKNavigationDelegate { // MARK : WKNavigationDelegate func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { print("did finish navigation") if let appDelegate: AppDelegate = UIApplication.shared.delegate as? AppDelegate { AppDelegate.lastPageURL = webView.url } webView.evaluateJavaScript("document.title") { (value: Any?, error: Error?) in if let error: Error = error { print(error.localizedDescription) return } guard let title: String = value as? String else { return } self.navigationItem.title = title } self.hideNetworkingIndicators() } func webView(_ webView, didFail navigation: WKNavigation!, withError error: Error) { print("did fail navigation") print("\(error.localizedDescription)") self.hideNetworkingIndicators() let message: String = "์ค๋ฅ๋ฐ์!\n" + error.localizedDescription let alert: UIAlertController alert = UIAlertController(title: "์๋ฆผ", message, preferredStyle: UIAlertController.alert) let okayaction: UIAlertAction okayaction = UIAlertAction(title: "ํ์ธ", style: UIAlertAction.Style.cancel, handler: nil) alert.addAction(okayaction) self.present(alert, animated: true, completion: nil) } func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) { print("did start navigation") self.showNetworkingIndicators() } } } }
- 0
- 4
- 395




