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

标签 ios swift amazon-web-services graphql aws-appsync

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

我一直在尝试制作一个简单的帖子应用程序,例如 docs 中的应用程序。但我没有发现任何文档或指南可以在一个 View Controller 中处理多个订阅。

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

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

每个订阅功能都可以工作,并创建具有正确功能的订阅,并相应地更新表格 View 如果单独使用。但是,如果一个接一个地调用,则只有最后一个订阅才会真正接收数据并更新 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.graphql

schema.json

mutations.graphql

queries.graphql

subscriptions.graphql

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

最佳答案

您是否在 AppSync 中使用 API key 进行授权?如果您使用 API Key,则 SDK 目前仅支持一项订阅。您能否切换到基于 IAM(Cognito Identity)或 Cognito UserPools 的身份验证,并查看多个订阅是否适合您?

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

相关文章:

ios - 循环 AVMutableCompositionTrack

ios - UIWebBroswerView 与 UIWebView 的顶部有差距

IOS:使用dispatch_async的单元测试未执行

ios - 为 UITableView 部分构建数据结构

amazon-web-services - AWS Cloudformation Codecommit S3 400 异常

java - 读取/更新操作时出现 Dynamodb ConditionalCheckFailedException - java sdk

html - 复杂 html 的 hpple XPath 查询

ios - 是否可以同时使用 Xcode 和 Adob​​e Flex 进行开发?

ios - 使用磁力计和加速度计计算准确的偏航

amazon-web-services - 无法使用 rabbitmq-autocluster 插件对属于同一 AWS 自动缩放组的两个 AWS 实例进行集群