반응형

여러번의 구글 로그인을 iOS 에서 구현했으나 할때마다 뭔가 동일하게 구현이 안되는듯 하는 느낌이여서 한번 정리를 해둔다.

 

Google 클라우드 콘솔에서 프로젝트 생성 키 발급 등은 

https://developers.google.com/identity/sign-in/ios/start-integrating?hl=ko 

 

iOS 및 macOS용 Google 로그인 시작하기  |  Authentication  |  Google for Developers

이 페이지는 Cloud Translation API를 통해 번역되었습니다. Switch to English 의견 보내기 iOS 및 macOS용 Google 로그인 시작하기 컬렉션을 사용해 정리하기 내 환경설정을 기준으로 콘텐츠를 저장하고 분류

developers.google.com

에서 주는 가이드를 따라하고,

 

SPM 을 통해 패키지를 설치하면 라이브러리 인식이 안되는 이슈가 종종 발생해서 Pod install 을 통해 패키지를 설치했다.

 

  1. pod 'GoogleSignIn'

info.plist에

<key>GIDClientID</key>
<string>YOUR_IOS_CLIENT_ID</string>
<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>YOUR_DOT_REVERSED_IOS_CLIENT_ID</string>
    </array>
  </dict>
</array>

넣어주고

 

코드상으로는 구글 사인버튼을 만들어서 어쩌니 하는거 다 귀차나서 어차피 커스텀 버튼으로 만들꺼 스토리보드에서 버튼 만들어서 액션 연결.

 

라이브러리 임포트

import GoogleSignIn

 

델리게이트 설정

class SignVC: UIViewController,GIDSignInDelegate{

 

 // MARK: - Google Login
    @IBAction func loginGoogle(_ sender: Any) {
        GIDSignIn.sharedInstance()?.presentingViewController = self
        GIDSignIn.sharedInstance().delegate = self
        GIDSignIn.sharedInstance().signIn()

    }
    
    func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
        if let error = error {
            if (error as NSError).code == GIDSignInErrorCode.hasNoAuthInKeychain.rawValue {
                print("The user has not signed in before or they have since signed out.")
            } else {
                print("\(error.localizedDescription)")
            }
            return
        }
            
        // 사용자 정보 가져오기
        if let userId = user.userID,                  // For client-side use only!
            let idToken = user.authentication.idToken, // Safe to send to the server
            let fullName = user.profile.name,
            let givenName = user.profile.givenName,
            let familyName = user.profile.familyName,
            let email = user.profile.email {
                
            print("Token : \(idToken)")
            print("User ID : \(userId)")
            print("User Email : \(email)")
            print("User Name : \((fullName))")

        } else {
            print("Error : User Data Not Found")
        }
    }
        
    // 구글 로그인 연동 해제했을때 불러오는 메소드
    func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!, withError error: Error!) {
        print("Disconnect")
    }

 

 

해서 액션걸고 로그인하려면 OAuth 어쩌고 저쩌고 하면서 액세스 디나이 뜨는 경우 있는데

 

https://console.cloud.google.com/apis/credentials/consent?project=

 

Google 클라우드 플랫폼

로그인 Google 클라우드 플랫폼으로 이동

accounts.google.com

 

들어가서 사용자유형 외부(난 외부메일로 테스트 할꺼라) 상태 테스트, 하고 테스트 사용자에 로그인 테스트 할 계정 추가해주면 해결.

Posted by npre
,
반응형

LoginView 라는 SwiftUI 파일 생성

 

기존 UIKit 의 VC파일에서

SwiftUI를 import

 

let loginView = LoginView()

let hostCon = UIHostingController(rootView: loginView)

 

와 같이 UIHostingController를 사용하여 swiftUI 파일을 UIViewcontrollelr등을 땡기는 것과 같이 사용 가능

 

 

 

//
//  LoginView.swift
//  GUIVINGKOREA
//
//  Created by JangHyun on 2023/07/20.
//

import SwiftUI

struct LoginView: View {
    var body: some View {
        VStack{
            Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
            Text("2")
        }
        
    }
}

struct LoginView_Previews: PreviewProvider {
    static var previews: some View {
        LoginView()
    }
}
//
//  SplashVC.swift
//  GUIVINGKOREA
//
//  Created by JangHyun on 2023/07/20.
//

import UIKit
import SwiftUI
class SplashVC: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
       
        self.swiftUIMoveTest()
    }
    
    func swiftUIMoveTest(){
        let loginView = LoginView()
        let hostCon = UIHostingController(rootView: loginView)
        APP.nav.pushViewController(hostCon, animated: true)
    }
    

    /*
    // 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.
    }
    */

}
Posted by npre
,
반응형

iOS13으로 업데이트 되면서 Scene delegate 라는것이 생겼었다.

새로 학습할 시간도 없고 내용파악도 귀찮아서

