diff --git a/iOS_Study_A.xcodeproj/project.pbxproj b/iOS_Study_A.xcodeproj/project.pbxproj index 1f5c336..e9f92ca 100644 --- a/iOS_Study_A.xcodeproj/project.pbxproj +++ b/iOS_Study_A.xcodeproj/project.pbxproj @@ -10,9 +10,21 @@ 954B6B612AC57BE100FDCFAB /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 954B6B602AC57BE100FDCFAB /* AppDelegate.swift */; }; 954B6B632AC57BE100FDCFAB /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 954B6B622AC57BE100FDCFAB /* SceneDelegate.swift */; }; 954B6B652AC57BE100FDCFAB /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 954B6B642AC57BE100FDCFAB /* ViewController.swift */; }; - 954B6B682AC57BE100FDCFAB /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 954B6B662AC57BE100FDCFAB /* Main.storyboard */; }; 954B6B6A2AC57BE200FDCFAB /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 954B6B692AC57BE200FDCFAB /* Assets.xcassets */; }; 954B6B6D2AC57BE200FDCFAB /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 954B6B6B2AC57BE200FDCFAB /* LaunchScreen.storyboard */; }; + DFB412F62B00F23100DA60B7 /* SnapKit in Frameworks */ = {isa = PBXBuildFile; productRef = DFB412F52B00F23100DA60B7 /* SnapKit */; }; + DFB412F92B032BB900DA60B7 /* Alamofire in Frameworks */ = {isa = PBXBuildFile; productRef = DFB412F82B032BB900DA60B7 /* Alamofire */; }; + DFB412FC2B03803100DA60B7 /* CombineMoya in Frameworks */ = {isa = PBXBuildFile; productRef = DFB412FB2B03803100DA60B7 /* CombineMoya */; }; + DFB412FE2B03803100DA60B7 /* Moya in Frameworks */ = {isa = PBXBuildFile; productRef = DFB412FD2B03803100DA60B7 /* Moya */; }; + DFB413002B03803100DA60B7 /* ReactiveMoya in Frameworks */ = {isa = PBXBuildFile; productRef = DFB412FF2B03803100DA60B7 /* ReactiveMoya */; }; + DFB413022B03803100DA60B7 /* RxMoya in Frameworks */ = {isa = PBXBuildFile; productRef = DFB413012B03803100DA60B7 /* RxMoya */; }; + DFB413052B0460E400DA60B7 /* KakaoSDK in Frameworks */ = {isa = PBXBuildFile; productRef = DFB413042B0460E400DA60B7 /* KakaoSDK */; }; + DFB413072B0460E400DA60B7 /* KakaoSDKAuth in Frameworks */ = {isa = PBXBuildFile; productRef = DFB413062B0460E400DA60B7 /* KakaoSDKAuth */; }; + DFB413092B0460E400DA60B7 /* KakaoSDKCert in Frameworks */ = {isa = PBXBuildFile; productRef = DFB413082B0460E400DA60B7 /* KakaoSDKCert */; }; + DFB4130B2B0460E400DA60B7 /* KakaoSDKCertCore in Frameworks */ = {isa = PBXBuildFile; productRef = DFB4130A2B0460E400DA60B7 /* KakaoSDKCertCore */; }; + DFB4130D2B0460E400DA60B7 /* KakaoSDKCommon in Frameworks */ = {isa = PBXBuildFile; productRef = DFB4130C2B0460E400DA60B7 /* KakaoSDKCommon */; }; + DFB4130F2B0460E400DA60B7 /* KakaoSDKUser in Frameworks */ = {isa = PBXBuildFile; productRef = DFB4130E2B0460E400DA60B7 /* KakaoSDKUser */; }; + DFB413112B0472B400DA60B7 /* SecondViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFB413102B0472B400DA60B7 /* SecondViewController.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -20,10 +32,10 @@ 954B6B602AC57BE100FDCFAB /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 954B6B622AC57BE100FDCFAB /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 954B6B642AC57BE100FDCFAB /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; - 954B6B672AC57BE100FDCFAB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 954B6B692AC57BE200FDCFAB /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 954B6B6C2AC57BE200FDCFAB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 954B6B6E2AC57BE200FDCFAB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + DFB413102B0472B400DA60B7 /* SecondViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecondViewController.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -31,6 +43,18 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + DFB413092B0460E400DA60B7 /* KakaoSDKCert in Frameworks */, + DFB4130D2B0460E400DA60B7 /* KakaoSDKCommon in Frameworks */, + DFB413022B03803100DA60B7 /* RxMoya in Frameworks */, + DFB4130B2B0460E400DA60B7 /* KakaoSDKCertCore in Frameworks */, + DFB412F62B00F23100DA60B7 /* SnapKit in Frameworks */, + DFB412F92B032BB900DA60B7 /* Alamofire in Frameworks */, + DFB412FE2B03803100DA60B7 /* Moya in Frameworks */, + DFB413002B03803100DA60B7 /* ReactiveMoya in Frameworks */, + DFB4130F2B0460E400DA60B7 /* KakaoSDKUser in Frameworks */, + DFB412FC2B03803100DA60B7 /* CombineMoya in Frameworks */, + DFB413052B0460E400DA60B7 /* KakaoSDK in Frameworks */, + DFB413072B0460E400DA60B7 /* KakaoSDKAuth in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -59,7 +83,7 @@ 954B6B602AC57BE100FDCFAB /* AppDelegate.swift */, 954B6B622AC57BE100FDCFAB /* SceneDelegate.swift */, 954B6B642AC57BE100FDCFAB /* ViewController.swift */, - 954B6B662AC57BE100FDCFAB /* Main.storyboard */, + DFB413102B0472B400DA60B7 /* SecondViewController.swift */, 954B6B692AC57BE200FDCFAB /* Assets.xcassets */, 954B6B6B2AC57BE200FDCFAB /* LaunchScreen.storyboard */, 954B6B6E2AC57BE200FDCFAB /* Info.plist */, @@ -83,6 +107,20 @@ dependencies = ( ); name = iOS_Study_A; + packageProductDependencies = ( + DFB412F52B00F23100DA60B7 /* SnapKit */, + DFB412F82B032BB900DA60B7 /* Alamofire */, + DFB412FB2B03803100DA60B7 /* CombineMoya */, + DFB412FD2B03803100DA60B7 /* Moya */, + DFB412FF2B03803100DA60B7 /* ReactiveMoya */, + DFB413012B03803100DA60B7 /* RxMoya */, + DFB413042B0460E400DA60B7 /* KakaoSDK */, + DFB413062B0460E400DA60B7 /* KakaoSDKAuth */, + DFB413082B0460E400DA60B7 /* KakaoSDKCert */, + DFB4130A2B0460E400DA60B7 /* KakaoSDKCertCore */, + DFB4130C2B0460E400DA60B7 /* KakaoSDKCommon */, + DFB4130E2B0460E400DA60B7 /* KakaoSDKUser */, + ); productName = iOS_Study_A; productReference = 954B6B5D2AC57BE100FDCFAB /* iOS_Study_A.app */; productType = "com.apple.product-type.application"; @@ -111,6 +149,12 @@ Base, ); mainGroup = 954B6B542AC57BE100FDCFAB; + packageReferences = ( + DFB412F42B00F23100DA60B7 /* XCRemoteSwiftPackageReference "SnapKit" */, + DFB412F72B032BB900DA60B7 /* XCRemoteSwiftPackageReference "Alamofire" */, + DFB412FA2B03803000DA60B7 /* XCRemoteSwiftPackageReference "Moya" */, + DFB413032B0460E400DA60B7 /* XCRemoteSwiftPackageReference "kakao-ios-sdk" */, + ); productRefGroup = 954B6B5E2AC57BE100FDCFAB /* Products */; projectDirPath = ""; projectRoot = ""; @@ -127,7 +171,6 @@ files = ( 954B6B6D2AC57BE200FDCFAB /* LaunchScreen.storyboard in Resources */, 954B6B6A2AC57BE200FDCFAB /* Assets.xcassets in Resources */, - 954B6B682AC57BE100FDCFAB /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -138,6 +181,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + DFB413112B0472B400DA60B7 /* SecondViewController.swift in Sources */, 954B6B652AC57BE100FDCFAB /* ViewController.swift in Sources */, 954B6B612AC57BE100FDCFAB /* AppDelegate.swift in Sources */, 954B6B632AC57BE100FDCFAB /* SceneDelegate.swift in Sources */, @@ -147,14 +191,6 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXVariantGroup section */ - 954B6B662AC57BE100FDCFAB /* Main.storyboard */ = { - isa = PBXVariantGroup; - children = ( - 954B6B672AC57BE100FDCFAB /* Base */, - ); - name = Main.storyboard; - sourceTree = ""; - }; 954B6B6B2AC57BE200FDCFAB /* LaunchScreen.storyboard */ = { isa = PBXVariantGroup; children = ( @@ -285,13 +321,13 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = iOS_Study_A/Info.plist; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; - INFOPLIST_KEY_UIMainStoryboardFile = Main; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; LD_RUNPATH_SEARCH_PATHS = ( @@ -312,13 +348,13 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = iOS_Study_A/Info.plist; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; - INFOPLIST_KEY_UIMainStoryboardFile = Main; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; LD_RUNPATH_SEARCH_PATHS = ( @@ -356,6 +392,104 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ + +/* Begin XCRemoteSwiftPackageReference section */ + DFB412F42B00F23100DA60B7 /* XCRemoteSwiftPackageReference "SnapKit" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/SnapKit/SnapKit.git"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 5.0.0; + }; + }; + DFB412F72B032BB900DA60B7 /* XCRemoteSwiftPackageReference "Alamofire" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/Alamofire/Alamofire.git"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 5.0.0; + }; + }; + DFB412FA2B03803000DA60B7 /* XCRemoteSwiftPackageReference "Moya" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/Moya/Moya.git"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 15.0.0; + }; + }; + DFB413032B0460E400DA60B7 /* XCRemoteSwiftPackageReference "kakao-ios-sdk" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/kakao/kakao-ios-sdk"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 2.0.0; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + DFB412F52B00F23100DA60B7 /* SnapKit */ = { + isa = XCSwiftPackageProductDependency; + package = DFB412F42B00F23100DA60B7 /* XCRemoteSwiftPackageReference "SnapKit" */; + productName = SnapKit; + }; + DFB412F82B032BB900DA60B7 /* Alamofire */ = { + isa = XCSwiftPackageProductDependency; + package = DFB412F72B032BB900DA60B7 /* XCRemoteSwiftPackageReference "Alamofire" */; + productName = Alamofire; + }; + DFB412FB2B03803100DA60B7 /* CombineMoya */ = { + isa = XCSwiftPackageProductDependency; + package = DFB412FA2B03803000DA60B7 /* XCRemoteSwiftPackageReference "Moya" */; + productName = CombineMoya; + }; + DFB412FD2B03803100DA60B7 /* Moya */ = { + isa = XCSwiftPackageProductDependency; + package = DFB412FA2B03803000DA60B7 /* XCRemoteSwiftPackageReference "Moya" */; + productName = Moya; + }; + DFB412FF2B03803100DA60B7 /* ReactiveMoya */ = { + isa = XCSwiftPackageProductDependency; + package = DFB412FA2B03803000DA60B7 /* XCRemoteSwiftPackageReference "Moya" */; + productName = ReactiveMoya; + }; + DFB413012B03803100DA60B7 /* RxMoya */ = { + isa = XCSwiftPackageProductDependency; + package = DFB412FA2B03803000DA60B7 /* XCRemoteSwiftPackageReference "Moya" */; + productName = RxMoya; + }; + DFB413042B0460E400DA60B7 /* KakaoSDK */ = { + isa = XCSwiftPackageProductDependency; + package = DFB413032B0460E400DA60B7 /* XCRemoteSwiftPackageReference "kakao-ios-sdk" */; + productName = KakaoSDK; + }; + DFB413062B0460E400DA60B7 /* KakaoSDKAuth */ = { + isa = XCSwiftPackageProductDependency; + package = DFB413032B0460E400DA60B7 /* XCRemoteSwiftPackageReference "kakao-ios-sdk" */; + productName = KakaoSDKAuth; + }; + DFB413082B0460E400DA60B7 /* KakaoSDKCert */ = { + isa = XCSwiftPackageProductDependency; + package = DFB413032B0460E400DA60B7 /* XCRemoteSwiftPackageReference "kakao-ios-sdk" */; + productName = KakaoSDKCert; + }; + DFB4130A2B0460E400DA60B7 /* KakaoSDKCertCore */ = { + isa = XCSwiftPackageProductDependency; + package = DFB413032B0460E400DA60B7 /* XCRemoteSwiftPackageReference "kakao-ios-sdk" */; + productName = KakaoSDKCertCore; + }; + DFB4130C2B0460E400DA60B7 /* KakaoSDKCommon */ = { + isa = XCSwiftPackageProductDependency; + package = DFB413032B0460E400DA60B7 /* XCRemoteSwiftPackageReference "kakao-ios-sdk" */; + productName = KakaoSDKCommon; + }; + DFB4130E2B0460E400DA60B7 /* KakaoSDKUser */ = { + isa = XCSwiftPackageProductDependency; + package = DFB413032B0460E400DA60B7 /* XCRemoteSwiftPackageReference "kakao-ios-sdk" */; + productName = KakaoSDKUser; + }; +/* End XCSwiftPackageProductDependency section */ }; rootObject = 954B6B552AC57BE100FDCFAB /* Project object */; } diff --git a/iOS_Study_A/AppDelegate.swift b/iOS_Study_A/AppDelegate.swift index a37563b..71f9c47 100644 --- a/iOS_Study_A/AppDelegate.swift +++ b/iOS_Study_A/AppDelegate.swift @@ -6,6 +6,9 @@ // import UIKit +import KakaoSDKCommon +import KakaoSDKAuth +import KakaoSDKUser @main class AppDelegate: UIResponder, UIApplicationDelegate { @@ -14,6 +17,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. + //KakaoSDK.initSDK(appKey: "6991dad04e23fc94a5f6375804b13ae0") return true } diff --git a/iOS_Study_A/Assets.xcassets/kakao_login_medium_narrow.imageset/Contents.json b/iOS_Study_A/Assets.xcassets/kakao_login_medium_narrow.imageset/Contents.json new file mode 100644 index 0000000..8f851ed --- /dev/null +++ b/iOS_Study_A/Assets.xcassets/kakao_login_medium_narrow.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "kakao_login_medium_narrow.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/iOS_Study_A/Assets.xcassets/kakao_login_medium_narrow.imageset/kakao_login_medium_narrow.png b/iOS_Study_A/Assets.xcassets/kakao_login_medium_narrow.imageset/kakao_login_medium_narrow.png new file mode 100644 index 0000000..09bb358 Binary files /dev/null and b/iOS_Study_A/Assets.xcassets/kakao_login_medium_narrow.imageset/kakao_login_medium_narrow.png differ diff --git a/iOS_Study_A/Base.lproj/Main.storyboard b/iOS_Study_A/Base.lproj/Main.storyboard deleted file mode 100644 index 25a7638..0000000 --- a/iOS_Study_A/Base.lproj/Main.storyboard +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/iOS_Study_A/Info.plist b/iOS_Study_A/Info.plist index dd3c9af..0eb786d 100644 --- a/iOS_Study_A/Info.plist +++ b/iOS_Study_A/Info.plist @@ -15,8 +15,6 @@ Default Configuration UISceneDelegateClassName $(PRODUCT_MODULE_NAME).SceneDelegate - UISceneStoryboardFile - Main diff --git a/iOS_Study_A/SceneDelegate.swift b/iOS_Study_A/SceneDelegate.swift index aaf78de..1941d76 100644 --- a/iOS_Study_A/SceneDelegate.swift +++ b/iOS_Study_A/SceneDelegate.swift @@ -6,17 +6,41 @@ // import UIKit +import KakaoSDKCommon +import KakaoSDKAuth +import KakaoSDKUser class SceneDelegate: UIResponder, UIWindowSceneDelegate { var window: UIWindow? - func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { + func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions){ + // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). - guard let _ = (scene as? UIWindowScene) else { return } + + guard let windowScene = (scene as? UIWindowScene) else { return } + window = UIWindow(windowScene: windowScene) // SceneDelegate의 프로퍼티에 설정해줌 + let mainViewController = ViewController() // 맨 처음 보여줄 ViewController + KakaoSDK.initSDK(appKey: "6991dad04e23fc94a5f6375804b13ae0") + window?.rootViewController = mainViewController + window?.makeKeyAndVisible() + /*if let url = URLContexts.first?.url { + if (AuthApi.isKakaoTalkLoginUrl(url)) { + _ = AuthController.handleOpenUrl(url: url) + } + }*/ + } + + func scene(_ scene: UIScene, openURLContexts URLContexts: Set) { + if let url = URLContexts.first?.url { + if (AuthApi.isKakaoTalkLoginUrl(url)) { + + _ = AuthController.handleOpenUrl(url: url) + } + } } func sceneDidDisconnect(_ scene: UIScene) { diff --git a/iOS_Study_A/SecondViewController.swift b/iOS_Study_A/SecondViewController.swift new file mode 100644 index 0000000..e40a57b --- /dev/null +++ b/iOS_Study_A/SecondViewController.swift @@ -0,0 +1,59 @@ +// +// SecondViewController.swift +// iOS_Study_A +// +// Created by 박현수 on 2023/11/15. +// + +import UIKit +import SnapKit +import Alamofire +import KakaoSDKAuth +import KakaoSDKUser +import KakaoSDKCommon + +class SecondViewController: UIViewController { + + @objc func logOutButtonTapped() { + UserApi.shared.logout {(error) in + if let error = error { + print(error) + } + else { + print("logout() success.") + self.dismiss(animated: true, completion: nil) + } + } + } + + let logOutButton: UIButton = { + let button = UIButton() + button.setTitle("로그아웃", for: .normal) + button.backgroundColor = .systemBlue + button.layer.cornerRadius = 10 + return button + }() + + override func viewDidLoad() { + super.viewDidLoad() + view.addSubview(logOutButton) + logOutButton.snp.makeConstraints { make in + make.center.equalToSuperview() + make.width.height.equalTo(200) + } + logOutButton.addTarget(self, action: #selector(logOutButtonTapped), for: .touchUpInside) + // Do any additional setup after loading the view. + } + + + /* + // 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.destination. + // Pass the selected object to the new view controller. + } + */ + +} diff --git a/iOS_Study_A/ViewController.swift b/iOS_Study_A/ViewController.swift index 0804a27..7c4a149 100644 --- a/iOS_Study_A/ViewController.swift +++ b/iOS_Study_A/ViewController.swift @@ -6,14 +6,293 @@ // import UIKit +import SnapKit +import Alamofire +import KakaoSDKAuth +import KakaoSDKUser +import KakaoSDKCommon class ViewController: UIViewController { - + + + let seoulUrl = "https://api.openweathermap.org/data/2.5/weather?appid=46bf119912a3aaa443360e604dfcaf40&units=metric&q=seoul&lang=kr" + let busanUrl = "https://api.openweathermap.org/data/2.5/weather?appid=46bf119912a3aaa443360e604dfcaf40&units=metric&q=busan&lang=kr" + let jejuUrl = "https://api.openweathermap.org/data/2.5/weather?appid=46bf119912a3aaa443360e604dfcaf40&units=metric&q=jeju&lang=kr" + + let apiKey = "46bf119912a3aaa443360e604dfcaf40" + + let seoul: UIView = { + let view = UIView() + view.backgroundColor = .systemGray4 + view.layer.cornerRadius = 10 + return view + }() + let seoulLabel: UILabel = { + let label = UILabel() + label.backgroundColor = .white + label.layer.cornerRadius = 5 + label.layer.masksToBounds = true + return label + }() + let seoulTemp: UILabel = { + let label = UILabel() + label.backgroundColor = .clear + return label + }() + let seoulDescription: UILabel = { + let label = UILabel() + label.backgroundColor = .clear + return label + }() + + let busan: UIView = { + let view = UIView() + view.backgroundColor = .systemGray4 + view.layer.cornerRadius = 10 + return view + }() + let busanLabel: UILabel = { + let label = UILabel() + label.backgroundColor = .systemBlue + label.layer.cornerRadius = 5 + label.layer.masksToBounds = true + return label + }() + let busanTemp: UILabel = { + let label = UILabel() + label.backgroundColor = .clear + return label + }() + let busanDescription: UILabel = { + let label = UILabel() + label.backgroundColor = .clear + return label + }() + + let jeju: UIView = { + let view = UIView() + view.backgroundColor = .systemGray4 + view.layer.cornerRadius = 10 + return view + }() + let jejuLabel: UILabel = { + let label = UILabel() + label.backgroundColor = .orange + label.layer.cornerRadius = 5 + label.layer.masksToBounds = true + return label + }() + let jejuTemp: UILabel = { + let label = UILabel() + label.backgroundColor = .clear + return label + }() + let jejuDescription: UILabel = { + let label = UILabel() + label.backgroundColor = .clear + return label + }() + + let kakaoLoginButton: UIButton = { + let button = UIButton() + button.setImage(UIImage(named: "kakao_login_medium_narrow"), for: .normal) + return button + }() + + @objc func signInButtonTapped() { + UserApi.shared.loginWithKakaoAccount {(oauthtoken, error) in + if let error = error { + print(error) + } + else { + print("loginWithKakaoAccount() success.") + let secondViewController = SecondViewController() + secondViewController.modalPresentationStyle = UIModalPresentationStyle.fullScreen + self.present(secondViewController, animated: true, completion: nil) + _ = oauthtoken + } + } + } + + func configureSubviews() { + view.addSubview(seoul) + seoul.addSubview(seoulLabel) + seoul.addSubview(seoulDescription) + seoul.addSubview(seoulTemp) + view.addSubview(busan) + busan.addSubview(busanLabel) + busan.addSubview(busanDescription) + busan.addSubview(busanTemp) + view.addSubview(jeju) + jeju.addSubview(jejuLabel) + jeju.addSubview(jejuDescription) + jeju.addSubview(jejuTemp) + view.addSubview(kakaoLoginButton) + kakaoLoginButton.addTarget(self, action: #selector(signInButtonTapped), for: .touchUpInside) + } + + func makeConstraints() { + seoul.snp.makeConstraints { make in + make.width.equalTo(300) + make.height.equalTo(200) + make.centerX.equalToSuperview() + make.top.equalToSuperview().offset(80) + } + seoulLabel.snp.makeConstraints { make in + make.width.equalTo(180) + make.height.equalTo(40) + make.left.equalToSuperview().offset(10) + make.top.equalToSuperview().offset(10) + } + seoulDescription.snp.makeConstraints { make in + make.width.equalTo(180) + make.height.equalTo(40) + make.left.equalToSuperview().offset(10) + make.top.equalTo(seoulLabel.snp.bottom).offset(10) + } + seoulTemp.snp.makeConstraints { make in + make.width.equalTo(180) + make.height.equalTo(40) + make.left.equalToSuperview().offset(10) + make.top.equalTo(seoulDescription.snp.bottom).offset(10) + } + + busan.snp.makeConstraints { make in + make.width.equalTo(300) + make.height.equalTo(200) + make.centerX.equalToSuperview() + make.top.equalTo(seoul.snp.bottom).offset(30) + } + busanLabel.snp.makeConstraints { make in + make.width.equalTo(180) + make.height.equalTo(40) + make.left.equalToSuperview().offset(10) + make.top.equalToSuperview().offset(10) + } + busanDescription.snp.makeConstraints { make in + make.width.equalTo(180) + make.height.equalTo(40) + make.left.equalToSuperview().offset(10) + make.top.equalTo(busanLabel.snp.bottom).offset(10) + } + busanTemp.snp.makeConstraints { make in + make.width.equalTo(180) + make.height.equalTo(40) + make.left.equalToSuperview().offset(10) + make.top.equalTo(busanDescription.snp.bottom).offset(10) + } + + jeju.snp.makeConstraints { make in + make.width.equalTo(300) + make.height.equalTo(200) + make.centerX.equalToSuperview() + make.top.equalTo(busan.snp.bottom).offset(30) + } + jejuLabel.snp.makeConstraints { make in + make.width.equalTo(180) + make.height.equalTo(40) + make.left.equalToSuperview().offset(10) + make.top.equalToSuperview().offset(10) + } + jejuDescription.snp.makeConstraints { make in + make.width.equalTo(180) + make.height.equalTo(40) + make.left.equalToSuperview().offset(10) + make.top.equalTo(jejuLabel.snp.bottom).offset(10) + } + jejuTemp.snp.makeConstraints { make in + make.width.equalTo(180) + make.height.equalTo(40) + make.left.equalToSuperview().offset(10) + make.top.equalTo(jejuDescription.snp.bottom).offset(10) + } + kakaoLoginButton.snp.makeConstraints { make in + make.width.equalTo(183) + make.height.equalTo(45) + make.centerX.equalToSuperview() + make.bottom.equalToSuperview().offset(-30) + } + } + override func viewDidLoad() { super.viewDidLoad() - // Do any additional setup after loading the view. - } - + view.backgroundColor = .white + + configureSubviews() + makeConstraints() + + AF.request(seoulUrl, + method: .get, + parameters: nil, + encoding: URLEncoding.default) + .responseJSON { response in + switch response.result { + case .success(let data): + let dictData = data as! [String: Any] + let name = dictData["name"] as! String + let mainData = dictData["main"] as! [String: Any] + let tempData = mainData["temp"] as! NSNumber + let temp = tempData.floatValue + let weatherData = dictData["weather"] as! [[String: Any]] + let innerData = weatherData.first + let description = innerData?["description"] as! String + self.seoulLabel.text = "도시 : \(name)" + self.seoulDescription.text = "기상 : \(description)" + self.seoulTemp.text = "기온 : \(String(temp))" + case .failure(let error): + print("\(error)") + } + } + + + + AF.request(busanUrl, + method: .get, + parameters: nil, + encoding: URLEncoding.default) + .responseJSON { response in + switch response.result { + case .success(let data): + let dictData = data as! [String: Any] + let name = dictData["name"] as! String + let mainData = dictData["main"] as! [String: Any] + let tempData = mainData["temp"] as! NSNumber + let temp = tempData.floatValue + let weatherData = dictData["weather"] as! [[String: Any]] + let innerData = weatherData.first + let description = innerData?["description"] as! String + + self.busanLabel.text = "도시 : \(name)" + self.busanDescription.text = "기상 : \(description)" + self.busanTemp.text = "기온 : \(String(temp))" + case .failure(let error): + print("\(error)") + } + } + + AF.request(jejuUrl, + method: .get, + parameters: nil, + encoding: URLEncoding.default) + .responseJSON { response in + switch response.result { + case .success(let data): + let dictData = data as! [String: Any] + let name = dictData["name"] as! String + let mainData = dictData["main"] as! [String: Any] + let tempData = mainData["temp"] as! NSNumber + let temp = tempData.floatValue + let weatherData = dictData["weather"] as! [[String: Any]] + let innerData = weatherData.first + let description = innerData?["description"] as! String + self.jejuLabel.text = "도시 : \(name)" + self.jejuDescription.text = "기상 : \(description)" + self.jejuTemp.text = "기온 : \(String(temp))" + case .failure(let error): + print("\(error)") + } + } + } }