From 818f82aaa5c9eeaf7f69ac9984d75d4c386885b6 Mon Sep 17 00:00:00 2001 From: Erik Little Date: Thu, 17 Aug 2017 12:38:10 -0400 Subject: [PATCH] Add faqs page --- README.md | 3 ++ .../project.pbxproj | 2 + Usage Docs/FAQ.md | 44 +++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 Usage Docs/FAQ.md diff --git a/README.md b/README.md index 8b01fae..a51ef86 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,9 @@ SocketIOClient* socket = [[SocketIOClient alloc] initWithSocketURL:url config:@{ - Supports TLS/SSL - Can be used from Objective-C +## FAQS +Checkout the [FAQs](https://nuclearace.github.io/Socket.IO-Client-Swift/FAQS.html) for commonly asked questions. + ## Installation Requires Swift 3/Xcode 8.x diff --git a/Socket.IO-Client-Swift.xcodeproj/project.pbxproj b/Socket.IO-Client-Swift.xcodeproj/project.pbxproj index 0a79938..22b8236 100644 --- a/Socket.IO-Client-Swift.xcodeproj/project.pbxproj +++ b/Socket.IO-Client-Swift.xcodeproj/project.pbxproj @@ -241,6 +241,7 @@ 74DA217D1F0945E9009C19EE /* libcommonCrypto.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libcommonCrypto.tbd; path = usr/lib/system/libcommonCrypto.tbd; sourceTree = SDKROOT; }; 74F124EF1BC574CF002966F4 /* SocketBasicPacketTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketBasicPacketTest.swift; sourceTree = ""; }; CEBA56991CDA0B8200BA0389 /* SocketExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketExtensions.swift; path = Source/SocketExtensions.swift; sourceTree = ""; }; + DD52BA265A22022906AF006D /* FAQ.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; name = FAQ.md; path = "Usage Docs/FAQ.md"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -309,6 +310,7 @@ 572EF2391B51F18A00EEBB58 /* SocketIO-Mac */, 572EF2461B51F18A00EEBB58 /* SocketIO-MacTests */, 5764DF7B1B51F24A004FF46E /* Source */, + DD52BA265A22022906AF006D /* FAQ.md */, ); sourceTree = ""; }; diff --git a/Usage Docs/FAQ.md b/Usage Docs/FAQ.md new file mode 100644 index 0000000..a073439 --- /dev/null +++ b/Usage Docs/FAQ.md @@ -0,0 +1,44 @@ +## How do I connect to my WebSocket server? + +This library is **NOT** a WebSockets library. This library is only for servers that implement the socket.io protocol, +such as [socket.io](https://socket.io/). If you need a plain WebSockets client check out +[Starscream](https://github.com/daltoniam/Starscream) for Swift and [JetFire](https://github.com/acmacalister/jetfire) +for Objective-C. + +## Why isn't my event handler being called? + +One of the most common reasons your event might not be called is if the client is released by +[ARC](https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/AutomaticReferenceCounting.html). + +Take this code for example: + +```swift +class SocketManager { + func addHandlers() { + let socket = SocketIOClient(socketURL: "http://somesocketioserver.com") + + socket.on("myEvent") {data, ack in + print(data) + } + } + +} +``` + +This code is **incorrect**, and the event handler will never be called. Because as soon as this method is called `socket` +will be released and its memory reclaimed. + +A correct way would be: + +```swift +class SocketManager { + let socket = SocketIOClient(socketURL: "http://somesocketioserver.com") + + func addHandlers() { + socket.on("myEvent") {data, ack in + print(data) + } + } +} + +```