gpt4 book ai didi

ios - 同一 View Controller 中的 AWS AppSync 多个订阅不起作用 - iOS Swift

转载 作者:可可西里 更新时间:2023-11-01 00:39:17 24 4
gpt4 key购买 nike

仅供引用,我发布了这个问题 originally在 AWS AppSync 论坛中(以防将来 AWS 回答)。

我一直在尝试制作一个简单的 Posts 应用程序,就像 docs 中的应用程序一样但我没有找到在一个 View Controller 中处理多个订阅的文档或指南。

三个突变:onCreatePost、onUpdatePost、onDeletePost(当然还有对这些突变的三个订阅)

在 Xcode 中,我在 viewDidLoad() 期间调用了三个函数:subscribeToNewPosts()、subscribeToUpdatedPosts()、subscribeToDeletedPosts()

每个订阅函数都起作用并创建一个具有正确功能的订阅并相应地更新 TableView 如果单独使用。但是,如果一个接一个地调用,只有最后一个订阅会真正接收数据并更新 TableView 。在订阅所有三个突变后,我在 AppSyncMQTTClient.swift 中设置了一个断点来检查 topicSubscribersDictionary

func startNewSubscription(subscriptionInfo: AWSSubscriptionInfo) {
var topicQueue = [String]()
let mqttClient = MQTTClient<AnyObject, AnyObject>()
mqttClient.clientDelegate = self
for topic in subscriptionInfo.topics {
if topicSubscribersDictionary[topic] != nil {
// if the client wants subscriptions and is allowed we add it to list of subscribe
topicQueue.append(topic)
}
}
mqttClients.append(mqttClient)
mqttClientsWithTopics[mqttClient] = topicQueue
mqttClient.connect(withClientId: subscriptionInfo.clientId, toHost: subscriptionInfo.url, statusCallback: nil)
}

所有三个订阅实际上都在字典中...

我是否需要多个 appSyncClient 实例,每个订阅一个?是schema设计的问题吗?

schema.graphql

schema.json

mutations.graphql

queries.graphql

subscriptions.graphql

示例用例:简单的聊天应用程序。新对话开始 = OnCreatePostSubscription;该对话中的新传入消息 = OnUpdatePostSubscription

最佳答案

您是否使用 API KeyAppSync 中进行授权?如果您使用的是 API Key,此时 SDK 仅支持一个订阅。您能否切换到基于 IAM(Cognito Identity)或 Cognito UserPools 的身份验证,看看多个订阅是否适合您?

关于ios - 同一 View Controller 中的 AWS AppSync 多个订阅不起作用 - iOS Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49212271/

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