info.plist의

	<key>UIApplicationSceneManifest</key>
	<dict>
		<key>UIApplicationSupportsMultipleScenes</key>
		<false/>
		<key>UISceneConfigurations</key>
		<dict>
			<key>UIWindowSceneSessionRoleApplication</key>
			<array>
				<dict>
					<key>UISceneConfigurationName</key>
					<string>Default Configuration</string>
					<key>UISceneDelegateClassName</key>
					<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
					<key>UISceneStoryboardFile</key>
					<string>Main</string>
				</dict>
			</array>
		</dict>
	</dict>

를 지워버리고

 

AppDelegate의

 

    func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
        // Called when a new scene session is being created.
        // Use this method to select a configuration to create the new scene with.
        return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
    }

    func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
        // Called when the user discards a scene session.
        // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
        // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
    }

를 날려버려서 기존 AppDelegate만 있을 때 와 동일하게 프로젝트를 생성, 관리했었으나

 

이제는 SceneDelegate에 대하여 정확히 이해하고 사용하려고 메모를 남긴다.

 

골자는 iOS13부터 멀티 window를 지원하므로

 

앱이 백그라운드로 떨어지는것, 다시 올라오는것 등의 UI변화를 SceneDelegate로 이관한다는 것.

 

크게 변하는것 없이 기존 AppDelegate didFinish~ 에  구현하던 초기화 코드를

 

SceneDelegate wiillConnet~ 으로 옮겨준다.

 

나는 navigationController를 앱 전역에서 자주 접근하므로

 

appdelegate에 nav con을 만들어 두고

 

Scene에서 아래와 같이 구현,

 

        APP.nav = UINavigationController.init(rootViewController: vc)

        APP.nav.setNavigationBarHidden(true, animated: false)

        APP.nav.modalPresentationStyle = .fullScreen

        self.window?.rootViewController = APP.nav

        self.window?.makeKeyAndVisible()

 

 

 

SceneDelegate로 전환 후 APP.window 접근 에러가 발생하는데

 

https://xodhks0113.blogspot.com/2020/03/ios13-window-scenedelegate.html

 

iOS13 window 접근 에러 (SceneDelegate 변경 접근하기)

iOS 개발 및 일상에 대한 블로그 입니다.

xodhks0113.blogspot.com

 

를 참고하여 해결.

Posted by npre
,
반응형
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
{

    NSString* urlString = [URL_STRING];
    NSString *escapedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    NSMutableURLRequest *fixRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:escapedString]];
    [fixRequest addValue:@"[CUSTOM_USER_AGENT]" forHTTPHeaderField:@"User-Agent"];


    [webView evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id userAgent, NSError * error) {
        if (userAgent != NULL){
            NSLog(@"default UserAgent = %@", userAgent);
            webView.customUserAgent = [NSString stringWithFormat:@"%@/[CUSTOM_USER_AGENT]", userAgent];
            [[NSUserDefaults standardUserDefaults] registerDefaults:@{@"UserAgent": [NSString stringWithFormat:@"%@[CUSTOM_USER_AGENT]]}];
        }
    }];
    decisionHandler(WKNavigationActionPolicyCancel);
    
    [self.webView loadRequest:fixRequest];

}

 

'Programing' 카테고리의 다른 글

AWS/Ubuntu EC2 셋팅  (0) 2023.06.30
[iOS] 상단 Safety Area 영역  (2) 2022.02.18
[iOS] klip sdk 적용이슈  (0) 2022.02.09
CRUL 관련  (0) 2021.12.02
STS Git 로그인 불가  (0) 2021.11.01
Posted by npre
,
반응형

Klip SDK 적용 중 

 

"building for ios but the linked framework was built for ios simulator"와 같은 에러가 발생

 

build setting에서  Validate Workspace 를 YES로 바꿔주면서 해결.

'Programing' 카테고리의 다른 글

[iOS] 상단 Safety Area 영역  (2) 2022.02.18
[iOS] WKWebview User Agent 설정  (0) 2022.02.18
CRUL 관련  (0) 2021.12.02
STS Git 로그인 불가  (0) 2021.11.01
리눅스 Mysql 외부접속 셋팅  (0) 2021.04.19
Posted by npre
,
반응형

iOS Splash Screen을 Storyboard를 사용하지 않고 Image Set에서 Lanch Image를 셋팅할때

Target, Build Setting에서

Asset Catalog Compiler의 LanchImage name을 셋팅해줘야함.

'Programing' 카테고리의 다른 글

Docker 추가 셋팅  (1) 2021.01.11
Docker 초기 셋팅  (1) 2021.01.11
Spring boot message property 다국어 대응  (0) 2020.04.29
iOS 13 Modal FullScreen 이슈  (0) 2020.04.27
[iOS] UserDefault Setting  (0) 2016.05.17
Posted by npre
,