혹시 강의하실때 사용하셨던 Xcode 버전을 알 수 있을까요?
420
작성한 질문수 1
모두 똑같이 적었는데 오류가 많이 납니다 ㅠㅠ
저는 10.2.1 사용합니다.
답변 4
0
앱딜리게이트
//
// 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
뷰 컨트롤러
//
// 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()
}
}
}
}
강좌소개의 overview
0
370
1
configure 메소드의 DispatchQueue.main
0
343
1
prepareForReuse 사용 방법
0
620
1
화면이 야곰님처럼 로드되지 않아 질문드립니다.
0
375
2
버튼 이미지 크기가 조절이 안 되는데 어떤 부분을 조정해야 할까요?
0
2179
1
코드블록 10-3-5 에러
1
207
0
info에서 자동완성이 나오지 않는데 따로 설정을 해주어야 하는 부분인가요?
0
264
1
star buton
0
362
1
Singleton 관련 질문.
0
251
1
로컬 유저 노티피케이션에서 반복 주기 설정 방법 문의 드립니다.
0
532
0
Todo 앱에서 로컬 노티피케이션 해제 시 질문 드립니다.
0
352
1
ios13이 생기고 변경점 관련
0
204
1
8번 프로젝트
0
189
1
todo 앱에서 파일 저장 기능에 대한 질문입니다.
0
270
1
todo앱 User Notification에서 질문이 있습니다
0
437
1
9번 프로젝트 질문
1
279
2
9번 프로젝트 자료 질문
0
260
1
8번 프로젝트 > 도전과제 2번 질문
0
214
2
Todo 앱에서 일정 추가가 바로 반영되지 않습니다.
1
435
6
Todo 앱에서 DateFormatter 사용 관련 질문 드립니다.
0
289
1
5번 프로젝트 - 나머지 화면 구성하기
1
192
1
웹브라우저 - 코드로 기능 구현하기
1
569
3
어시스던트에 매뉴얼이 없습니다.
0
256
1
제공된 코드블럭 파일
0
251
2





