代码之家  ›  专栏  ›  技术社区  ›  KoingDev

如何在iOS客户端传递AWS-AppSync自定义请求头?

  •  0
  • KoingDev  · 技术社区  · 8 年前

    $context.request.headers文件 .

    谢谢:)
    https://docs.aws.amazon.com/appsync/latest/devguide/resolver-context-reference.html

    2 回复  |  直到 8 年前
        1
  •  1
  •   KoingDev    8 年前

    我刚刚找到了一种在iOS客户端中传递额外AWS AppSync请求头的方法:)
    以下是 AppSyncManager

    final class AppSyncManager {
    
        static func instance() -> AWSAppSyncClient {
            let tmpURL = URL(fileURLWithPath: NSTemporaryDirectory())
            let databaseURL = tmpURL.appendingPathComponent(databasName)
            let urlSessionConfiguration = URLSessionConfiguration.default
            // Our request header => In resolve mapping: $context.request.headers.author
            urlSessionConfiguration.httpAdditionalHeaders = ["author": CognitoUserPoolManager.instance.author]
            let appSyncConfig = try! AWSAppSyncClientConfiguration(url: endPointURL,
                                                                   serviceRegion: region,
                                                                   userPoolsAuthProvider: CognitoAuthProvider(),
                                                                   urlSessionConfiguration: urlSessionConfiguration,
                                                                   databaseURL: databaseURL)
            let appSyncClient = try! AWSAppSyncClient(appSyncConfig: appSyncConfig)
            appSyncClient.apolloClient?.cacheKeyForObject = { $0["id"] }
            return appSyncClient
        }
    
    }
    
        2
  •  0
  •   Hemant Singh Rathore    8 年前

    aws-mobile-appsync-sdk-ios 软件开发工具包 2.6.22