### Initialize Pusher Client (Full Setup) Source: https://context7.com/pusher/pusher-websocket-swift/llms.txt Full Pusher client setup including private/presence channels with an auth endpoint, and specifying the EU cluster. Automatic reconnection and activity timeouts are configurable. ```swift // Full setup — private/presence channels with auth endpoint, EU cluster let options = PusherClientOptions( authMethod: .endpoint(authEndpoint: "https://your-server.com/pusher/auth"), autoReconnect: true, host: .cluster("eu"), useTLS: true, activityTimeout: 30 ) let pusher = Pusher(key: "YOUR_APP_KEY", options: options) pusher.connect() ``` -------------------------------- ### Install Carthage Source: https://github.com/pusher/pusher-websocket-swift/blob/master/README.md Use Homebrew to install the Carthage dependency manager. ```bash brew update brew install carthage ``` -------------------------------- ### Setting up PusherDelegate in Swift Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/docsets/PusherSwift.docset/Contents/Resources/Documents/index.html Example of how to set up a class to conform to the PusherDelegate protocol and assign it to the Pusher connection. ```APIDOC ## Swift Delegate Setup ### Description This example demonstrates how to set up a `UIViewController` to conform to the `PusherDelegate` protocol and assign it as the delegate for the Pusher connection. ### Code ```swift class ViewController: UIViewController, PusherDelegate { override func viewDidLoad() { super.viewDidLoad() let pusher = Pusher(key: "APP_KEY") pusher.connection.delegate = self // ... other setup } // Implement PusherDelegate methods as needed func changedConnectionState(from old: ConnectionState, to new: ConnectionState) { // Handle connection state change } // ... other delegate methods } ``` ``` -------------------------------- ### Setting up PusherDelegate in Objective-C Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/docsets/PusherSwift.docset/Contents/Resources/Documents/index.html Example of how to set up a class to conform to the PusherDelegate protocol and assign it to the Pusher connection in Objective-C. ```APIDOC ## Objective-C Delegate Setup ### Description This example shows how to set up an Objective-C class to conform to the `PusherDelegate` protocol and assign it as the delegate for the Pusher connection. ### Code ```objectivec @interface ViewController : UIViewController @property (nonatomic, strong) Pusher *client; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.client = [[Pusher alloc] initWithAppKey:@"YOUR_APP_KEY"]; self.client.connection.delegate = self; // ... other setup } // Implement PusherDelegate methods as needed - (void)changedConnectionState:(PusherConnectionState)from to:(PusherConnectionState)to { // Handle connection state change } // ... other delegate methods @end ``` ``` -------------------------------- ### Authenticated Channel Example Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/docsets/PusherSwift.docset/Contents/Resources/Documents/index.html Example of setting up an authenticated channel using a custom `AuthRequestBuilder` in Swift. ```APIDOC ## Authenticated Channel Example (Swift) ### Description This example demonstrates how to implement `AuthRequestBuilderProtocol` to create custom authentication requests for authenticated channels. ### AuthRequestBuilder Implementation ```swift class AuthRequestBuilder: AuthRequestBuilderProtocol { func requestFor(socketID: String, channelName: String) -> URLRequest? { var request = URLRequest(url: URL(string: "http://localhost:9292/builder")!) request.httpMethod = "POST" request.httpBody = "socket_id=\(socketID)&channel_name=\(channel.name)".data(using: String.Encoding.utf8) request.addValue("myToken", forHTTPHeaderField: "Authorization") return request } } ``` ### Pusher Instantiation with AuthRequestBuilder ```swift let options = PusherClientOptions( authMethod: AuthMethod.authRequestBuilder(authRequestBuilder: AuthRequestBuilder()) ) let pusher = Pusher( key: "APP_KEY", options: options ) ``` ``` -------------------------------- ### Initialize Pusher Client (Minimal Setup) Source: https://context7.com/pusher/pusher-websocket-swift/llms.txt Minimal Pusher client initialization for public channels only, with TLS enabled by default. Ensure a strong reference to the Pusher instance is maintained. ```swift import PusherSwift // Minimal setup — public channels only, TLS enabled by default let pusher = Pusher(key: "YOUR_APP_KEY") pusher.connect() ``` -------------------------------- ### Install PusherSwift with CocoaPods Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/docsets/PusherSwift.docset/Contents/Resources/Documents/index.html Use this command to install the Cocoapods gem if you don't have it. This is the recommended method for installing PusherSwift. ```bash $ gem install cocoapods ``` -------------------------------- ### Swift: Implement All PusherDelegate Functions Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/docsets/PusherSwift.docset/Contents/Resources/Documents/index.html Example implementation of all optional functions within the `PusherDelegate` protocol. Use these functions to handle various connection and event states. ```swift class DummyDelegate: PusherDelegate { func changedConnectionState(from old: ConnectionState, to new: ConnectionState) { // ... } func debugLog(message: String) { // ... } func subscribedToChannel(name: String) { // ... } func failedToSubscribeToChannel(name: String, response: URLResponse?, data: String?, error: NSError?) { // ... } func receivedError(error: PusherError) { let message = error.message if let code = error.code { // ... } } func failedToDecryptEvent(eventName: String, channelName: String, data: String?) { // ... } } ``` -------------------------------- ### Install Carthage Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/docsets/PusherSwift.docset/Contents/Resources/Documents/index.html Install Carthage, a decentralized dependency manager, using Homebrew. This is an alternative method for adding frameworks to your Cocoa application. ```bash $ brew update $ brew install carthage ``` -------------------------------- ### Install PusherSwift with CocoaPods Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/index.html Use this command to install the Cocoapods gem if you don't have it already. Ensure you have the latest version by cleaning the cache and updating the repository. ```bash gem install cocoapods ``` ```ruby source 'https://github.com/CocoaPods/Specs.git' platform :ios, '10.0' use_frameworks! pod 'PusherSwift', '~> 10.1.0' ``` ```bash pod install ``` ```bash pod cache clean pod repo update PusherSwift pod install ``` -------------------------------- ### Dummy Delegate Implementation in Swift Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/docsets/PusherSwift.docset/Contents/Resources/Documents/index.html A comprehensive example of a Swift class implementing all optional functions of the PusherDelegate protocol. ```APIDOC ## Swift Dummy Delegate Example ### Description This example provides a `DummyDelegate` class in Swift that implements all the optional methods of the `PusherDelegate` protocol, showing how each method can be used. ### Code ```swift class DummyDelegate: PusherDelegate { func changedConnectionState(from old: ConnectionState, to new: ConnectionState) { print("Connection state changed from \(old) to \(new)") } func debugLog(message: String) { print("Pusher Debug: \(message)") } func subscribedToChannel(name: String) { print("Successfully subscribed to channel: \(name)") } func failedToSubscribeToChannel(name: String, response: URLResponse?, data: String?, error: NSError?) { print("Failed to subscribe to channel \(name). Error: \(error?.localizedDescription ?? "Unknown error")") } func receivedError(error: PusherError) { let message = error.message if let code = error.code { print("Pusher Error: Code \(code), Message: \(message)") } else { print("Pusher Error: \(message)") } } func failedToDecryptEvent(eventName: String, channelName: String, data: String?) { print("Failed to decrypt event \(eventName) on channel \(channelName)") } } ``` ``` -------------------------------- ### Implement PusherDelegate Functions in Swift Source: https://github.com/pusher/pusher-websocket-swift/blob/master/README.md Example implementation of all optional functions within the PusherDelegate protocol in a Swift class. This demonstrates how to handle various connection and event callbacks. ```swift class DummyDelegate: PusherDelegate { func changedConnectionState(from old: ConnectionState, to new: ConnectionState) { // ... } func debugLog(message: String) { // ... } func subscribedToChannel(name: String) { // ... } func failedToSubscribeToChannel(name: String, response: URLResponse?, data: String?, error: NSError?) { // ... } func receivedError(error: PusherError) { let message = error.message if let code = error.code { // ... } } func failedToDecryptEvent(eventName: String, channelName: String, data: String?) { // ... } } ``` -------------------------------- ### Install Dependencies with CocoaPods Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/docsets/PusherSwift.docset/Contents/Resources/Documents/index.html Run this command after updating your Podfile to install PusherSwift and its dependencies. If you encounter issues with outdated versions, try cleaning the cache and updating the repository. ```bash $ pod install ``` -------------------------------- ### Swift Authenticated Channel Setup Source: https://github.com/pusher/pusher-websocket-swift/blob/master/README.md Set up an authenticated channel in Swift using a custom `AuthRequestBuilder`. ```swift class AuthRequestBuilder: AuthRequestBuilderProtocol { func requestFor(socketID: String, channelName: String) -> URLRequest? { var request = URLRequest(url: URL(string: "http://localhost:9292/builder")!) request.httpMethod = "POST" request.httpBody = "socket_id=\(socketID)&channel_name=\(channel.name)".data(using: String.Encoding.utf8) request.addValue("myToken", forHTTPHeaderField: "Authorization") return request } } let options = PusherClientOptions( authMethod: AuthMethod.authRequestBuilder(authRequestBuilder: AuthRequestBuilder()) ) let pusher = Pusher( key: "APP_KEY", options: options ) ``` -------------------------------- ### Objective-C Authenticated Channel Setup Source: https://github.com/pusher/pusher-websocket-swift/blob/master/README.md Set up an authenticated channel in Objective-C using a custom `AuthRequestBuilder`. ```objc @interface AuthRequestBuilder : NSObject - (NSURLRequest *)requestForSocketID:(NSString *)socketID channelName:(NSString *)channelName; @end @implementation AuthRequestBuilder - (NSURLRequest *)requestForSocketID:(NSString *)socketID channelName:(NSString *)channelName { NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:@"http://localhost:9292/pusher/auth"]]; NSMutableURLRequest *mutableRequest = [[NSMutableURLRequest alloc] initWithURL: [[NSURL alloc] initWithString:@"http://localhost:9292/pusher/auth"]]; NSString *dataStr = [NSString stringWithFormat: @"socket_id=%@&channel_name=%@", socketID, channelName]; NSData *data = [dataStr dataUsingEncoding:NSUTF8StringEncoding]; mutableRequest.HTTPBody = data; mutableRequest.HTTPMethod = @"POST"; [mutableRequest addValue:@"myToken" forHTTPHeaderField:@"Authorization"]; request = [mutableRequest copy]; return request; } @end OCAuthMethod *authMethod = [[OCAuthMethod alloc] initWithAuthRequestBuilder:[[AuthRequestBuilder alloc] init]]; PusherClientOptions *options = [[PusherClientOptions alloc] initWithAuthMethod:authMethod]; ``` -------------------------------- ### Configure Pusher Client with Cluster (Swift) Source: https://github.com/pusher/pusher-websocket-swift/blob/master/README.md Set a custom cluster for the Pusher client using the 'host' option. This example connects to the 'eu' cluster. ```swift let options = PusherClientOptions( host: .cluster("eu") ) ``` -------------------------------- ### Trigger a Client Event (Swift) Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/docsets/PusherSwift.docset/Contents/Resources/Documents/index.html Shows how to trigger a client event on an authorized channel. Ensure the channel is private or presence and has been successfully subscribed to. Event names must start with 'client-'. ```swift chan.trigger(eventName: "client-myEvent", data: ["myName": "Bob"]) ``` -------------------------------- ### Run Consumption Tests for Carthage Suites Only Source: https://github.com/pusher/pusher-websocket-swift/blob/master/Consumption-Tests/README.md Execute only the Carthage-related consumption test suites (`Carthage-Minimum` and `Carthage-Latest`) and skip others. This command also skips Swift Package Manager and Cocoapods installations. ```sh sh ./Consumption-Tests/run-tests-LOCALLY.sh -skip-spm -skip-cocoapods ``` -------------------------------- ### init (withAppKey:options:) Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/docsets/PusherSwift.docset/Contents/Resources/Documents/Classes/Pusher.html Initializes the Pusher client with an application key and client options. ```APIDOC ## init ### Description Initializes the Pusher client with an application key and client options. ### Method Signature ```swift convenience init(withAppKey key: String, options: PusherClientOptions) ``` ``` -------------------------------- ### Clean CocoaPods Cache and Update Repository Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/docsets/PusherSwift.docset/Contents/Resources/Documents/index.html If you are not getting the most recent version of PusherSwift, try cleaning the CocoaPods cache, updating the repository, and then running pod install again. ```bash $ pod cache clean $ pod repo update PusherSwift $ pod install ``` -------------------------------- ### init (withKey:) Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/docsets/PusherSwift.docset/Contents/Resources/Documents/Classes/Pusher.html Initializes the Pusher client with just an application key. ```APIDOC ## init ### Description Initializes the Pusher client with just an application key. ### Method Signature ```swift convenience init(withKey key: String) ``` ``` -------------------------------- ### Update CocoaPods Cache and Install Source: https://github.com/pusher/pusher-websocket-swift/blob/master/README.md If the latest version is not installed, clear the CocoaPods cache, update the PusherSwift repository, and then run pod install. Also, check Podfile.lock for version conflicts. ```bash pod cache clean pod repo update PusherSwift pod install ``` -------------------------------- ### Pusher Client Instantiation with Options Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/docsets/PusherSwift.docset/Contents/Resources/Documents/index.html Shows how to instantiate the Pusher client with provided options. ```APIDOC ## Swift Pusher Instantiation ### Description Instantiate the `Pusher` client with an app key and custom `PusherClientOptions`. ### Code ```swift let options = PusherClientOptions( authMethod: .endpoint(authEndpoint: "http://localhost:9292/pusher/auth") ) let pusher = Pusher(key: "APP_KEY", options: options) ``` ## Objective-C Pusher Instantiation ### Description Instantiate the `Pusher` client using Objective-C specific options. ### Code ```objectivec OCAuthMethod *authMethod = [[OCAuthMethod alloc] initWithAuthEndpoint:@"https://your.authendpoint/pusher/auth"]; OCPusherHost *host = [[OCPusherHost alloc] initWithCluster:@"eu"]; PusherClientOptions *options = [[PusherClientOptions alloc] initWithOcAuthMethod:authMethod autoReconnect:YES ocHost:host port:nil useTLS:YES activityTimeout:nil]; pusher = [[Pusher alloc] initWithAppKey:@"YOUR_APP_KEY" options:options]; ``` ``` -------------------------------- ### PusherClientOptions Initialization Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/docsets/PusherSwift.docset/Contents/Resources/Documents/index.html Demonstrates how to initialize PusherClientOptions with different configurations for Swift and Objective-C. ```APIDOC ## Swift Initialization ### Description Initialize `PusherClientOptions` with a cluster host. ### Code ```swift let options = PusherClientOptions( host: .cluster("eu") ) ``` ## Objective-C Initialization ### Description Initialize `PusherClientOptions` with an Objective-C specific authentication method and host. ### Code ```objectivec OCAuthMethod *authMethod = [[OCAuthMethod alloc] initWithAuthEndpoint:@"https://your.authendpoint/pusher/auth"]; OCPusherHost *host = [[OCPusherHost alloc] initWithCluster:@"eu"]; PusherClientOptions *options = [[PusherClientOptions alloc] initWithOcAuthMethod:authMethod autoReconnect:YES ocHost:host port:nil useTLS:YES activityTimeout:nil]; ``` ``` -------------------------------- ### Example Pusher Error Bash (Existing Subscription) Source: https://github.com/pusher/pusher-websocket-swift/blob/master/README.md Example of a 'pusher:error' event indicating an attempt to subscribe to an already subscribed channel. ```bash "{\"event\":\"pusher:error\",\"data\":{\"code\":null,\"message\":\"Existing subscription to channel presence-channel\"}}" ``` -------------------------------- ### Initialize OCPusherHost with Default Settings Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/Classes/OCPusherHost.html Use this initializer to create an OCPusherHost instance with default settings. No specific host or cluster is provided. ```swift override public init() ``` -------------------------------- ### init() Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/docsets/PusherSwift.docset/Contents/Resources/Documents/Classes/OCPusherHost.html Initializes an OCPusherHost object with default settings. This initializer is undocumented in the source. ```APIDOC ## init() ### Description Initializes an OCPusherHost object with default settings. This initializer is undocumented in the source. ### Declaration ```swift override public init() ``` ``` -------------------------------- ### Example Pusher Error Bash (Invalid Signature) Source: https://github.com/pusher/pusher-websocket-swift/blob/master/README.md Example of a 'pusher:error' event indicating an invalid authentication signature generated by the client's auth mechanism. ```bash "{\"event\":\"pusher:error\",\"data\":{\"code\":null,\"message\":\"Invalid signature: Expected HMAC SHA256 hex digest of 200557.5043858:presence-channel:{\"user_id\":\"200557.5043858\"}, but got 8372e1649cf5a45a2de3cd97fe11d85de80b214243e3a9e9f5cee502fa03f880\"}}" ``` -------------------------------- ### Initialize Pusher with App Key and Options Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/Classes/Pusher.html Initialize the Pusher client with an application key and client options. ```swift convenience init(withAppKey key: String, options: PusherClientOptions) ``` -------------------------------- ### Initialization Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/Classes/Pusher.html Initializes the Pusher client with an app key and optional client options. ```APIDOC ## init(key:options:) ### Description Initializes the Pusher client with an app key and any appropriate options. ### Parameters - **key** (String) - The Pusher app key - **options** (PusherClientOptions) - An optional collection of options ### Return Value A new Pusher client instance ``` -------------------------------- ### OCReconnectAttemptsMax Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/Classes/PusherConnection.html Objective-C compatible property to get or set the maximum number of reconnect attempts. ```APIDOC ## OCReconnectAttemptsMax ### Description Objective-C compatible property for maximum reconnect attempts. ### Declaration ```swift var OCReconnectAttemptsMax: NSNumber? { get set } ``` ``` -------------------------------- ### OCMaxReconnectGapInSeconds Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/Classes/PusherConnection.html Objective-C compatible property to get or set the maximum gap in seconds between reconnect attempts. ```APIDOC ## OCMaxReconnectGapInSeconds ### Description Objective-C compatible property for the maximum gap in seconds between reconnect attempts. ### Declaration ```swift var OCMaxReconnectGapInSeconds: NSNumber? { get set } ``` ``` -------------------------------- ### Initialization Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/Classes/OCPusherHost.html Initializes an OCPusherHost object. ```APIDOC ## Initialization ### Description Initializes an OCPusherHost object. ### Methods - `init()` - `init(host: String)` - `init(cluster: String)` ``` -------------------------------- ### Initialize Pusher Client (Objective-C) Source: https://context7.com/pusher/pusher-websocket-swift/llms.txt Objective-C initialization for Pusher client, configuring authentication, host, and TLS settings. Ensure a strong reference to the Pusher instance is maintained. ```objectivec // Objective-C OCAuthMethod *authMethod = [[OCAuthMethod alloc] initWithAuthEndpoint:@"https://your-server.com/pusher/auth"]; OCPusherHost *host = [[OCPusherHost alloc] initWithCluster:@"eu"]; PusherClientOptions *options = [[PusherClientOptions alloc] initWithOcAuthMethod:authMethod autoReconnect:YES ocHost:host port:nil useTLS:YES activityTimeout:nil]; Pusher *pusher = [[Pusher alloc] initWithAppKey:@"YOUR_APP_KEY" options:options]; [pusher connect]; ``` -------------------------------- ### Objective-C Initializer (authMethod, autoReconnect, host, port, useTLS, activityTimeout) Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/docsets/PusherSwift.docset/Contents/Resources/Documents/Classes/PusherClientOptions.html Convenience initializer for Objective-C compatibility, setting authentication, reconnection, host, port, TLS, and activity timeout. ```APIDOC ## init(ocAuthMethod:autoReconnect:ocHost:port:useTLS:activityTimeout:) ### Description Convenience initializer for Objective-C compatibility, setting authentication, reconnection, host, port, TLS, and activity timeout. ### Method `init` ### Parameters #### Path Parameters - **authMethod** (OCAuthMethod) - Required - The Objective-C authentication method. - **autoReconnect** (Bool) - Optional - Whether to automatically reconnect. - **host** (OCPusherHost) - Optional - The Objective-C host to connect to. - **port** (NSNumber?) - Optional - The port to connect to. - **useTLS** (Bool) - Optional - Whether to use TLS for the connection. - **activityTimeout** (NSNumber?) - Optional - The activity timeout in seconds. ``` -------------------------------- ### Initialize Pusher with App Key Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/Classes/Pusher.html Initialize the Pusher client with just an application key. ```swift convenience init(withKey key: String) ``` -------------------------------- ### Subscribe to a Channel and Bind Events in Objective-C Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/index.html Demonstrates how to initialize Pusher, subscribe to a channel, bind a callback to a specific event, and unbind it. Use this for managing real-time event listeners. ```objective-c Pusher *pusher = [[Pusher alloc] initWithAppKey:@"YOUR_APP_KEY"]; PusherChannel *chan = [pusher subscribeWithChannelName:@"my-channel"]; NSString *callbackId = [chan bindWithEventName:@"new-price" eventCallback:^void (PusherEvent *event) { //... }]; [chan unbindWithEventName:@"new-price" callbackId:callbackId]; ``` -------------------------------- ### Add PusherSwift Dependency via CocoaPods Source: https://context7.com/pusher/pusher-websocket-swift/llms.txt Integrate PusherSwift into your iOS project by adding it to your Podfile and running 'pod install'. ```ruby # Podfile source 'https://github.com/CocoaPods/Specs.git' platform :ios, '13.0' use_frameworks! pod 'PusherSwift', '~> 10.1.10' ``` ```bash $ pod install ``` -------------------------------- ### init(type:) Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/docsets/PusherSwift.docset/Contents/Resources/Documents/Classes/OCAuthMethod.html Initializes an OCAuthMethod with a given authentication type. ```APIDOC ## init(type:) ### Description Initializes an OCAuthMethod with a given authentication type. ### Declaration ```swift public init(type: Int) ``` ``` -------------------------------- ### Install PusherSwift with CocoaPods Source: https://github.com/pusher/pusher-websocket-swift/blob/master/README.md Add PusherSwift to your project's Podfile for iOS 10.0 and above. Ensure you are using frameworks and specify the desired version. ```ruby source 'https://github.com/CocoaPods/Specs.git' platform :ios, '10.0' use_frameworks! pod 'PusherSwift', '~> 10.1.10' ``` -------------------------------- ### PusherClientOptions Initialization Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/Classes/PusherClientOptions.html Initializes PusherClientOptions with various configuration parameters. ```APIDOC ## PusherClientOptions Initialization ### Description Initializes PusherClientOptions with various configuration parameters. ### Method `init(authMethod:attemptToReturnJSONObject:autoReconnect:host:port:path:useTLS:activityTimeout:)` ### Parameters * **authMethod** (`AuthMethod`) - The authentication method to use. * **attemptToReturnJSONObject** (`Bool`) - Whether to attempt to return JSON objects. * **autoReconnect** (`Bool`) - Whether to automatically reconnect. * **host** (`String`) - The host to connect to. * **port** (`Int`) - The port to connect to. * **path** (`String?`) - The path for the connection. * **useTLS** (`Bool`) - Whether to use TLS. * **activityTimeout** (`TimeInterval?`) - The activity timeout in seconds. ``` -------------------------------- ### Example Pusher Error JSON Source: https://github.com/pusher/pusher-websocket-swift/blob/master/README.md Illustrates the structure of error messages received from Pusher, including event name, code, and a descriptive message. ```json { "event": "pusher:error", "data": { "code": null, "message": "Error message here" } } ``` -------------------------------- ### connect Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/Classes/PusherConnection.html Establishes the WebSocket connection. ```APIDOC ## connect() ### Description Connects the websocket. ``` -------------------------------- ### Define AuthMethod Enum Source: https://github.com/pusher/pusher-websocket-swift/blob/master/README.md The AuthMethod enum defines the strategies for authenticating subscription requests. Choose the appropriate case based on your authentication setup. ```swift public enum AuthMethod { case endpoint(authEndpoint: String) case authRequestBuilder(authRequestBuilder: AuthRequestBuilderProtocol) case inline(secret: String) case authorizer(authorizer: Authorizer) case noMethod } ``` -------------------------------- ### init(host:) Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/docsets/PusherSwift.docset/Contents/Resources/Documents/Classes/OCPusherHost.html Initializes an OCPusherHost object with a specific host string. This initializer is undocumented in the source. ```APIDOC ## init(host:) ### Description Initializes an OCPusherHost object with a specific host string. This initializer is undocumented in the source. ### Declaration ```swift public init(host: String) ``` ``` -------------------------------- ### Objective-C Max Reconnect Attempts Property Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/Classes/PusherConnection.html Exposes the maximum number of reconnection attempts for Objective-C compatibility. This property is an NSNumber and can be get or set. ```swift var OCReconnectAttemptsMax: NSNumber? { get set } ``` -------------------------------- ### Objective-C Initializer (authMethod, attemptToReturnJSONObject, autoReconnect, host, port, useTLS, activityTimeout) Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/docsets/PusherSwift.docset/Contents/Resources/Documents/Classes/PusherClientOptions.html Convenience initializer for Objective-C compatibility, including attemptToReturnJSONObject. ```APIDOC ## init(ocAuthMethod:attemptToReturnJSONObject:autoReconnect:ocHost:port:useTLS:activityTimeout:) ### Description Convenience initializer for Objective-C compatibility, including attemptToReturnJSONObject. ### Method `init` ### Parameters #### Path Parameters - **authMethod** (OCAuthMethod) - Required - The Objective-C authentication method. - **attemptToReturnJSONObject** (Bool) - Optional - Whether to attempt to return a JSON object. - **autoReconnect** (Bool) - Optional - Whether to automatically reconnect. - **host** (OCPusherHost) - Optional - The Objective-C host to connect to. - **port** (NSNumber?) - Optional - The port to connect to. - **useTLS** (Bool) - Optional - Whether to use TLS for the connection. - **activityTimeout** (NSNumber?) - Optional - The activity timeout in seconds. ``` -------------------------------- ### init(authorizer:) Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/docsets/PusherSwift.docset/Contents/Resources/Documents/Classes/OCAuthMethod.html Initializes an OCAuthMethod with a custom authorizer object. ```APIDOC ## init(authorizer:) ### Description Initializes an OCAuthMethod with a custom authorizer object. ### Declaration ```swift public init(authorizer: Authorizer) ``` ``` -------------------------------- ### Objective-C Max Reconnect Gap Property Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/Classes/PusherConnection.html Exposes the maximum gap in seconds between reconnection attempts for Objective-C compatibility. This property is an NSNumber and can be get or set. ```swift var OCMaxReconnectGapInSeconds: NSNumber? { get set } ``` -------------------------------- ### Establishing a Pusher Connection Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/docsets/PusherSwift.docset/Contents/Resources/Documents/index.html Connect to Pusher by providing your application key to the Pusher constructor and then calling the connect() method. Ensure you maintain a strong reference to the Pusher client instance. ```APIDOC ## Swift ```swift let pusher = Pusher(key: "APP_KEY") pusher.connect() ``` ## Objective-C ```objectivec Pusher *pusher = [[Pusher alloc] initWithAppKey:@"YOUR_APP_KEY"]; [pusher connect]; ``` ``` -------------------------------- ### init(authEndpoint:) Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/docsets/PusherSwift.docset/Contents/Resources/Documents/Classes/OCAuthMethod.html Initializes an OCAuthMethod with a specific authentication endpoint. ```APIDOC ## init(authEndpoint:) ### Description Initializes an OCAuthMethod with a specific authentication endpoint. ### Declaration ```swift public init(authEndpoint: String) ``` ``` -------------------------------- ### Get PusherChannelType by Name Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/Enums/PusherChannelType.html A static method to retrieve the PusherChannelType corresponding to a given channel name. Use this to determine the type of a channel based on its string representation. ```swift public static func type(forName name: String) -> PusherChannelType ``` -------------------------------- ### Initialize OCPusherHost with Cluster in Objective-C Source: https://github.com/pusher/pusher-websocket-swift/blob/master/README.md Instantiate `OCPusherHost` using a cluster shortcode in Objective-C. ```objc [[OCPusherHost alloc] initWithCluster:@"YOUR_CLUSTER_SHORTCODE"]; ``` -------------------------------- ### Trigger Client Events in Swift Source: https://github.com/pusher/pusher-websocket-swift/blob/master/README.md Trigger client events on authorized private or presence channels. Event names must start with 'client-' and can only be triggered after the subscription has succeeded. ```swift chan.trigger(eventName: "client-myEvent", data: ["myName": "Bob"]) ``` -------------------------------- ### Initialize PusherClientOptions with Objective-C Auth Method Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/Classes/PusherClientOptions.html A simplified initializer for Objective-C, allowing only the specification of the authentication method. ```swift convenience init(authMethod: OCAuthMethod) ``` -------------------------------- ### Trigger Client Events Source: https://context7.com/pusher/pusher-websocket-swift/llms.txt Trigger client events directly from the client on private or presence channels. Event names must start with `client-`. Client events are NOT supported on encrypted channels. ```APIDOC ## `channel.trigger(eventName:data:)` — Client Events Trigger client events directly from the client on private or presence channels. Event names **must** start with `client-`. Client events are NOT supported on encrypted channels. ```swift let options = PusherClientOptions( authMethod: .endpoint(authEndpoint: "https://api.example.com/pusher/auth") ) let pusher = Pusher(key: "YOUR_APP_KEY", options: options) let channel = pusher.subscribe("private-collab-doc-123") // Wait until subscribed before triggering channel.bind(eventName: "pusher:subscription_succeeded") { _ in // The "client-" prefix is mandatory channel.trigger( eventName: "client-cursor-moved", data: ["x": 42, "y": 17, "userId": "user-99"] ) } pusher.connect() ``` ``` -------------------------------- ### Initialize Pusher Client Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/Classes/Pusher.html Initializes the Pusher client with an application key and custom options. ```APIDOC ## init(withAppKey:options:) ### Description Initializes the Pusher client with an application key and custom options. ### Method `convenience init(withAppKey key: String, options: PusherClientOptions)` ### Parameters - **key** (String) - The application key. - **options** (PusherClientOptions) - Custom client options. ``` ```APIDOC ## init(withKey:) ### Description Initializes the Pusher client with an application key. ### Method `convenience init(withKey key: String)` ### Parameters - **key** (String) - The application key. ``` -------------------------------- ### Install PusherSwift with Carthage Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/index.html Integrate PusherSwift into your Xcode project using Carthage by specifying the repository in your Cartfile. Ensure you are using Carthage 0.37.0 or above and the --use-xcframeworks flag for Xcode 12 compatibility. ```bash brew update brew install carthage ``` ```plaintext github "pusher/pusher-websocket-swift" ``` ```bash ./carthage update --use-xcframeworks ``` -------------------------------- ### Objective-C OCPusherHost Initializers Source: https://github.com/pusher/pusher-websocket-swift/blob/master/README.md Available initializers for the Objective-C `OCPusherHost` class. ```swift public init(host: String) ``` ```swift public init(cluster: String) ``` -------------------------------- ### Initialize PusherClientOptions for Objective-C (Basic) Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/Classes/PusherClientOptions.html This convenience initializer is designed for Objective-C compatibility, allowing configuration of authentication method, reconnection, host, port, TLS, and activity timeout. ```swift convenience init( ocAuthMethod authMethod: OCAuthMethod, autoReconnect: Bool = true, ocHost host: OCPusherHost = PusherHost.defaultHost.toObjc(), port: NSNumber? = nil, useTLS: Bool = true, activityTimeout: NSNumber? = nil ) ``` -------------------------------- ### Custom Authentication Request Builder Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/docsets/PusherSwift.docset/Contents/Resources/Documents/index.html Implement a custom authentication request builder to define how authentication requests are constructed. This example shows how to build a POST request with a socket ID and channel name in the body and an Authorization header. ```APIDOC ## Objective-C ```objectivec @interface AuthRequestBuilder : NSObject - (NSURLRequest *)requestForSocketID:(NSString *)socketID channelName:(NSString *)channelName; @end @implementation AuthRequestBuilder - (NSURLRequest *)requestForSocketID:(NSString *)socketID channelName:(NSString *)channelName { NSMutableURLRequest *mutableRequest = [[NSMutableURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:@"http://localhost:9292/pusher/auth"]]; NSString *dataStr = [NSString stringWithFormat: @"socket_id=%@&channel_name=%@", socketID, channelName]; NSData *data = [dataStr dataUsingEncoding:NSUTF8StringEncoding]; mutableRequest.HTTPBody = data; mutableRequest.HTTPMethod = @"POST"; [mutableRequest addValue:@"myToken" forHTTPHeaderField:@"Authorization"]; return [mutableRequest copy]; } @end // Usage: OCAuthMethod *authMethod = [[OCAuthMethod alloc] initWithAuthRequestBuilder:[[AuthRequestBuilder alloc] init]]; PusherClientOptions *options = [[PusherClientOptions alloc] initWithAuthMethod:authMethod]; ``` **Note:** The server expects the `Authorization` header with the value `myToken`. ``` -------------------------------- ### PusherClientOptions Initializer (Swift) Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/Classes/PusherClientOptions.html Initializes PusherClientOptions with various configuration parameters. Defaults are provided for most options. ```APIDOC ## init(authMethod:attemptToReturnJSONObject:autoReconnect:host:port:path:useTLS:activityTimeout:) ### Description Initializes PusherClientOptions with various configuration parameters. Defaults are provided for most options. ### Parameters #### Path Parameters - **authMethod** (AuthMethod) - Optional - The authentication method to use. - **attemptToReturnJSONObject** (Bool) - Optional - Whether to attempt to return JSON objects. - **autoReconnect** (Bool) - Optional - Whether to automatically reconnect. - **host** (PusherHost) - Optional - The host to connect to. - **port** (Int?) - Optional - The port to connect to. - **path** (String?) - Optional - The path for the connection. - **useTLS** (Bool) - Optional - Whether to use TLS. - **activityTimeout** (TimeInterval?) - Optional - The activity timeout in seconds. ``` -------------------------------- ### Run Full Consumption Test Suite Locally Source: https://github.com/pusher/pusher-websocket-swift/blob/master/Consumption-Tests/README.md Execute the entire suite of consumption tests on your local machine. This command initiates all test configurations. ```sh sh ./Consumption-Tests/run-tests-LOCALLY.sh ``` -------------------------------- ### Trigger Client Events on Private/Presence Channels Source: https://context7.com/pusher/pusher-websocket-swift/llms.txt Trigger client events on private or presence channels. Event names must start with `client-`. Client events are not supported on encrypted channels. Ensure you wait until subscribed before triggering. ```swift let options = PusherClientOptions( authMethod: .endpoint(authEndpoint: "https://api.example.com/pusher/auth") ) let pusher = Pusher(key: "YOUR_APP_KEY", options: options) let channel = pusher.subscribe("private-collab-doc-123") // Wait until subscribed before triggering channel.bind(eventName: "pusher:subscription_succeeded") { _ in // The "client-" prefix is mandatory channel.trigger( eventName: "client-cursor-moved", data: ["x": 42, "y": 17, "userId": "user-99"] ) } pusher.connect() ``` -------------------------------- ### Setting up the PusherDelegate Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/index.html You can set the delegate for the Pusher connection by assigning an object conforming to the PusherDelegate protocol to the `connection.delegate` property. ```APIDOC ## Setting up the PusherDelegate ### Swift Example ```swift class ViewController: UIViewController, PusherDelegate { override func viewDidLoad() { super.viewDidLoad() let pusher = Pusher(key: "APP_KEY") pusher.connection.delegate = self // ... other setup } // Implement PusherDelegate methods as needed func changedConnectionState(from old: ConnectionState, to new: ConnectionState) { print("Connection state changed from \(old) to \(new)") } func subscribedToChannel(name: String) { print("Successfully subscribed to channel: \(name)") } // ... other delegate methods } ``` ### Objective-C Example ```objectivec @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.client = [[Pusher alloc] initWithAppKey:@"YOUR_APP_KEY"]; self.client.connection.delegate = self; // ... other setup } // Implement PusherDelegate methods as needed - (void)changedConnectionState:(PusherConnectionState)from toState:(PusherConnectionState)to { NSLog(@"Connection state changed from %ld to %ld", (long)from, (long)to); } - (void)subscribedToChannelWithName:(NSString *)name { NSLog(@"Successfully subscribed to channel: %@", name); } // ... other delegate methods @end ``` ``` -------------------------------- ### Pusher Client Initialization Source: https://context7.com/pusher/pusher-websocket-swift/llms.txt Initialize the Pusher client with your app key and optional client options. The `connect()` method establishes the WebSocket connection. Ensure you maintain a strong reference to the Pusher instance. ```APIDOC ## Pusher Client Initialization ### Description Initialize the `Pusher` class with your Pusher app key and an optional `PusherClientOptions` object, then call `connect()`. Keep a strong reference to the instance (e.g., as an app delegate or view controller property). ### Usage ```swift import PusherSwift // Minimal setup — public channels only, TLS enabled by default let pusher = Pusher(key: "YOUR_APP_KEY") pusher.connect() // Full setup — private/presence channels with auth endpoint, EU cluster let options = PusherClientOptions( authMethod: .endpoint(authEndpoint: "https://your-server.com/pusher/auth"), autoReconnect: true, host: .cluster("eu"), useTLS: true, activityTimeout: 30 ) let pusher = Pusher(key: "YOUR_APP_KEY", options: options) pusher.connect() ``` ### Objective-C Usage ```objectivec #import // Minimal setup Pusher *pusher = [[Pusher alloc] initWithAppKey:@"YOUR_APP_KEY"]; [pusher connect]; // Full setup OCAuthMethod *authMethod = [[OCAuthMethod alloc] initWithAuthEndpoint:@"https://your-server.com/pusher/auth"]; OCPusherHost *host = [[OCPusherHost alloc] initWithCluster:@"eu"]; PusherClientOptions *options = [[PusherClientOptions alloc] initWithOcAuthMethod:authMethod autoReconnect:YES ocHost:host port:nil useTLS:YES activityTimeout:nil]; Pusher *pusher = [[Pusher alloc] initWithAppKey:@"YOUR_APP_KEY" options:options]; [pusher connect]; ``` ``` -------------------------------- ### init(secret:) Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/docsets/PusherSwift.docset/Contents/Resources/Documents/Classes/OCAuthMethod.html Initializes an OCAuthMethod with a secret key for authentication. ```APIDOC ## init(secret:) ### Description Initializes an OCAuthMethod with a secret key for authentication. ### Declaration ```swift public init(secret: String) ``` ``` -------------------------------- ### Pusher Initialization Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/docsets/PusherSwift.docset/Contents/Resources/Documents/Classes/Pusher.html Initializes the Pusher client with an app key and optional client options. Use this to set up your connection to Pusher. ```swift public init(key: String, options: PusherClientOptions = PusherClientOptions()) ``` -------------------------------- ### Instantiate Pusher Client with Auth Endpoint (Swift) Source: https://github.com/pusher/pusher-websocket-swift/blob/master/README.md Initialize a Pusher client with a specific authentication endpoint. Ensure the provided key and options are correct. ```swift let options = PusherClientOptions( authMethod: .endpoint(authEndpoint: "http://localhost:9292/pusher/auth") ) let pusher = Pusher(key: "APP_KEY", options: options) ``` -------------------------------- ### Initialize PusherClientOptions with Default Values Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/Classes/PusherClientOptions.html Use this initializer to create PusherClientOptions with all default settings. This is useful for basic configurations where custom options are not required. ```swift @nonobjc public init( authMethod: AuthMethod = .noMethod, attemptToReturnJSONObject: Bool = true, autoReconnect: Bool = true, host: PusherHost = .defaultHost, port: Int? = nil, path: String? = nil, useTLS: Bool = true, activityTimeout: TimeInterval? = nil ) ``` -------------------------------- ### Initialize PusherClientOptions for Objective-C (with JSON) Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/Classes/PusherClientOptions.html This convenience initializer, intended for Objective-C use, includes an option to attempt returning JSON objects, alongside standard configurations for authentication, reconnection, host, port, TLS, and activity timeout. ```swift convenience init( ocAuthMethod authMethod: OCAuthMethod, attemptToReturnJSONObject: Bool = true, autoReconnect: Bool = true, ocHost host: OCPusherHost = PusherHost.defaultHost.toObjc(), port: NSNumber? = nil, useTLS: Bool = true, activityTimeout: NSNumber? = nil ) ``` -------------------------------- ### Objective-C Initializer (authMethod) Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/docsets/PusherSwift.docset/Contents/Resources/Documents/Classes/PusherClientOptions.html Convenience initializer for Objective-C compatibility, setting only the authentication method. ```APIDOC ## init(authMethod:) ### Description Convenience initializer for Objective-C compatibility, setting only the authentication method. ### Method `init` ### Parameters #### Path Parameters - **authMethod** (OCAuthMethod) - Required - The Objective-C authentication method. ``` -------------------------------- ### PusherClientOptions Initializer Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/docsets/PusherSwift.docset/Contents/Resources/Documents/Classes/PusherClientOptions.html Initializes Pusher client options with various configuration parameters. ```APIDOC ## init(authMethod:attemptToReturnJSONObject:autoReconnect:host:port:path:useTLS:activityTimeout:) ### Description Initializes Pusher client options with various configuration parameters. ### Method `init` ### Parameters #### Path Parameters - **authMethod** (AuthMethod) - Optional - Authentication method to use. - **attemptToReturnJSONObject** (Bool) - Optional - Whether to attempt to return a JSON object. - **autoReconnect** (Bool) - Optional - Whether to automatically reconnect. - **host** (PusherHost) - Optional - The host to connect to. - **port** (Int?) - Optional - The port to connect to. - **path** (String?) - Optional - The path for the connection. - **useTLS** (Bool) - Optional - Whether to use TLS for the connection. - **activityTimeout** (TimeInterval?) - Optional - The activity timeout in seconds. ``` -------------------------------- ### init(cluster:) Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/docsets/PusherSwift.docset/Contents/Resources/Documents/Classes/OCPusherHost.html Initializes an OCPusherHost object with a specific cluster string. This initializer is undocumented in the source. ```APIDOC ## init(cluster:) ### Description Initializes an OCPusherHost object with a specific cluster string. This initializer is undocumented in the source. ### Declaration ```swift public init(cluster: String) ``` ``` -------------------------------- ### OCPusherHost Initializers Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/docsets/PusherSwift.docset/Contents/Resources/Documents/index.html Available initializers for the `OCPusherHost` class in Objective-C. ```APIDOC ## OCPusherHost Initializers ### Description These are the available initializers for the `OCPusherHost` class, used for configuring the host connection. ### Initializers - `public init(host: String)` - `public init(cluster: String)` ### Example Usage (Cluster) ```objectivec [[OCPusherHost alloc] initWithCluster:@"YOUR_CLUSTER_SHORTCODE"]; ``` ``` -------------------------------- ### Initialize Pusher Client with Objective-C Auth Method Source: https://github.com/pusher/pusher-websocket-swift/blob/master/README.md Configure the Pusher client using Objective-C specific authentication classes for auth endpoints and hosts. ```objc OCAuthMethod *authMethod = [[OCAuthMethod alloc] initWithAuthEndpoint:@"https://your.authendpoint/pusher/auth"]; OCPusherHost *host = [[OCPusherHost alloc] initWithCluster:@"eu"]; PusherClientOptions *options = [[PusherClientOptions alloc] initWithOcAuthMethod:authMethod autoReconnect:YES ocHost:host port:nil useTLS:YES activityTimeout:nil]; pusher = [[Pusher alloc] initWithAppKey:@"YOUR_APP_KEY" options:options]; ``` -------------------------------- ### Initialization Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/docsets/PusherSwift.docset/Contents/Resources/Documents/Classes/PusherChannel.html Initializes a new PusherChannel with a given name and connection. Optionally, authentication details and a subscription count change callback can be provided. ```APIDOC ## init(name:connection:auth:onSubscriptionCountChanged:) ### Description Initializes a new PusherChannel with a given name and connection. ### Parameters - `name` (String) - The name of the channel. - `connection` (PusherConnection) - The connection that this channel is relevant to. - `auth` (PusherAuth?) - Optional. A PusherAuth value if subscription is being made to an authenticated channel without using the default auth methods. - `onSubscriptionCountChanged` ((Int) -> Void)? - Optional. A closure to be called when the subscription count changes. ### Return Value A new PusherChannel instance. ``` -------------------------------- ### PusherClientOptions Initializer (Objective-C with JSON) Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/Classes/PusherClientOptions.html Initializes PusherClientOptions for Objective-C compatibility, including an option to attempt returning JSON objects. ```APIDOC ## init(ocAuthMethod:attemptToReturnJSONObject:autoReconnect:ocHost:port:useTLS:activityTimeout:) ### Description Initializes PusherClientOptions for Objective-C compatibility, including an option to attempt returning JSON objects. ### Parameters #### Path Parameters - **ocAuthMethod** (OCAuthMethod) - Required - The Objective-C authentication method. - **attemptToReturnJSONObject** (Bool) - Optional - Whether to attempt to return JSON objects. - **autoReconnect** (Bool) - Optional - Whether to automatically reconnect. - **ocHost** (OCPusherHost) - Optional - The Objective-C host to connect to. - **port** (NSNumber?) - Optional - The port to connect to. - **useTLS** (Bool) - Optional - Whether to use TLS. - **activityTimeout** (NSNumber?) - Optional - The activity timeout in seconds. ``` -------------------------------- ### Instantiate Pusher Client with Endpoint Auth (Objective-C) Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/index.html Instantiate PusherClientOptions in Objective-C using an authentication endpoint and then initialize the Pusher client. ```objectivec OCAuthMethod *authMethod = [[OCAuthMethod alloc] initWithAuthEndpoint:@"https://your.authendpoint/pusher/auth"]; OCPusherHost *host = [[OCPusherHost alloc] initWithCluster:@"eu"]; PusherClientOptions *options = [[PusherClientOptions alloc] initWithOcAuthMethod:authMethod autoReconnect:YES ocHost:host port:nil useTLS:YES activityTimeout:nil]; pusher = [[Pusher alloc] initWithAppKey:@"YOUR_APP_KEY" options:options]; ``` -------------------------------- ### init(authRequestBuilder:) Source: https://github.com/pusher/pusher-websocket-swift/blob/master/docs/docsets/PusherSwift.docset/Contents/Resources/Documents/Classes/OCAuthMethod.html Initializes an OCAuthMethod using a custom authentication request builder. ```APIDOC ## init(authRequestBuilder:) ### Description Initializes an OCAuthMethod using a custom authentication request builder. ### Declaration ```swift public init(authRequestBuilder: AuthRequestBuilderProtocol) ``` ```