Page 1 of 1

[UPDATE] New Client API update

Posted: 20 Jul 2023, 16:14
by Lapo
We have just released a small update for all our client API, which addresses the caching of UserVariables when users enter and leave multiple Rooms. A recent bug submission has pointed to a specific situation in which a UserVariable would remain in the cache, potentially wasting some memory.

You can read more in the related support forum discussion:
https://forums.smartfoxserver.com/v ... 18&t=31191

And download the latest release from our API Download page:
https://www.smartfoxserver.com/download/sfs2x#p=client

Cheers

Re: [UPDATE] New Client API update

Posted: 26 Jul 2025, 17:39
by scott1224
I am trying to get the updated Api for IOS/Objective C. It says there is a version 1.8.4 but the download is giving me 1.7.15.

I have downloaded the Smartfoxserver 2_19_1.dmg and the patch 2.20.3 and this is the code files I am trying to use. I have commented ou the errors and files that are not working.

Bridging-Header.h

Code: Select all

#import <CFNetwork/CFNetwork.h>
#import <QuartzCore/QuartzCore.h>
#import <Security/Security.h>
#import <SFS2XAPIIOS/SmartFox2XClient.h>

//#import <SFS2XAPIIOS/SmartFox2XClient.h>
#import <SFS2XAPIIOS/SFSEvent.h>
#import <SFS2XAPIIOS/ISFSEvents.h>
//#import <SFS2XAPIIOS/SFSConfig.h>
#import <SFS2XAPIIOS/ConfigData.h> //Trial file to connect
#import <SFS2XAPIIOS/SFSObject.h>
#import <SFS2XAPIIOS/LoginRequest.h>
#import <SFS2XAPIIOS/ExtensionRequest.h>
#import <SFS2XAPIIOS/JoinRoomRequest.h>

import Foundation

final class SmartFoxManager: NSObject, ObservableObject, ISFSEvents {

    static let shared = SmartFoxManager()

    @Published var isConnected = false
    @Published var isLoggedIn = false
    @Published var lastError: String?

    private var sfs: SmartFox2XClient?

    // MARK: - Connect

    func connect(host: String = "127.0.0.1",
                 port: Int32 = 9933,
                 zone: String = "BasicExamples",
                 debug: Bool = true) {

        // Build config
        let cfg = ConfigData() //SFSConfig()
        cfg.host = host
        cfg.port = port //Cannot assign Int32 to Int
        cfg.zone = zone //Cannot assign a value: 'zone' is a  method
        cfg.debug = debug

        // Create client
        sfs = SmartFox2XClient(config: cfg, delegate: self)  //Cannot convert value of type ConfigData to expected type Bool
        sfs?.connect()
    }

    // MARK: - Login

    func login(username: String, password: String? = nil) {
        guard let sfs = sfs, sfs.isConnected else { return }
        let req = LoginRequest(userName: username, password: password, zoneName: nil, params: nil)
        sfs.send(req)
    }

    // MARK: - Send extension command example

    func sendExtension(cmd: String, params: [String: Any]) {
        guard let sfs = sfs, sfs.isConnected else { return }

        let obj = SFSObject()
        params.forEach { key, value in
            switch value {
            case let v as Int:    obj.putInt(key, value: Int(Int32(v)))
            case let v as Bool:   obj.putBool(key, value: v)
            case let v as String: obj.putUtfString(key, value: v)
            default: break
            }
        }

        let req = ExtensionRequest()
        sfs.send(req)
    }
}

// MARK: - ISFSEventDelegate

extension SmartFoxManager: ISFSEventDelegate {  //Cannot find ISFSEventDelegate

