Is it possible to prepolulate an AWS AppSync iOS client?

110 Views Asked by At

We’re looking at using AWS AppSync for our next mobile project because of its offline capabilities. Using AppSync is it possible to release a mobile app (iOS / Android) with the mobile app database prepopulated with content? This is to avoid a slow mega content download the first time the app connects after being installed.

1

There are 1 best solutions below

1
On

Yes, this is possible to do. The appsync client allows you to specify your database location as part of the config. Here is some sample code that shows you how it is done

// Set up Amazon Cognito credentials
let credentialsProvider = AWSCognitoCredentialsProvider(regionType: CognitoIdentityRegion, identityPoolId: CognitoIdentityPoolId)

// Specify the location to your custom local DB
let databaseURL = URL(fileURLWithPath:NSTemporaryDirectory()).appendingPathComponent("custom_db_name")

    do {
        // Initialize the AWS AppSync configuration
        let appSyncConfig = try AWSAppSyncClientConfiguration(url: AppSyncEndpointURL, serviceRegion: AppSyncRegion, credentialsProvider: credentialsProvider, databaseURL:databaseURL)

        // Initialize the AWS AppSync client
        appSyncClient = try AWSAppSyncClient(appSyncConfig: appSyncConfig)

        ....

You can use this mechanism to include the pre-populated database in your app and then configure appsync with that path for the database.