Back

Realtime Feature with AppwriteCloud and iOS Swift

  • 0
  • Accounts
  • Apple
  • Realtime
  • Cloud
03WMEO
16 Jun, 2023, 16:25

Hi guys,

i'm currently trying to get this running: So i'm able to register a user or log in to the account i created, but what i try to achieve now is: i want to react to any 'Realtime' changes to this account. Like it doesnt matter if the account is created a session or anything.

My Problem: I'm not getting any feedback or response from the realtime subscription:

TypeScript
        print("subscription func ")
        let realtime = Realtime(AppwriteClient.shared.client)
        let subscription = realtime.subscribe(channel: "account", callback: { [weak self] response in
            print("realtime subscription")
            print(String(describing: response))
            DispatchQueue.main.async { 
                                     
                self?.checkforSignedin()
            }
        })
    } ```

Maybe you can help me out here a littlebit, 
Ty, your help is appreciated!
TL;DR
User is having difficulty getting a realtime subscription to work with an iOS Swift app. They have tried subscribing to the 'account' channel, but are not receiving any response or feedback. They are unsure if they are handling the response correctly or if nothing is being sent on the channel. The suggested solution is to pass an array of channels to subscribe to, and they should try the following code: ```swift let subscription = realtime.subscribe(channels: ["account"]) { response in print("realtime payload: ") print(String(describing: response)) } ```
safwan
16 Jun, 2023, 18:46

i'm not an iOS developer, but according to the docs you need to pass an array of channels you want to subscribe to.

try doing this:

TypeScript
let subscription = realtime.subscribe(channels: ["account"]) {
  response in
  print("realtime payload: ")
  print(String(describing: response))
}
03WMEO
18 Jun, 2023, 19:22

Ty, but it didn't solve it for me. I can't get it running.. I think it doesnt matter if i use channels: [] or a single channel, as i found both in the docs and can actually see that i got a realtime connection set up in my AppwriteConsole. The issue is that i cant get any output or anything in my ios app. I dont know if iam handling the reponse wrong or if nothing is send on the channel..

safwan
18 Jun, 2023, 20:59

Yup that's correct. That's my bad lmao

safwan
18 Jun, 2023, 21:01

According to your code, it seems like it should work.

Since you're subscribing to 'account', are you sure you're making changes to the 'account` channel?

safwan
18 Jun, 2023, 21:01

That's the only thing I can think of

Drake
19 Jun, 2023, 02:23

Honestly, subscribing to account can be a little wonky due to sessions and permissions.

You can try to make sure to subscribe after making sure you have a valid session, but the socket might close or so if sessions or permissions change

03WMEO
20 Jun, 2023, 21:02

Thank you!

Yeah i actually tried to make sure to have a valid session. Can i somehow track which events the server fire, probably not on cloud, i guess ? Maybe i'll try it on other channels than the account one.

Thanks again for the help.

Drake
20 Jun, 2023, 21:33

you could create a function that triggers on events...but those don't exactly match up with channels....

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more