Skip to content

Instantly share code, notes, and snippets.

@barthap
Last active June 9, 2023 22:58
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barthap/8064d9a8bded61a099f35b7b74a6dcc2 to your computer and use it in GitHub Desktop.
Save barthap/8064d9a8bded61a099f35b7b74a6dcc2 to your computer and use it in GitHub Desktop.
An Expo config plugin for including multiple custom URI schemes into Info.plist (CFBundleSchemes)
// Usage example
{
"expo": {
"scheme": "primary scheme", // supported out of the box, but only single scheme
...
"plugins": [
...
["./withIosCustomScheme", { customScheme: "extraScheme1" }],
["./withIosCustomScheme", { customScheme: "extraScheme2" }]
]
}
}
// copied from https://github.com/expo/expo-cli/blob/master/packages/config-plugins/src/ios/Scheme.ts
function appendScheme(scheme, infoPlist) {
if (!scheme) {
return infoPlist;
}
const existingSchemes = infoPlist.CFBundleURLTypes;
return {
...infoPlist,
CFBundleURLTypes: [
...(existingSchemes ?? []),
{
CFBundleURLSchemes: [scheme],
},
],
};
}
const withIosCustomScheme = (config, { customScheme }) => {
// Ensure the objects exist
if (!config.ios) {
config.ios = {};
}
if (!config.ios.infoPlist) {
config.ios.infoPlist = {};
}
// Append the scheme
config.ios.infoPlist = appendScheme(customScheme, config.ios.infoPlist);
return config;
};
module.exports = withIosCustomScheme;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment