如何使用AWSMobileClient设置不同的配置(awsconfiguration.json)以进行调试和发布构建类型 [英] How to setup different configuration(awsconfiguration.json) with AWSMobileClient for debug and release build types

查看:653
本文介绍了如何使用AWSMobileClient设置不同的配置(awsconfiguration.json)以进行调试和发布构建类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对debugrelease构建使用不同的配置.所有配置都存储在awsconfiguration.json内部,例如,我有两个不同的配置文件,如何设置应该使用的文件.

I want to have different configuration for debug and release builds. All the configuration is stored inside awsconfiguration.json, for example I have two different config files how can I set which file should be used.

使用AWSMobileClient.getInstance()时,它将从文件awsconfiguration.json

配置文件示例:

{
  "Version": "1.0",
  "CredentialsProvider": {
    "CognitoIdentity": {
      "Default": {
        "PoolId": "DIFFERENT_VALUES",
        "Region": "DIFFERENT_VALUES"
      }
    }
  },
  "IdentityManager": {
    "Default": {}
  },
  "CognitoUserPool": {
    "Default": {
      "AppClientSecret": "DIFFERENT_VALUES",
      "AppClientId": "DIFFERENT_VALUES",
      "PoolId": "DIFFERENT_VALUES",
      "Region": "DIFFERENT_VALUES"
    }
  }
}

更新 通过将不同的文件放在main\res\rawrelease\res\raw中,可以选择使用不同的awsconfiguration.json,例如,遵循以下 answer ,它的工作原理. 但是我想知道是否可以选择以编程方式执行此操作.

Update There is option to use different awsconfiguration.json by puting different files in main\res\raw and release\res\raw, for example by following this answer and it works. But I'm wondering whether there is an option to do it programmatically.

推荐答案

我一直在尝试实现类似的目标;根据选定的配置文件在运行时选择AWS配置.我通过入侵AWS开发工具包使其部分工作,但随后偶然发现" rel =" nofollow noreferrer> 2.11.0 .报价:

I've been trying to achieve something similar; selecting an AWS configuration at runtime based on a selected profile. I got it partially working by hacking the AWS SDK but then stumbled across release notes for AWS SDK version 2.11.0. Quoting:

添加了通过新的API将配置作为内存对象(即[String: Any]/NSDictionary)而不是默认的awsconfiguration.json传递的选项

Added the option of passing the configuration as an in-memory object (i.e. [String: Any]/NSDictionary) instead of the default awsconfiguration.json through the new API

我还在放大入门指南此处.

因此,自2019年9月9日起,可以在运行时选择AWS配置.

So since 9th September 2019 it IS possible to select an AWS configuration at runtime.

编辑:刚刚注意到,这个问题是针对Android而非iOS的.我不是Android开发人员,但经过快速搜索,发现在AWS Android SDK版本 2.13.6 (2019年6月7日).引用发行说明:

Just noticed that this question is for Android rather than iOS. I'm not an Android developer but a quick searched revealed something similar in AWS Android SDK release 2.13.6 (7th June 2019). Quoting the release notes:

添加AWSConfiguration(JSONObject)构造函数以根据通过JSONObject传递的配置构造AWSConfiguration对象

Add AWSConfiguration(JSONObject) constructor to construct a AWSConfiguration object from the configuration passed via a JSONObject

...看起来很有希望.

... which looks promising.

这篇关于如何使用AWSMobileClient设置不同的配置(awsconfiguration.json)以进行调试和发布构建类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