Skip to content

Commit

Permalink
feat(expo): allow customizing iCloud container identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
mfkrause committed Sep 29, 2024
1 parent d68ee26 commit 4193a01
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/expo-plugin/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ export interface RNCloudStorageConfigPluginOptions {
* The iCloud container environment to use. Defaults to 'Production'.
*/
iCloudContainerEnvironment?: 'Production' | 'Development';
/**
* The iCloud container identifier to use. Defaults to `iCloud.{appBundleIdentifier}`
*/
iCloudContainerIdentifier?: string;
}
31 changes: 20 additions & 11 deletions src/expo-plugin/withRNCloudStorageIos.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { withEntitlementsPlist, withInfoPlist, withPlugins, type ConfigPlugin } from '@expo/config-plugins';
import { type ExpoConfig } from '@expo/config-types';
import type { RNCloudStorageConfigPluginOptions } from './types';

const withRNCloudStorageInfoPlist: ConfigPlugin = (config) =>
const getICloudContainerIdentifier = (config: ExpoConfig, options: RNCloudStorageConfigPluginOptions) => {
if (options.iCloudContainerIdentifier) return options.iCloudContainerIdentifier;

if (!config?.ios?.bundleIdentifier) throw new Error('Missing iOS bundle identifier');
return `iCloud.${config.ios.bundleIdentifier}`;
};

const withRNCloudStorageInfoPlist: ConfigPlugin<RNCloudStorageConfigPluginOptions> = (config, options) =>
withInfoPlist(config, async (newConfig) => {
if (!config.ios?.bundleIdentifier) {
throw new Error('Missing iOS bundle identifier');
}
const infoPlist = newConfig.modResults;
infoPlist.NSUbiquitousContainers = {
[`iCloud.${config.ios.bundleIdentifier}`]: {
[getICloudContainerIdentifier(config, options)]: {
NSUbiquitousContainerIsDocumentScopePublic: true,
NSUbiquitousContainerSupportedFolderLevels: 'Any',
NSUbiquitousContainerName: config.slug,
Expand All @@ -24,19 +29,23 @@ const withRNCloudStorageEntitlementsPlist: ConfigPlugin<RNCloudStorageConfigPlug
throw new Error('Missing iOS bundle identifier');
}
const entitlementsPlist = newConfig.modResults;
entitlementsPlist['com.apple.developer.icloud-container-identifiers'] = [`iCloud.${config.ios.bundleIdentifier}`];
entitlementsPlist['com.apple.developer.icloud-container-identifiers'] = [
getICloudContainerIdentifier(config, options),
];
entitlementsPlist['com.apple.developer.icloud-services'] = ['CloudDocuments'];
entitlementsPlist['com.apple.developer.icloud-container-environment'] =
options?.iCloudContainerEnvironment ?? 'Production';
entitlementsPlist['com.apple.developer.ubiquity-container-identifiers'] = [`iCloud.${config.ios.bundleIdentifier}`];
entitlementsPlist[
'com.apple.developer.ubiquity-kvstore-identifier'
] = `$(TeamIdentifierPrefix)${config.ios.bundleIdentifier}`;
entitlementsPlist['com.apple.developer.ubiquity-container-identifiers'] = [
getICloudContainerIdentifier(config, options),
];

return newConfig;
});

const withRNCloudStorageIos: ConfigPlugin<RNCloudStorageConfigPluginOptions> = (config, options) =>
withPlugins(config, [withRNCloudStorageInfoPlist, [withRNCloudStorageEntitlementsPlist, options]]);
withPlugins(config, [
[withRNCloudStorageInfoPlist, options],
[withRNCloudStorageEntitlementsPlist, options],
]);

export default withRNCloudStorageIos;

0 comments on commit 4193a01

Please sign in to comment.