Files
otunes/apps/mobile/plugins/with-mac-catalyst.js
T

67 lines
2.6 KiB
JavaScript

const {
withEntitlementsPlist,
withPodfile,
withPodfileProperties,
withXcodeProject,
} = require("expo/config-plugins")
// Pods left at React Native's iOS 15.1 minimum map to a macOS target below what
// current Xcode accepts for Catalyst, so raise them to the app's own target.
const raisePodDeploymentTargets = `
app_target = installer.aggregate_targets.first.platform.deployment_target
installer.pods_project.targets.each do |target|
target.build_configurations.each do |build|
current = build.build_settings['IPHONEOS_DEPLOYMENT_TARGET']
if current.nil? || Pod::Version.new(current) < app_target
build.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = app_target.to_s
end
end
end
`
// Opt in during prebuild so normal iOS builds keep their precompiled dependencies.
module.exports = (config) => {
config = withPodfileProperties(config, (config) => {
config.modResults["ios.buildReactNativeFromSource"] = "true"
config.modResults.EXPO_USE_PRECOMPILED_MODULES = "false"
return config
})
// macOS rejects expo-secure-store's Keychain writes without an access group,
// and requesting one makes Xcode provision the Mac app with a profile.
config = withEntitlementsPlist(config, (config) => {
config.modResults["keychain-access-groups"] = [
`$(AppIdentifierPrefix)${config.ios.bundleIdentifier}`,
]
return config
})
config = withPodfile(config, (config) => {
const flag = /:mac_catalyst_enabled\s*=>\s*(?:false|true)/
const postInstall = /(react_native_post_install\([\s\S]*?\n {4}\)\n)/
let contents = config.modResults.contents
if (!flag.test(contents) || !postInstall.test(contents)) {
throw new Error("Cannot enable Catalyst: Expo's Podfile template has changed")
}
contents = contents.replace(flag, ":mac_catalyst_enabled => true")
contents = contents.replace(postInstall, `$1${raisePodDeploymentTargets}`)
config.modResults.contents = contents
return config
})
return withXcodeProject(config, (config) => {
const project = config.modResults
const target = project.getFirstTarget().firstTarget
const lists = project.pbxXCConfigurationList()
const configurations = project.pbxXCBuildConfigurationSection()
for (const { value } of lists[target.buildConfigurationList].buildConfigurations) {
const settings = configurations[value].buildSettings
settings.SUPPORTS_MACCATALYST = "YES"
// Share the iOS bundle ID so Handoff and the App ID match across devices.
settings.DERIVE_MACCATALYST_PRODUCT_BUNDLE_IDENTIFIER = "NO"
settings.TARGETED_DEVICE_FAMILY = '"1,2"'
}
return config
})
}