Search code examples
swiftxcodegetstream-io

Callbacks not called on GetStream Swift SDK


I have a blank Xcode project with GetStream integrated

Podfile :

  pod 'GetStream'

Initialized GetStream on AppDelegate :

Client.config = .init(apiKey: "XXXXX", appId: "XXXX", logsEnabled: true)
Client.shared.setupUser(token: "XXXXX") { (result) in
      // THIS IS SUCCESSFUL, working perfectly
}

On the ViewController, trying to fetch the activities from a feed (which have activities inside)

let userFeed = Client.shared.flatFeed(feedSlug: "FLAT_FEED_ID", userId: "LOGGED_USER_ID")

let activity = Activity(actor: User.current!, verb: "pin", object: "Place:72482734")

userFeed.add(activity) { result in
   print("Callback called") // ----> Never called
   if let activity = try? result.get() {
         print(activity.id) // ----> Never called
   } else {
         print("FAILED") // ----> Never called
   }
}

userFeed.get() { result in
        print(result) // ---->  Never called
}

However, since I have the logsEnabled to true, I'm able to see the raw JSON values in the Xcode Console with all my activities from that feed. The activities are successfully posted to the feed but the closures are just not called.

GetStream Environment

GetStream version: 2.2.2 Xcode version: 11.5 Swift version: 5 Platform(s) running GetStream: iOS 13.5 macOS version running Xcode: macOS 10.15.4

Additional info

I've also tried removing all the pods and installing GetStream using pod 'GetStream', '~> 2.2.2' and pod 'GetStreamActivityFeed'

`


Solution

  • Found the solution, went through the code and found that self becomes nil when the methods are called from the local scope. Creating a strong reference to the feed or activity fixed the issue.

    class ViewController {
    
        var userFeed : FlatFeed! // create strong reference
        var activity : Activity! // create strong reference
    
        override func viewDidLoad() {
            super.viewDidLoad()
            userFeed = Client.shared.flatFeed(feedSlug: "FLAT_FEED_ID", userId: "LOGGED_USER_ID")
    
            activity = Activity(actor: User.current!, verb: "pin", object: "Place:72482734")
    
            userFeed.add(activity) { [weak self] result in
                    if let activity = try? result.get() {
                            print(activity.id)
                    } else {
                              print("FAILED")
                    }
            }
    
            userFeed.get() {  [weak self] result in
                    print(result)
            }
        }
    
    }