From 8b121af2e438ca77cc5f5b1715516107c18aff6f Mon Sep 17 00:00:00 2001 From: Hailey Date: Thu, 11 Jul 2024 18:43:10 -0700 Subject: referrers for all platforms (#4514) --- plugins/withAppDelegateReferrer.js | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 plugins/withAppDelegateReferrer.js (limited to 'plugins') diff --git a/plugins/withAppDelegateReferrer.js b/plugins/withAppDelegateReferrer.js new file mode 100644 index 000000000..de773df07 --- /dev/null +++ b/plugins/withAppDelegateReferrer.js @@ -0,0 +1,41 @@ +const {withAppDelegate} = require('@expo/config-plugins') +const {mergeContents} = require('@expo/config-plugins/build/utils/generateCode') +const path = require('path') +const fs = require('fs') + +module.exports = config => { + // eslint-disable-next-line no-shadow + return withAppDelegate(config, async config => { + const delegatePath = path.join( + config.modRequest.platformProjectRoot, + 'AppDelegate.mm', + ) + + let newContents = config.modResults.contents + newContents = mergeContents({ + src: newContents, + anchor: '// Linking API', + newSrc: ` + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + [defaults setObject:options[UIApplicationOpenURLOptionsSourceApplicationKey] forKey:@"referrerApp"];\n`, + offset: 2, + tag: 'referrer info - deep links', + comment: '//', + }).contents + + newContents = mergeContents({ + src: newContents, + anchor: '// Universal Links', + newSrc: ` + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + [defaults setURL:userActivity.referrerURL forKey:@"referrer"];\n`, + offset: 2, + tag: 'referrer info - universal links', + comment: '//', + }).contents + + config.modResults.contents = newContents + + return config + }) +} -- cgit 1.4.1