    func dispatch(_ evt: SFSEvent!) {
        guard let evt = evt else { return }

        switch evt.type {
        case SFSEvent.CONNECTION: //SFSEvent has no member CONNECTION
            let success = evt.params?["success"] as? Bool ?? false
            DispatchQueue.main.async {
                self.isConnected = success
            }
            print("SFS Connection:", success)

        case SFSEvent.CONNECTION_LOST: //SFSEvent has no member CONNECTION_LOST
            let reason = evt.params?["reason"] as? String
            DispatchQueue.main.async {
                self.isConnected = false
                self.isLoggedIn = false
                self.lastError = reason
            }
            print("SFS Disconnected. Reason:", reason ?? "unknown")

        case SFSEvent.LOGIN: //SFSEvent has no member LOGIN
            DispatchQueue.main.async {
                self.isLoggedIn = true
            }
            print("SFS Login OK")

        case SFSEvent.LOGIN_ERROR: //SFSEvent has no member LOGIN_ERROR
            let errorMsg = evt.params?["errorMessage"] as? String ?? "unknown"
            DispatchQueue.main.async {
                self.isLoggedIn = false
                self.lastError = errorMsg
            }
            print("SFS Login error:", errorMsg)

        case SFSEvent.EXTENSION_RESPONSE: //SFSEvent has no member EXTENSION_RESPONSE
            if let cmd = evt.params?["cmd"] as? String,
               let data = evt.params?["params"] as? ISFSObject {
                print("EXT RESP:", cmd, data)
                // Parse your response here
            }

        default:
            // Handle more events as you need (ROOM_JOIN, USER_ENTER_ROOM, PUBLIC_MESSAGE, etc.)
            break
        }
    }
}

Re: [UPDATE] New Client API update

Posted: 27 Jul 2025, 09:57
by Lapo
Hi Scott,
scott1224 wrote:I am trying to get the updated Api for IOS/Objective C. It says there is a version 1.8.4 but the download is giving me 1.7.15.

This unfortunately looks like of those AI spam posts... but I'll give you the benefit of the doubt :)
There is no such thing as version 1.8.4 for the Objective-C API. The latest is 1.7.15 as you will find in the relative download page: https://www.smartfoxserver.com/download#p=client
//Cannot assign Int32 to Int

You can convert the value to an Int or declare the port parameter as Int instead.

//Cannot assign a value: 'zone' is a method

use setZone("SomeValue")

//Cannot convert value of type ConfigData to expected type Bool

Because the constructor signature is as follows:

Code: Select all

SmartFox2XClient(smartFoxWithDebugMode: true, delegate: self)

You should use this instead:

Code: Select all

sfs = SmartFox2XClient(smartFoxWithDebugMode: true, delegate: self)
sfs?.connect(withConfig: cfg);


//SFSEvent has no member CONNECTION

You will find the event names as constants such as:
SFSEvent_CONNECTION
SFSEvent_LOGIN
SFSEvent_LOGOUT
etc...

Cheers

Re: [UPDATE] New Client API update

Posted: 28 Jul 2025, 03:34
by scott1224
Thanks for the reply. I asked because the download page says it was upgraded.
I just updated my account and I will try again next week.
What is the difference between SFS2XAPIIOS.xcframework and SFS2XAPIOSX.framework?

I am going to start with the first one.

Re: [UPDATE] New Client API update

Posted: 28 Jul 2025, 04:12
by Lapo
SFS2XAPIIOS.xcframework is for developing apps for iOS (iPhone/iPad/Catalyst)
SFS2XAPIOSX.framework is for developing apps for MacOS

Cheers

Re: [UPDATE] New Client API update

Posted: 28 Jul 2025, 14:42
by scott1224
Thanks lol. I do see that now.
I see the files but the files are hidden or empty. IOS finds nothing there
I started with IOS and moved to server access.
Server works but doesn't connect to zone BasicExample

I am back to IOS and failed again

I will try again tonight

Re: [UPDATE] New Client API update

Posted: 29 Jul 2025, 08:19
by Lapo
I see the files but the files are hidden or empty. IOS finds nothing there

I am not sure what you're referring to.
I would recommend to follow the documentation to setup an iOS project in XCode with the SFS2X API:
https://docs2x.smartfoxserver.com/Getti ... t-api-objc

Cheers

Re: [UPDATE] New Client API update

Posted: 29 Jul 2025, 14:22
by scott1224
Thanks for the document link,

I have been able to get some of the files working via the bridgingheader file. Next step is to make a connection.

Thanks again.