TIL: RN | 인앱 결제 react-native-iap (7) Listener Methods - 221130

Lumpen·2022년 11월 30일
0

RN인앱결제

목록 보기
7/16

purchaseErrorListener

구매 오류가 발생했을 때 호출되는 콜백을 등록합니다
.remove()를 호출하여 업데이트 수신을 중지할 수 있는
React Native Emitter Subscription을 반환합니다.

Signature

purchaseErrorListener((error: PurchaseError) => {});

Usage

import React, {useEffect} from 'react';
import {View} from 'react-native';
import {purchaseErrorListener} from 'react-native-iap';

const App = () => {
  useEffect(() => {
    const subscription = purchaseErrorListener((error: PurchaseError) => {
      console.log(error);
    });

    return () => {
      subscription.remove();
    };
  }, []);

  return <View />;
};

purchaseUpdatedListener

스토어에 아직 완료되지 않았거나, 소비되었거나, 승인되지 않은 구매에 대한 업데이트가 있을 때 호출되는 콜백을 등록합니다.
.remove()를 호출하여 업데이트 수신을 중지할 수 있는 React Native Emitter Subscription을 반환합니다. 가능한 빨리 청취자를 등록하고 항상 업데이트에 응답하십시오.

Signature

purchaseUpdatedListener((purchase: Purchase) => {});

Usage

import React, {useEffect} from 'react';
import {View} from 'react-native';
import {purchaseUpdatedListener} from 'react-native-iap';

const App = () => {
  useEffect(() => {
    const subscription = purchaseUpdatedListener((purchase: Purchase) => {
      console.log(purchase);
    });

    return () => {
      subscription.remove();
    };
  }, []);

  return <View />;
};
profile

promotedProductListener

Add IAP promoted subscription event.
향상된 IAP 구독 이벤트 추가

Signature

promotedProductListener((productId?: string) => {});

Usage

import React, {useEffect} from 'react';
import {View} from 'react-native';
import {promotedProductListener} from 'react-native-iap';

const App = () => {
  useEffect(() => {
    const subscription = promotedProductListener((productId) => {
      console.log(productId);
    });

    return () => {
      subscription.remove();
    };
  }, []);

  return <View />;
};
profile
떠돌이 생활을 하는. 실업자는 아니지만, 부랑 생활을 하는

0개의 댓글