Adjust SDK for iOS

repository·master·Indexed 20 days ago

https://github.com/adjust/ios_sdk

A mobile measurement partner (MMP) integration for tracking app installs, attribution, and user engagement. The repository includes PocketSocket, a WebSocket implementation featuring PSWebSocketDriver for protocol logic, PSWebSocket for client networking, and PSWebSocketServer for hosting WebSocket servers.

Tokens
1.1K
Snippets
3
Records
4
Agent score
21%

What's inside adjust-ios_sdk

  1. How PocketSocket components work together

    master

    PocketSocket is composed of three main layers that allow for different levels of networking control:

    1. PSWebSocketDriver: The core, networkless engine. It handles the WebSocket protocol logic (handshakes, framing, and parsing) by converting raw bytes into events and vice versa. It is ideal for 'Bring your own' networking scenarios.
    2. PSWebSocket: A networking-based client implementation. It wraps NSInputStream and NSOutputStream to manage connection maintenance and uses PSWebSocketDriver internally.
    3. PSWebSocketServer: A networking-based server implementation built around CFSocket. It listens for incoming connections and creates a unique PSWebSocket instance for every successful handshake.
  2. Use PSWebSocketServer to host a WebSocket server

    master

    To host a server, use serverWithHost:port: to create a PSWebSocketServer instance. The server currently only supports the ws protocol.

    Important Lifecycle Note: The server manages the lifecycle of the PSWebSocket instances it creates. You should not attempt to manage these instances manually or detach them from the server, as the server expects to remain the delegate for all managed sockets.

    ```objc
    # import <PSWebSocket/PSWebSocketServer.h>
    
    @interface AppDelegate() <PSWebSocketServerDelegate>
    @property (nonatomic, strong) PSWebSocketServer *server;
    @end
    
    @implementation AppDelegate
    
    - (void)applicationDidFinishLaunching:(NSNotification *)notification {
        // Initialize server on a specific port
        _server = [PSWebSocketServer serverWithHost:nil port:9001];
        _server.delegate = self;
        [_server start];
    }
    
    #pragma mark - PSWebSocketServerDelegate
    
    - (BOOL)server:(PSWebSocketServer *)server acceptWebSocketWithRequest:(NSURLRequest *)request {
        // Return YES to accept the handshake
        return YES;
    }
    
    - (void)server:(PSWebSocketServer *)server webSocket:(PSWebSocket *)webSocket didReceiveMessage:(id)message {
        NSLog(@
  3. Use PSWebSocket as a client

    master

    To use PocketSocket as a client, use clientSocketWithRequest: to create a socket. The client supports both ws and wss (secure) protocols and automatically handles certificate negotiation.

    Key behaviors:

    • Compression: The client automatically requests permessage-deflate compression. If the server supports it, compression is enabled for the entire connection.
    • Timeouts: If the provided NSURLRequest has a timeout greater than 0, the connection will timeout if it cannot open within that interval.
    • SSL Pinning: For custom SSL certificate support or pinning, implement the webSocket:evaluateServerTrust: method in the PSWebSocketDelegate.
    ```objc
    # import <PSWebSocket/PSWebSocket.h>
    
    @interface AppDelegate() <PSWebSocketDelegate>
    @property (nonatomic, strong) PSWebSocket *socket;
    @end
    
    @implementation AppDelegate
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        // 1. Create the request (supports wss://)
        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@