Skip to content

Commit

Permalink
fix: handle multiple scheme (ios)
Browse files Browse the repository at this point in the history
  • Loading branch information
achorein committed May 27, 2024
1 parent 57f33bf commit 562c388
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
13 changes: 10 additions & 3 deletions plugin/src/ios/writeIosShareExtensionFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,17 @@ export function getShareExtensionViewControllerContent(
scheme: string,
appIdentifier: string,
) {
let updatedScheme = scheme;
if (Array.isArray(scheme)) {
console.debug(
`[expo-share-intent] multiple scheme detected (${scheme.join(",")}), using:${updatedScheme}`,
);
updatedScheme = scheme[0];
}
console.debug(
`[expo-share-intent] add ios share extension (scheme:${scheme} appIdentifier:${appIdentifier})`,
`[expo-share-intent] add ios share extension (scheme:${updatedScheme} appIdentifier:${appIdentifier})`,
);
if (!scheme) {
if (!updatedScheme) {
throw new Error(
"[expo-share-intent] missing custom URL scheme 'expo.scheme' in app.json ! (see https://docs.expo.dev/guides/linking/#linking-to-your-app)",
);
Expand All @@ -199,6 +206,6 @@ export function getShareExtensionViewControllerContent(
);

return content
.replaceAll("<SCHEME>", scheme)
.replaceAll("<SCHEME>", updatedScheme)
.replaceAll("<APPIDENTIFIER>", appIdentifier);
}
21 changes: 15 additions & 6 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,21 @@ export const getScheme = (options?: ShareIntentOptions) => {
return options.scheme;
}
if (Constants.expoConfig?.scheme) {
options?.debug &&
console.debug(
"expoShareIntent[scheme] from expoConfig:",
Constants.expoConfig?.scheme,
);
return Constants.expoConfig?.scheme;
let updatedScheme = Constants.expoConfig?.scheme;
if (Array.isArray(Constants.expoConfig?.scheme)) {
updatedScheme = updatedScheme[0];
options?.debug &&
console.debug(
`expoShareIntent[scheme] from expoConfig: multiple scheme detected (${Constants.expoConfig?.scheme.join(",")}), using:${updatedScheme}`,
);
} else {
options?.debug &&
console.debug(
"expoShareIntent[scheme] from expoConfig:",
updatedScheme,
);
}
return updatedScheme;
}
const deepLinkUrl = createURL("dataUrl=");
const extracted = deepLinkUrl.match(/^([^:]+)/gi)?.[0] || null;
Expand Down

0 comments on commit 562c388

Please sign in to comment.