Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use AWSMobileClient without `awsconfiguration.json`in iOS

I'd like to authenticate an iOS device to use AppSync/S3 services via Cognito user pools. The AWSMobileClient provides some nice conveniences but the initialization requires that you're bundle have an awsconfiguration.json file -- which our application will define dynamically. Is there a way to configure that manually?

like image 364
tgk Avatar asked Dec 31 '18 18:12

tgk


2 Answers

The current solution is to use the multi-environment workflow from the CLI. https://aws-amplify.github.io/docs/cli/multienv?sdk=ios


Edit

If the multi-environment workflow from the Amplify team doesn't work for you, what you can do is create debug and prod versions of your config, and then create a build phase that copies the correct one based on your build settings (debug vs release, etc). This is working extremely well for one of my projects.

Config files

Build phases

#export; #Prints list of all xcode variables with values
printf "$CONFIGURATION\n";

if [ "$CONFIGURATION" = "Debug" ]; then
printf "creating debug configuration";
cp -r "$PROJECT_DIR/awsconfiguration-debug.json" "$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.app/awsconfiguration.json"
else 
printf "creating production configuration";
cp -r "$PROJECT_DIR/awsconfiguration-prod.json" "$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.app/awsconfiguration.json"
fi
like image 143
Mongo Avatar answered Sep 30 '22 07:09

Mongo


As of AWS iOS SDK 2.11.0 (9th September 2019) it is now possible to configure without an awsconfiguration.json file.

It's even documented in the amplify documentation here

See also my answer to a related question

like image 34
Nick Ager Avatar answered Sep 30 '22 06:09

Nick Ager