Add faqs page

This commit is contained in:
Erik Little 2017-08-17 12:38:10 -04:00
parent 54c2b3bd35
commit 818f82aaa5
No known key found for this signature in database
GPG Key ID: 4930B7C5FBC1A69D
3 changed files with 49 additions and 0 deletions

View File

@ -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

View File

@ -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 = "<group>"; };
CEBA56991CDA0B8200BA0389 /* SocketExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketExtensions.swift; path = Source/SocketExtensions.swift; sourceTree = "<group>"; };
DD52BA265A22022906AF006D /* FAQ.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; name = FAQ.md; path = "Usage Docs/FAQ.md"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -309,6 +310,7 @@
572EF2391B51F18A00EEBB58 /* SocketIO-Mac */,
572EF2461B51F18A00EEBB58 /* SocketIO-MacTests */,
5764DF7B1B51F24A004FF46E /* Source */,
DD52BA265A22022906AF006D /* FAQ.md */,
);
sourceTree = "<group>";
};

44
Usage Docs/FAQ.md Normal file
View File

@ -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)
}
}
}
```