同一视图控制器中的AWS AppSync多个订阅不起作用-iOS Swift [英] AWS AppSync multiple subscriptions in same view controller not working - iOS Swift

查看:80
本文介绍了同一视图控制器中的AWS AppSync多个订阅不起作用-iOS Swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅供参考,我发布了这个问题最初在AWS AppSync论坛中(以防将来AWS回答).

Just FYI I posted this question originally in the AWS AppSync forum (in case in the future AWS answers it).

我一直在尝试制作一个简单的Posts应用程序,例如

I have been trying to make a simple Posts app like the one in the docs but I have found no documentation or guides that handle multiple subscriptions in one view controller.

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

Three mutations: onCreatePost, onUpdatePost, onDeletePost (and of course three subscriptions to those mutations)

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

In Xcode, I have three functions called during viewDidLoad(): subscribeToNewPosts(), subscribeToUpdatedPosts(), subscribeToDeletedPosts()

每个预订功能都可以工作,并创建具有正确功能的预订,并相应地如果单独使用来更新表视图.但是,如果一个接一个地调用,则只有最后一个预订实际上会接收数据并更新表视图.订阅所有三个突变后,我在AppSyncMQTTClient.swift中设置了一个断点以查看topicSubscribersDictionary

Each subscription function works and creates a subscription with the correct functionality and updates the table view accordingly if used alone. But, if called one after the other, only the last subscription will actually receive data and update the table view. I put a breakpoint to check out topicSubscribersDictionary in AppSyncMQTTClient.swift after subscribing to all three mutations

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)
    }

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

and all three subscriptions are in fact in the dictionary...

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

Do I need multiple instances of appSyncClient, one for each subscription? Is it a problem with the schema design?

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

Example use case: simple chat app. New conversation started = OnCreatePostSubscription; new incoming message in that conversation = OnUpdatePostSubscription

推荐答案

您是否在AppSync中使用API Key进行授权?如果您使用的是API Key,则此时SDK仅支持一个订阅.您能否切换到IAM(认知身份)或基于Cognito UserPools的身份验证,看看是否有多个订阅对您有用?

Are you using API Key for authorization in AppSync? If you are using API Key only one subscription is supported by the SDK at this point. Could you switch to IAM (Cognito Identity) or Cognito UserPools based auth and see if multiple subscriptions work for you?

这篇关于同一视图控制器中的AWS AppSync多个订阅不起作用-iOS Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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