Skip to content

Commit

Permalink
Merge pull request #91 from Jae-eun/webviewError
Browse files Browse the repository at this point in the history
즐겨찾기 등록 & 웹뷰 에러 해결
  • Loading branch information
eojine authored May 1, 2019
2 parents 28a62fb + a83f7ec commit 98be9be
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 28 deletions.
8 changes: 8 additions & 0 deletions Toonie.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
92D88D4D5D1ACC0BB983D7797079C87C /* DetailToonService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E371E0D955FBC2867AD25C4BD72ABF4 /* DetailToonService.swift */; };
687C00FF78A900251B747635F98172EC /* DetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4C42DB5B38C27C2E993254790693BDF /* DetailViewController.swift */; };
558FAE24BC1D46AEE96A7839D2EECDF9 /* FavoriteCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6181A5BE3CAF62901728B8DEC5745044 /* FavoriteCollectionViewCell.swift */; };
1FDC495E51E4103A48DBE746A3B5742F /* FavoriteService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 384EC31B5698BBD32C8427B4D3D3FA9E /* FavoriteService.swift */; };
AEEF2D26F2272450934285EA171238A5 /* FavoriteToon.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9A15E6123D0B310EBC6C8200A8A7BCE /* FavoriteToon.swift */; };
461C3F46EE79F602B9C6DC249B3A419C /* Feed.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 482A114E8A6A879454C3CB47C1BA9443 /* Feed.storyboard */; };
C9355A5FA67D262F35C7B8B185D2CA62 /* FeedViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7BD45CDB0C7E1A8A0FE2DB9C0C25B75 /* FeedViewController.swift */; };
6931E65B235D9EF98AF252FC0326C078 /* ForYouCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C59DFBC67BAFC0446C4ACC3CD30166 /* ForYouCollectionViewCell.swift */; };
Expand Down Expand Up @@ -108,6 +110,8 @@
2E371E0D955FBC2867AD25C4BD72ABF4 /* DetailToonService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailToonService.swift; sourceTree = "<group>"; };
E4C42DB5B38C27C2E993254790693BDF /* DetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailViewController.swift; sourceTree = "<group>"; };
6181A5BE3CAF62901728B8DEC5745044 /* FavoriteCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoriteCollectionViewCell.swift; sourceTree = "<group>"; };
384EC31B5698BBD32C8427B4D3D3FA9E /* FavoriteService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoriteService.swift; sourceTree = "<group>"; };
B9A15E6123D0B310EBC6C8200A8A7BCE /* FavoriteToon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoriteToon.swift; sourceTree = "<group>"; };
482A114E8A6A879454C3CB47C1BA9443 /* Feed.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Feed.storyboard; sourceTree = "<group>"; };
D7BD45CDB0C7E1A8A0FE2DB9C0C25B75 /* FeedViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedViewController.swift; sourceTree = "<group>"; };
C3C59DFBC67BAFC0446C4ACC3CD30166 /* ForYouCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForYouCollectionViewCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -326,6 +330,7 @@
isa = PBXGroup;
children = (
5C0F9FDA6D7EDBB6CC18F7B48E4304F5 /* DetailToon.swift */,
B9A15E6123D0B310EBC6C8200A8A7BCE /* FavoriteToon.swift */,
92086364F206D590B0D7FF7BD726FD80 /* ForYouToonLists.swift */,
9222FD8324DC3A507BC365062CF19A15 /* Keywords.swift */,
7ACAA8940643DB9FC71B7E231C435FD6 /* Recommends.swift */,
Expand Down Expand Up @@ -380,6 +385,7 @@
children = (
F0DFADE2E74674626C62C5847756D7C3 /* CurationTagService.swift */,
2E371E0D955FBC2867AD25C4BD72ABF4 /* DetailToonService.swift */,
384EC31B5698BBD32C8427B4D3D3FA9E /* FavoriteService.swift */,
919CB7352060E4267D23B8B6D5169BEC /* ForYouToonListService.swift */,
BF827ADC08C996D3C51D60BE675C7641 /* KeywordsService.swift */,
FBB7847F6E2C082500A180183EDA27D6 /* RecommendService.swift */,
Expand Down Expand Up @@ -737,6 +743,8 @@
92D88D4D5D1ACC0BB983D7797079C87C /* DetailToonService.swift in Sources */,
687C00FF78A900251B747635F98172EC /* DetailViewController.swift in Sources */,
558FAE24BC1D46AEE96A7839D2EECDF9 /* FavoriteCollectionViewCell.swift in Sources */,
1FDC495E51E4103A48DBE746A3B5742F /* FavoriteService.swift in Sources */,
AEEF2D26F2272450934285EA171238A5 /* FavoriteToon.swift in Sources */,
C9355A5FA67D262F35C7B8B185D2CA62 /* FeedViewController.swift in Sources */,
6931E65B235D9EF98AF252FC0326C078 /* ForYouCollectionViewCell.swift in Sources */,
EB475B47E259D7432C73537026F9FF8D /* ForYouToonListService.swift in Sources */,
Expand Down
13 changes: 11 additions & 2 deletions Toonie/Detail/Controller/DetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,22 @@ final class DetailToonViewController: GestureViewController {
as? ToonWebViewController {
viewController.modalTransitionStyle = UIModalTransitionStyle.coverVertical
viewController.toonUrl = detailToon?.instaUrl
viewController.instaID = detailToon?.instaID
self.present(viewController, animated: true, completion: nil)
}
}

/// 툰 찜하기
@IBAction func addToMyCollection(_ sender: UIButton) {
@IBAction func addToMyFavorite(_ sender: UIButton) {
let body = [
"workListName": "default",
"workListInfo": "찜한 목록",
"toonId": detailToon?.toonID
]

FavoriteService.shared.postFavoriteToon(params: body as [String : Any],
completion: {
print("Success to add favorite toon")
})
}

// MARK: - Life Cycle
Expand Down
27 changes: 15 additions & 12 deletions Toonie/Detail/Controller/ToonWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ final class ToonWebViewController: UIViewController, WKNavigationDelegate {
// MARK: - Property

var toonUrl: String?
var instaID: String?

// MARK: - IBOutlet

Expand All @@ -30,8 +29,8 @@ final class ToonWebViewController: UIViewController, WKNavigationDelegate {
override func viewDidLoad() {
super.viewDidLoad()

instagramWebView.navigationDelegate = self
loadWebView()
setLabel(instaId: instaID ?? "", url: toonUrl ?? "https://www.instagram.com/")
}

override var preferredStatusBarStyle: UIStatusBarStyle {
Expand All @@ -48,13 +47,11 @@ final class ToonWebViewController: UIViewController, WKNavigationDelegate {
/// 웹 화면 이동
@IBAction func backButtonDidTap(_ sender: UIButton) {
instagramWebView.goBack()
instagramWebView.reload()
}

/// 웹 화면 이동
@IBAction func forwardButtonDidTap(_ sender: UIButton) {
instagramWebView.goForward()
instagramWebView.reload()
}

// MARK: - Function
Expand All @@ -66,19 +63,25 @@ final class ToonWebViewController: UIViewController, WKNavigationDelegate {
let request = URLRequest(url: url)
instagramWebView.load(request)
}
instagramWebView.navigationDelegate = self
instagramWebView.allowsBackForwardNavigationGestures = true
}

/// 웹뷰 정보 넣기
private func setLabel(instaId: String, url: String) {
idLabel.text = instaId
urlLabel.text = url
/// 웹뷰 타이틀, url 넣기
private func setLabel() {
let javascript = "document.title\n"

instagramWebView.evaluateJavaScript(javascript) { (result, error) -> Void in
if error == nil {
self.idLabel.text = result as? String
}
}
urlLabel.text = instagramWebView.url?.absoluteString
}

/// 웹뷰 버튼 설정
private func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
/// 웹뷰 버튼, 레이블 설정
func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {
backButton.isEnabled = instagramWebView.canGoBack
forwardButton.isEnabled = instagramWebView.canGoForward
setLabel()
}

}
17 changes: 8 additions & 9 deletions Toonie/Detail/View/Detail.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="N5B-jj-8nl">
<rect key="frame" x="20" y="44" width="44" height="44"/>
<rect key="frame" x="0.0" y="44" width="44" height="44"/>
<constraints>
<constraint firstAttribute="width" constant="44" id="C6X-wr-PU0"/>
<constraint firstAttribute="height" constant="44" id="JPq-NZ-4LP"/>
Expand Down Expand Up @@ -149,7 +149,7 @@
<color key="titleColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</state>
<connections>
<action selector="addToMyCollection:" destination="SAT-03-eWA" eventType="touchUpInside" id="QNV-IU-tSB"/>
<action selector="addToMyFavorite:" destination="SAT-03-eWA" eventType="touchUpInside" id="QNV-IU-tSB"/>
</connections>
</button>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="mW4-Am-OaH" userLabel="line">
Expand All @@ -160,7 +160,7 @@
</constraints>
</view>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="userProfileimg" translatesAutoresizingMaskIntoConstraints="NO" id="3WF-JR-rme">
<rect key="frame" x="87.333333333333329" y="100.99999999999999" width="200.33333333333337" height="200.66666666666663"/>
<rect key="frame" x="87.333333333333314" y="100.99999999999999" width="200.33333333333337" height="200.66666666666663"/>
<constraints>
<constraint firstAttribute="width" secondItem="3WF-JR-rme" secondAttribute="height" multiplier="1:1" id="wGF-Go-DS3"/>
</constraints>
Expand All @@ -182,7 +182,7 @@
<constraint firstItem="3WF-JR-rme" firstAttribute="centerX" secondItem="an7-mg-Mse" secondAttribute="centerX" id="PKC-Fq-il8"/>
<constraint firstItem="Sew-Sr-lzS" firstAttribute="top" secondItem="kmQ-2P-dcV" secondAttribute="bottom" constant="14" id="RWD-2p-Q7e"/>
<constraint firstItem="kmQ-2P-dcV" firstAttribute="centerX" secondItem="an7-mg-Mse" secondAttribute="centerX" id="SQh-Ad-qdZ"/>
<constraint firstItem="N5B-jj-8nl" firstAttribute="leading" secondItem="an7-mg-Mse" secondAttribute="leading" constant="20" id="Vwb-t0-gNZ"/>
<constraint firstItem="N5B-jj-8nl" firstAttribute="leading" secondItem="an7-mg-Mse" secondAttribute="leading" id="Vwb-t0-gNZ"/>
<constraint firstItem="an7-mg-Mse" firstAttribute="trailing" secondItem="mW4-Am-OaH" secondAttribute="trailing" constant="20" id="W6T-sh-bk7"/>
<constraint firstItem="mW4-Am-OaH" firstAttribute="centerX" secondItem="an7-mg-Mse" secondAttribute="centerX" id="WNa-21-Np2"/>
<constraint firstItem="an7-mg-Mse" firstAttribute="trailing" secondItem="Zp5-BU-IbD" secondAttribute="trailing" id="bZY-gJ-lFM"/>
Expand Down Expand Up @@ -250,13 +250,13 @@
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="Z4B-Wu-BFh">
<rect key="frame" x="37.666666666666657" y="51.666666666666664" width="300" height="31.666666666666664"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="hongal.hongal" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4ZN-rw-CCc">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" " textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4ZN-rw-CCc">
<rect key="frame" x="0.0" y="0.0" width="300" height="17"/>
<fontDescription key="fontDescription" name="AppleSDGothicNeo-Bold" family="Apple SD Gothic Neo" pointSize="14"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="https://www.instagram.com/hongal.hongal" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ZHQ-Oy-n8g">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" " textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ZHQ-Oy-n8g">
<rect key="frame" x="0.0" y="17.000000000000007" width="300" height="14.666666666666664"/>
<fontDescription key="fontDescription" name="AppleSDGothicNeo-Bold" family="Apple SD Gothic Neo" pointSize="12"/>
<color key="textColor" name="unselectedText"/>
Expand All @@ -270,7 +270,7 @@
<stackView opaque="NO" contentMode="scaleToFill" spacing="40" translatesAutoresizingMaskIntoConstraints="NO" id="AJo-zt-QZk">
<rect key="frame" x="10" y="5" width="128" height="44"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" enabled="NO" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="IRf-NR-BXT">
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="IRf-NR-BXT">
<rect key="frame" x="0.0" y="0.0" width="44" height="44"/>
<constraints>
<constraint firstAttribute="width" constant="44" id="7eL-Nt-Uqo"/>
Expand All @@ -282,7 +282,7 @@
<action selector="backButtonDidTap:" destination="6vy-PQ-pVp" eventType="touchUpInside" id="V1x-Ev-iMm"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" enabled="NO" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="kUe-LW-UU8">
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="kUe-LW-UU8">
<rect key="frame" x="84" y="0.0" width="44" height="44"/>
<constraints>
<constraint firstAttribute="height" constant="44" id="Qwo-mD-b6y"/>
Expand Down Expand Up @@ -365,4 +365,3 @@
</namedColor>
</resources>
</document>

18 changes: 13 additions & 5 deletions Toonie/Network/API+Base.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ import Foundation
*/
class API {
static let baseURL = "http://220.76.238.7:10"
// static let baseURL = "http://172.30.1.12:8080"

// static let baseURL = "http://172.30.1.12:8080"
static let jsonDecoder: JSONDecoder = {
let jsonDecoder = JSONDecoder()
jsonDecoder.keyDecodingStrategy = .convertFromSnakeCase
return jsonDecoder
}()

static let token = {
return baseURL + "/token"
}()

static let keywords = {
return baseURL + "/keywords"
}()
Expand All @@ -44,7 +44,7 @@ class API {
static let toons = {
return baseURL + "/toons"
}()

//mykeywords/:token
static let myKeywordsToken = { (token) in
return myKeywords + "/" + token
Expand All @@ -55,4 +55,12 @@ class API {
return keywords + "/" + keyword
}

static let worklist = {
return baseURL + "/worklist"
}()

static let myWorklist = {
return baseURL + "/worklist/\(CommonUtility.userToken)/default"
}()

}
16 changes: 16 additions & 0 deletions Toonie/Network/Model/FavoriteToon.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// FavoriteToon.swift
// Toonie
//
// Created by 이재은 on 28/04/2019.
// Copyright © 2019 Yapp. All rights reserved.
//

import Foundation

struct FavoriteToon: Codable {
let success: Bool?
let workListName: String?
let workListInfo: String?
let toonId: String?
}
34 changes: 34 additions & 0 deletions Toonie/Network/Service/FavoriteService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// FavoriteService.swift
// Toonie
//
// Created by 이재은 on 28/04/2019.
// Copyright © 2019 Yapp. All rights reserved.
//

import Foundation

struct FavoriteService: Requestable {
typealias NetworkData = FavoriteToon
static let shared = FavoriteService()

///선택한 툰 즐겨찾기 post 통신
func postFavoriteToon(params: [String: Any],
completion: @escaping () -> Void) {
post((API.myWorklist),
params: params) { result in
switch result {
case .networkSuccess(let data):
if data.resResult.success == false {
return
}
completion()
print("FavoriteToon post success")
case .networkError(let error):
print(error)
case .networkFail:
print("FavoriteToon post fail")
}
}
}
}

0 comments on commit 98be9be

Please sign in to comment.