카카오링크 샘플코드 문의

  • (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    // [self sendLinkScrap];

    CGRect rect = CGRectMake(50, 50, 50, 50);
    UIButton *btnLink = [[UIButton alloc] initWithFrame:rect];
    btnLink.backgroundColor = [UIColor blackColor];
    [btnLink addTarget:self action:@selector(touchedTestButton) forControlEvents:UIControlEventTouchUpInside];
    [btnLink setTitle:@“test” forState:UIControlStateNormal];

    [self.view addSubview:btnLink];

    UIView *testView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
    testView.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:testView];

}

-(void)touchedTestButton {
NSLog(@“clicked test button”);
[self sendLinkCustom];
}

  • (void)sendLinkCustom {

    // 템플릿 ID
    NSString *templateId = CUSTOM_TEMPLATE_ID;
    // 템플릿 Arguments
    NSDictionary *templateArgs = @{@“title”: @“제목 영역입니다.”,
    @“description”: @“설명 영역입니다.”};
    // 서버에서 콜백으로 받을 정보
    NSDictionary *serverCallbackArgs = @{@“user_id”: @“abcd”,
    @“product_id”: @“1234”};

    // 카카오링크 실행
    [[KLKTalkLinkCenter sharedCenter] sendCustomWithTemplateId:templateId templateArgs:templateArgs serverCallbackArgs:serverCallbackArgs success:^(NSDictionary<NSString *,NSString *> * _Nullable warningMsg, NSDictionary<NSString *,NSString *> * _Nullable argumentMsg) {

      // 성공
      NSLog(@"warning message: %@", warningMsg);
      NSLog(@"argument message: %@", argumentMsg);
    

    } failure:^(NSError * _Nonnull error) {

      // 실패
      [UIAlertController showMessage:error.description];
      NSLog(@"error: %@", error);
    

    }];
    }

그냥 버튼하나 생성해서 샘플코드 적용해봤는데 아래와같은 에러가 발생합니다.

error: Error Domain=KLKErrorDomain Code=-2 “appId=308746, appId in templateJson=2” UserInfo={KLKErrorHTTPStatusCode=400, KLKErrorResponseJSON={
code = “-2”;
msg = “appId=308746, appId in templateJson=2”;
}, NSLocalizedFailureReason=appId=308746, appId in templateJson=2}

샘플코드는 정상동작하는데…새로운 프로젝트를 생성해서 테스트해보던 중 에러가 발생해서 조언구합니다!

@gusgudz
템플릿 아이디를 잘못 입력하신 것 같아요
보내려고 하는 템플릿 아이디가 맞게 입력 됐는지 확인해주세요

답변덕분에 이해하고 해결했습니다. 감사합니다!

1개의 좋아요