Latest 1.0.0
Homepage https://github.com/truebucha/FeathersjsClientSwift
License MIT
Platforms ios 8.0
Dependencies Socket.IO-Client-Swift
Frameworks Foundation
Authors

CI Status
Version
License
Platform

Description

Feathersjs SocketIO Client for iOS wrote in Swift 3.0

Could receive and emit events(with/without ack), handle server responses using clear response object.
Processing auto reconnects, but you should handle Authentification yourself.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.
You could use local featherjs server by cloninig this repo https://github.com/truebucha/FeathersjsTestApp

HOWTO use http transport

add to your app info plist

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
        <key>NSExceptionDomains</key>
        <dict>
            <key>127.0.0.1</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <key>NSTemporaryExceptionMinimumTLSVersion</key>
                <string>TLSv1.1</string>
            </dict>
            <key>featherstest.herokuapp.com</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <key>NSTemporaryExceptionMinimumTLSVersion</key>
                <string>TLSv1.1</string>
            </dict>
        </dict>
    </dict>

HOWTO connect

        self.feathers = FeathersClient(URL: URL(string: "https://feathersjs-client-swift.herokuapp.com/")!,
                                       namespace: nil,
                                       token: "sdfsdfsdf",
                                       timeout: 60)

        let auth = UserAuth(email: "[email protected]", password: "pass5")

        guard auth != nil else {
            print("Email should be valid and password length should be more than 5 symbols")
            return
        }

        feathers?.onConnect = { [unowned self] response, ack in

            do { try self.feathers?.authorize(auth!) { (response) in
                let error = response.extractError()
                guard error == nil else {
                    print("Authentification error: rn (error)")
                    return
                }

                let object = response.extractDataObject()
                let ID = object?["id"]
                let userID = ID as? Int

                guard userID != nil else {
                    let reason = NSLocalizedString("INVALID_USER_ID", comment: "")
                    print("Authentification error: rn (reason)")
                    return
                }
                print("Signed in as user with id (userID)")
                // Do you stuff here
                }
            } catch {
                print("Connection error: rn (error)")
            }
        }

        feathers?.onError = { response, ack in
            if case let FeathersResponse.error(error) = response {
                print("Connection error: rn (error)")    
            }
        }

        feathers?.onDisconnect = { response, ack in
            print("Connection disconnect")
        }

        feathers?.onUnathorize = { response, ack in
            print("Connection unauthorized")
        }

        feathers?.connect()

HOWTO send event (create user)


        let object: FeathersRequestObject = ["email": "[email protected]",
                                             "password" : "pass5"]
        let emitter = Emitter(feathers: self.feathers!,
                              event: "users::create",
                              authRequired: false)

        do { try emitter.emitWithAck(object) { (response) in
            let error = response.extractError()
            guard error == nil else {
                print("Creation error error: rn (error)")
                return
            }
            let object = response.extractResponseObject()
            print("Received (object)")
            // you stuff
            }
        } catch {
            print("Connection error: rn (error)") 
        }

HOWTO receive event (unauthorization event)

        authFailedReceiver =  Receiver(feathers: self.feathers!,
                                       event: "unauthorized")
        do { try
            self.authFailedReceiver?.startListening() { (response, ack) in
            let object = response.extractResponseObject()
                print("Received unauthentification event (object)")
            }
        } catch {
            print("===== authFailedReceiver has error: (error)")
        }

Requirements

Installation

FeathersjsClientSwift is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "FeathersjsClientSwift"

Author

Kanstantsin Bucha, [email protected]

License

FeathersjsClientSwift is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "FeathersjsClientSwift",
    "version": "1.0.0",
    "summary": "Feathersjs Client for iOS wrote in swift 3.0",
    "description": "Feathersjs Client for iOS wrote in swift 3.0. Working on socketIO iOS under the hood. The framework stable.n This verions still under development because Feathersjs response has plenty ogf different formats and I still working on Response parser to handle it carefully. I set deployment target to 9.0 but it is possible to downgrade it if any requests will occure.",
    "homepage": "https://github.com/truebucha/FeathersjsClientSwift",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Kanstantsin Bucha": "[email protected]"
    },
    "source": {
        "git": "https://github.com/truebucha/FeathersjsClientSwift.git",
        "tag": "1.0.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "FeathersjsClientSwift/Classes/**/*.{swift}",
    "frameworks": "Foundation",
    "dependencies": {
        "Socket.IO-Client-Swift": [
            "8.3.3"
        ]
    },
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This