Last active
June 9, 2023 22:58
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Usage example | |
{ | |
"expo": { | |
"scheme": "primary scheme", // supported out of the box, but only single scheme | |
... | |
"plugins": [ | |
... | |
["./withIosCustomScheme", { customScheme: "extraScheme1" }], | |
["./withIosCustomScheme", { customScheme: "extraScheme2" }] | |
] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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