Skip to content

codercodingthecode/ios-tracking-tranparency

Repository files navigation

ios-tracking-transparency

NPM

ios-tracking-transparency Capacitor plugin for ios tracking transparency

https://www.npmjs.com/package/ios-tracking-transparency

Install

npm install ios-tracking-transparency
yarn add ios-tracking-transparency
npx cap sync

API

	export type AuthorizationStatus =
	| 'authorized'
	| 'denied'
	| 'notDetermined'
	| 'restricted'
	| 'null';
	export interface AppTrackingTransparencyPlugin {
		requestTrackingAuthorization(): Promise<{
			status: AuthorizationStatus;
			code: number;
		}>;
		trackingAuthorizationStatus(): Promise<{
			status: AuthorizationStatus;
			code: number;
		}>;
	}

requestTrackingAuthorization()

	function requestTrackingAuthorization(): Promise<{
		status: AuthorizationStatus;
		code: number;
	}>;

trackingAuthorizationStatus()

	function trackingAuthorizationStatus(): Promise<{
		status: AuthorizationStatus;
		code: number;
	}>;

Snippet

import { AppTrackingTransparency } from 'ios-tracking-transparency';

function App(): JSX.Element {
    useEffect(() => {
        try {
            if (Capacitor.getPlatform() === 'ios') {
                AppTrackingTransparency.trackingAuthorizationStatus()
                    .then(async (trackStat) => {
                        if (trackStat.status !== 'authorized') {
                            await AppTrackingTransparency.requestTrackingAuthorization();
                        }
                    })
                    .catch((e) => console.warn('IOS Error', e));
            }
        } catch (e) {
            console.warn('Authorization failed', e);
        }
    }, []);
    return (
        <Components/>
    );
}

Xcode settings Info.plist

- Follow the guide below over Apple Dev to add the App Tracking key string in the info.plist file.

https://developer.apple.com/documentation/apptrackingtransparency

About

Capacitor IOS App Tracking Transparency

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published