본문 바로가기
coding/react native

[React Native] IOS, Android facebook ATT SDK 설정하기

by 코딩희송 2021. 9. 8.

준비사항 

  • react-native-fbsdk-next
  • react-native-permissions

ATT 권한 추가하기

import {AppEventsLogger, Settings} from 'react-native-fbsdk-next';
import {PERMISSIONS, RESULTS, request, check} from 'react-native-permissions';

export async function initPixel() {
  if (Platform.OS === 'ios') {
    const ATT_CHECK = await check(PERMISSIONS.IOS.APP_TRACKING_TRANSPARENCY);
    if (ATT_CHECK === RESULTS.DENIED) {
      try {
        const ATT = await request(PERMISSIONS.IOS.APP_TRACKING_TRANSPARENCY);
        if (ATT === RESULTS.GRANTED) {
          Settings.setAdvertiserTrackingEnabled(true).then(() => {
            Settings.initializeSDK();
          });
        }
      } catch (error) {
        throw error;
      } finally {
        Settings.initializeSDK();
      }
      Settings.initializeSDK();
      Settings.setAdvertiserTrackingEnabled(true);
      Settings.FacebookAutoLogAppEventsEnabled(true);
    }
  } else {
    Settings.initializeSDK();
    Settings.setAdvertiserTrackingEnabled(true);
  }
}

App.js 레벨에서 useEffect를 통해 함수를 호출

 AppEventsLogger.logEvent('test', 14, {type: 'ios'}); //Test Event

 

react-native-permissions 플러그인을 추가 후, info.plist파일에서 아래 권한 추가

NSUserTrackingUsageDescription

pod 파일에 아래 코드를 추가하고 pod install 명령을 실행한다.

permissions_path = '../node_modules/react-native-permissions/ios'
pod 'Permission-AppTrackingTransparency', :path => :path => "#{permissions_path}/AppTrackingTransparency/Permission-AppTrackingTransparency.podspec"

댓글