gpt4 book ai didi

swift - 如何在 iOS (Swift) 中对 AWS Appsync 进行身份验证

转载 作者:行者123 更新时间:2023-11-30 11:19:06 25 4
gpt4 key购买 nike

这里是初级开发人员。

我正在尝试让 AWS Appsync 在我当前正在构建的 iOS 应用程序中工作,但无法进行身份验证。

我想快速复制这段 Javascript 代码,以进行身份​​验证。

Amplify.configure({

Auth: {

region: "<REGION>",

userPoolId: "<USER-POOL-ID>",

userPoolWebClientId: "<USER-POOL-WEB-CLIENT-ID>"

}

});

const client = new AWSAppSyncClient({

auth: {

jwtToken: async () =>

(await Auth.currentSession()).getIdToken().getJwtToken(),

type: AUTH_TYPE.AMAZON_COGNITO_USER_POOLS

},

disableOffline: true,

region: "<REGION>",

url:

"<ENDPOINT-URL>"

});

我在这里发现了类似的问题: cannot authenticate user for aws appsync with swift SDK

但他还没有得到答案。

我用谷歌搜索了很多,但似乎找不到解决方案。你们中的一位善良的程序员灵魂能给我指出正确的方向吗?

最佳答案

适用于 iOS 的 AWS 开发工具包 - AppSync 可以解决您的使用案例。您可以在此处查看文档:https://docs.aws.amazon.com/appsync/latest/devguide/building-a-client-app-ios.html 。您可以在这里查看源代码:https://github.com/awslabs/aws-mobile-appsync-sdk-ios 。有一个入门应用程序可以帮助您快速入门:https://github.com/aws-samples/aws-mobile-appsync-events-starter-ios .

import UIKit
import AWSAppSync

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
var appSyncClient: AWSAppSyncClient?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Set up Amazon Cognito credentials
let credentialsProvider = AWSCognitoCredentialsProvider(regionType: CognitoIdentityRegion,
identityPoolId: CognitoIdentityPoolId)
// You can choose your database location, accessible by the SDK
let databaseURL = URL(fileURLWithPath:NSTemporaryDirectory()).appendingPathComponent(database_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)
// Set id as the cache key for objects
appSyncClient?.apolloClient?.cacheKeyForObject = { $0["id"] }
} catch {
print("Error initializing appsync client. \(error)")
}
return true
}

// ... other intercept methods
}

关于swift - 如何在 iOS (Swift) 中对 AWS Appsync 进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51476502/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com