Cordova 카카오 로그인 이슈

안녕하세요.
코르도바로 카카오 로그인 구현 중 이슈가 있어 글을 올리게 되었습니다.

사용 플러그인은
https://github.com/taejaehan/Cordova-Kakaotalk-Plugin 이며

meTaskWithCompletionHandler 함수에 result 값이 전달이 안되는 현상인데
아래 로그와 구현 코드를 보면
로그인 석세스는 뜹니다만
그 이후 값이 전달이 안되는 현상입니다.

화면 상으로 보면
버튼을 누르고

카톡이 열리면서
어떤 페이지가 ( 아무래도 권한요청 페이지라는 추측) 위로 페이지업이 되자마자 안에 내용물이
보이기도 전에 다시 어플리케이션으로 돌아오며,
에러를 뿜습니다.

KakaoTalk.m

- (void) login:(CDVInvokedUrlCommand*) command
{
    [[KOSession sharedSession] close];
    
    [[KOSession sharedSession] openWithCompletionHandler:^(NSError *error) {
        
        if(error) {
            NSLog(@"test Open kakao error : %@", error);
        } else {
            if ([[KOSession sharedSession] isOpen]) {
                // login success
                NSLog(@"login succeeded. %@", error);
                [KOSessionTask meTaskWithCompletionHandler:^(KOUser* result, NSError *error) {
                    CDVPluginResult* pluginResult = nil;
                    if (result) {
                        // success
                        NSLog(@"userId=%@", result.ID);
                        NSLog(@"nickName=%@", [result propertyForKey:@"nickname"]);
                        NSLog(@"profileImage=%@", [result propertyForKey:@"profile_image"]);
                        
                        NSDictionary *userSession = @{
                                              @"id": result.ID,
                                              @"nickname": [result propertyForKey:@"nickname"],
                                              @"profile_image": [result propertyForKey:@"profile_image"]};
                        pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:userSession];
                    } else {
                        // failed
                        NSLog(@"login session failed. : %@", error);
                        pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[error localizedDescription]];
                    }
                    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
                }];
            } else {
                // failed
                NSLog(@"login failed.");
                CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[error localizedDescription]];
                [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
            }
        }
        
    } authParams:nil authType:(KOAuthType)KOAuthTypeTalk, nil];
     
}

appdelegate.m

#import "AppDelegate.h"
#import "MainViewController.h"
#import <KakaoOpenSDK/KakaoOpenSDK.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {
 
  if ([KOSession isKakaoAccountLoginCallback:url]) {
    return [KOSession handleOpenURL:url];
  }
  return NO;
 
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
            options:(NSDictionary<NSString *,id> *)options {
 
  if ([KOSession isKakaoAccountLoginCallback:url]) {
    return [KOSession handleOpenURL:url];
  }
  return NO;
  
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
  [KOSession handleDidBecomeActive];
}

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
    self.viewController = [[MainViewController alloc] init];
    return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

@end

.plist

