diff --git a/packages/expo-cli/src/credentials/views/IosPushCredentials.ts b/packages/expo-cli/src/credentials/views/IosPushCredentials.ts index 2b8159de6f..c16b14169c 100644 --- a/packages/expo-cli/src/credentials/views/IosPushCredentials.ts +++ b/packages/expo-cli/src/credentials/views/IosPushCredentials.ts @@ -38,6 +38,7 @@ export class CreateIosPush implements IView { log('Successfully created Push Notification Key\n'); displayIosUserCredentials(pushKey); log(); + return null; } @@ -74,6 +75,40 @@ export class CreateIosPush implements IView { } } +export class CreateAndAssignIosPush extends CreateIosPush { + async open(ctx: Context): Promise { + const pushKey = await super.create(ctx); + + log('Successfully created Push Notification Key\n'); + displayIosUserCredentials(pushKey); + log(); + + if (ctx.hasProjectContext && pushKey) { + await this.assignToCurrentProject(ctx, pushKey.id); + log(); + } + + return null; + } + + async assignToCurrentProject(ctx: Context, pushKeyId: number) { + const experienceName = `@${ctx.projectOwner}/${ctx.manifest.slug}`; + const bundleIdentifier = ctx.manifest?.ios?.bundleIdentifier; + if (!ctx.nonInteractive && bundleIdentifier) { + const confirm = await confirmAsync({ + message: `Would you like to use this push key for the current project: ${experienceName} (${bundleIdentifier})?`, + }); + if (!confirm) { + return; + } + + const app = getAppLookupParams(experienceName, bundleIdentifier); + await ctx.ios.usePushKey(app, pushKeyId); + log(chalk.green(`Successfully assigned Push Key to ${experienceName} (${bundleIdentifier})`)); + } + } +} + export class RemoveIosPush implements IView { constructor(private accountName: string, private shouldRevoke: boolean = false) {} diff --git a/packages/expo-cli/src/credentials/views/Select.ts b/packages/expo-cli/src/credentials/views/Select.ts index dfb0200620..3bd10d5f3f 100644 --- a/packages/expo-cli/src/credentials/views/Select.ts +++ b/packages/expo-cli/src/credentials/views/Select.ts @@ -90,7 +90,7 @@ export class SelectIosExperience implements IView { handleAction(ctx: Context, accountName: string, action: string): IView | null { switch (action) { case 'create-ios-push': - return new iosPushView.CreateIosPush(accountName); + return new iosPushView.CreateAndAssignIosPush(accountName); case 'update-ios-push': return new iosPushView.UpdateIosPush(accountName); case 'remove-ios-push':