Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Week09, 10-ahyun] 9주차 미션, 10주차 미션 #42

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
486 changes: 486 additions & 0 deletions 04_ahyun/Week09/Week9/Week9.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
44 changes: 44 additions & 0 deletions 04_ahyun/Week09/Week9/Week9/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// AppDelegate.swift
// Week9
//
// Created by 정아현 on 5/31/24.
//

import Foundation
import UIKit
import KakaoSDKCommon
import KakaoSDKAuth

class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions:
[UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
let kakaoAppKey = Bundle.main.infoDictionary?["KAKAO_NATIVE_APP_KEY"] ?? ""

print("kakaoAppKey : \(kakaoAppKey)")
// Kakao SDK 초기화
KakaoSDK.initSDK(appKey: kakaoAppKey as! String)

return true
}

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
if (AuthApi.isKakaoTalkLoginUrl(url)) {
return AuthController.handleOpenUrl(url: url)
}

return false
}

func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {

let sceneConfiguration = UISceneConfiguration(name: nil, sessionRole: connectingSceneSession.role)

sceneConfiguration.delegateClass = SceneDelegate.self

return sceneConfiguration
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions 04_ahyun/Week09/Week9/Week9/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
33 changes: 33 additions & 0 deletions 04_ahyun/Week09/Week9/Week9/ContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// ContentView.swift
// Week9
//
// Created by 정아현 on 5/31/24.
//

import SwiftUI

struct ContentView: View {
@StateObject var kakaoAuthVM : KakaoAuthVM = KakaoAuthVM()

var body: some View {
VStack(spacing: 20) {
if !kakaoAuthVM.nickName.isEmpty {
Text("Hello, \(kakaoAuthVM.nickName)!")
} else {
Text("Not logged in")
}

Button("kakao login", action: {
kakaoAuthVM.handleKakaoLogin()
})
Button("kakao logout", action: {
kakaoAuthVM.handleKakaoLogout()
})
}
}
}

#Preview {
ContentView()
}
33 changes: 33 additions & 0 deletions 04_ahyun/Week09/Week9/Week9/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KAKAO_NATIVE_APP_KEY</key>
<string>${KAKAO_NATIVE_APP_KEY}</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>kakao${KAKAO_NATIVE_APP_KEY}</string>
</array>
</dict>
</array>
<key>UIBackgroundModes</key>
<array/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<false/>
</dict>
<key>LSApplicationQueriesSchemes</key>
<array>
<!-- 카카오톡으로 로그인 -->
<string>kakaokompassauth</string>
<!-- 카카오톡 공유 -->
<string>kakaolink</string>
</array>
</dict>
</plist>
74 changes: 74 additions & 0 deletions 04_ahyun/Week09/Week9/Week9/KakaoAuthVM.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//
// KakaoAuthVM.swift
// Week9
//
// Created by 정아현 on 5/31/24.
//

import Foundation
import Combine
import KakaoSDKAuth
import KakaoSDKUser
import SwiftUI

class KakaoAuthVM : ObservableObject {
@AppStorage("nickName") var nickName: String = ""

func handleKakaoLogin() {
// 카카오톡 실행 가능 여부 확인
if (UserApi.isKakaoTalkLoginAvailable()) {
// 카카오앱을 통해 로그인
UserApi.shared.loginWithKakaoTalk {(oauthToken, error) in
if let error = error {
print(error)
}
else {
print("loginWithKakaoTalk() success.")
self.getUserInfo()
}
}
} else { // 카카오앱이 설치되지 않았을 때
// 카카오 웹을 통해 로그인
UserApi.shared.loginWithKakaoAccount {(oauthToken, error) in
if let error = error {
print(error)
}
else {
print("loginWithKakaoAccount() success.")
self.getUserInfo()
}
}
}

}

func handleKakaoLogout() {
UserApi.shared.logout {(error) in
if let error = error {
print(error)
}
else {
print("logout() success.")
self.clearUserInfo()
}
}
}

func getUserInfo() {
UserApi.shared.me() {(user, error) in
if let error = error {
print(error)
}
else {
print("me() success.")
// 유저 닉네임 가져오기
self.nickName = user?.kakaoAccount?.profile?.nickname ?? ""
print(self.nickName)
}
}
}

func clearUserInfo() {
nickName = ""
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
20 changes: 20 additions & 0 deletions 04_ahyun/Week09/Week9/Week9/SceneDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// SceneDelegate.swift
// Week9
//
// Created by 정아현 on 5/31/24.
//

import Foundation
import KakaoSDKAuth
import UIKit

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
if let url = URLContexts.first?.url {
if (AuthApi.isKakaoTalkLoginUrl(url)) {
_ = AuthController.handleOpenUrl(url: url)
}
}
}
}
22 changes: 22 additions & 0 deletions 04_ahyun/Week09/Week9/Week9/Week9App.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Week9App.swift
// Week9
//
// Created by 정아현 on 5/31/24.
//

import SwiftUI
import KakaoSDKCommon
import KakaoSDKAuth

@main
struct Week9App: App {

@UIApplicationDelegateAdaptor var appDelegate : AppDelegate

var body: some Scene {
WindowGroup {
ContentView()
}
}
}
8 changes: 8 additions & 0 deletions 04_ahyun/Week10/Week10/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## User settings
xcuserdata/
Package.resolved

*.xcconfig
*.plist
*.xcprivacy
.DS_Store
18 changes: 18 additions & 0 deletions 04_ahyun/Week10/Week10/.swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
disabled_rules: # Default Rules에서 비활성화할 규칙

# 라인 뒤에 공백이 없어야 합니다. https://realm.github.io/SwiftLint/trailing_whitespace.html
- trailing_whitespace

# 강제 캐스팅은 피해야합니다. https://realm.github.io/SwiftLint/force_cast.html
- force_cast

# 강제 언래핑은 피해야합니다. https://realm.github.io/SwiftLint/force_unwrapping.html
- force_unwrapping

# 한 줄의 길이를 제한합니다.
- line_length

opt_in_rules:

# Imports should be sorted
- sorted_imports
Loading