<?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>CFBundleDevelopmentRegion</key>
	<string>en_US</string>
	<key>CFBundleDisplayName</key>
	<string>mangoi</string>
	<key>CFBundleExecutable</key>
	<string>$(EXECUTABLE_NAME)</string>
	<key>CFBundleIdentifier</key>
	<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleName</key>
	<string>$(PRODUCT_NAME)</string>
	<key>CFBundlePackageType</key>
	<string>APPL</string>
	<key>CFBundleShortVersionString</key>
	<string>1.0.0</string>
	<key>CFBundleSignature</key>
	<string>????</string>
	<key>CFBundleURLTypes</key>
	<array>
		<dict>
			<key>CFBundleURLSchemes</key>
			<array>
				<string>???</string>
			</array>
		</dict>
		<dict>
			<key>CFBundleURLSchemes</key>
			<array>
				<string>kakao8c045cd2...2d15</string> // 보안상 혹시몰라  ... 으로 변경했습니다.
			</array>
		</dict>
	</array>
	<key>CFBundleVersion</key>
	<string>1.0.0</string>
	<key>KAKAO_APP_KEY</key>
	<string>8c...d15</string>
	<key>LSApplicationQueriesSchemes</key>
	<array>
		<string>kakao8c...15</string>
		<string>kakaokompassauth</string>
		<string>storykompassauth</string>
		<string>kakaolink</string>
		<string>kakaotalk-4.5.0</string>
		<string>kakaostory-2.9.0</string>
		<string>youtube</string>
	</array>
	<key>LSRequiresIPhoneOS</key>
	<true/>
	<key>NSAppTransportSecurity</key>
	<dict>
		<key>NSAllowsArbitraryLoads</key>
		<true/>
	</dict>
	<key>NSCameraUsageDescription</key>
	<string></string>
	<key>NSMainNibFile</key>
	<string></string>
	<key>NSMainNibFile~ipad</key>
	<string></string>
	<key>NSPhotoLibraryUsageDescription</key>
	<string></string>
	<key>UIBackgroundModes</key>
	<array>
		<string>remote-notification</string>
	</array>
	<key>UILaunchStoryboardName</key>
	<string>CDVLaunchScreen</string>
	<key>UIRequiresFullScreen</key>
	<true/>
	<key>UISupportedInterfaceOrientations</key>
	<array>
		<string>UIInterfaceOrientationPortrait</string>
		<string>UIInterfaceOrientationLandscapeLeft</string>
		<string>UIInterfaceOrientationLandscapeRight</string>
	</array>
	<key>UISupportedInterfaceOrientations~ipad</key>
	<array>
		<string>UIInterfaceOrientationPortrait</string>
		<string>UIInterfaceOrientationLandscapeLeft</string>
		<string>UIInterfaceOrientationPortraitUpsideDown</string>
		<string>UIInterfaceOrientationLandscapeRight</string>
	</array>
</dict>
</plist>

Log

2020-08-16 06:52:28.801294+0900 ???[971:201830] login succeeded. (null)
2020-08-16 06:52:28.985093+0900 ???[971:201830] login session failed. : Error Domain=KOErrorDomain Code=9 "The request failed due to HTTP error." UserInfo={HTTPStatusCode=404, NSLocalizedDescription=The request failed due to HTTP error.}

https://developers.kakao.com/docs/latest/ko/sdk-download/ios-v13

여기 링크에 변경이력을 보면 알수 있는 내용인데

KOSessionTask meTaskWithCompletionHandler:^(KOUser *_result, NSError *_error) 는
1.8.0에서 디프리케이트 공지가 나갔고 1.15에 삭제 되었습니다.

대신
KOSessionTask userMeTaskWithCompletion::^(KOUser *_result, NSError *_error) 를 사용하셔야 합니다.

최신버전은 1.23.4입니다. 최신버전으로 업그레이드를 권장드립니다.

그리고, api 호출시 아래와같이 결과(result)말고 error를 먼저 확인하는 습관을 가지는게 좋습니다.

[KOSessionTask meTaskWithCompletionHandler:^(KOUser* result, NSError *error) {
    if (error == nil) {
        CDVPluginResult* pluginResult = nil;
        if (result) {
            // success
            NSLog(@"userId=%@", result.ID);
            NSLog(@"nickName=%@", [result propertyForKey:@"nickname"]);
            NSLog(@"profileImage=%@", [result propertyForKey:@"profile_image"]);

            NSDictionary *userSession = @{
                                    @"id": result.ID,
                                    @"nickname": [result propertyForKey:@"nickname"],
                                    @"profile_image": [result propertyForKey:@"profile_image"]};
            pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:userSession];


        }
    }
    else {
        // failed
        NSLog(@"login session failed. : %@", error);
        pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[error localizedDescription]];
    }
    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
2개의 좋아요