Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 4.1 Support #32

Merged
merged 68 commits into from Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
e3aaf95
Optimize a few things.
May 19, 2017
f6318dc
Fix compiler errors in test and sample app. Add comments for OCI chan…
May 20, 2017
128e80f
Make delegates weak references to avoid circular ownership
May 20, 2017
aced669
move MQTTMessage into models
May 20, 2017
73b43e2
Create MQTTBroker protocol
May 20, 2017
b6f0c7c
create simple MQTTBatchingSession (pass-thru right now)
May 20, 2017
4c1c09c
MQTTConnectParams work in a framework
May 20, 2017
7eeb5ec
fix bug when sending data in a disconnected state
May 20, 2017
d061a22
simplify life-cycle on connection errors
May 20, 2017
ef6c835
Fix stream ready flow
May 21, 2017
848806f
move all mqttparsing into session
May 21, 2017
f3e5281
move packet parsing out of session
May 21, 2017
a1b28a1
Correct queue usage
May 21, 2017
be1346a
forgot the else
May 21, 2017
561655c
Retry logic complete (for now)
May 22, 2017
dc45c41
don’t reuse time intervals
May 22, 2017
2f33e0c
Add DatedSnapShot
May 22, 2017
72dba7d
message id change
May 22, 2017
3d6b62a
DataSnapshot sendAll
May 22, 2017
fb54cf0
fix dated snapshot
May 22, 2017
04a1cd7
fix dated snapshot again
May 22, 2017
02fc9bc
Allow data snapshot to convert messages
May 30, 2017
5949179
Fix read loop
Jun 2, 2017
b9a08a2
Swift 4 compatible with 3 changes.
Jun 8, 2017
1e1f731
Add CustomStringConvertable to message, prototype file payload enum, …
Jun 8, 2017
1355da7
cleanup lifecycle
Jun 9, 2017
78980ff
Break up networkPacket method
Jun 10, 2017
0eee21e
move stream packet logic into Streamable
Jun 12, 2017
da9c9da
bug fix
Jun 12, 2017
4c413f1
Update README.md
Jul 5, 2017
3f030cc
better session handling
Jul 26, 2017
59e351e
Merge pull request #23 from oci-pronghorn/master
adolfo Apr 17, 2018
d42e260
Update .travis.yml
f2m2rd Dec 11, 2017
875275d
Add swift_version in podspec
Apr 17, 2018
9825ed3
Bump podspec versions
Apr 17, 2018
0ef9898
Fix typo
Apr 17, 2018
375984c
Keep payload as Data to minimize changes to public interface
Apr 17, 2018
62508e3
Remove inline change comments
Apr 17, 2018
04e8133
Make keep alive timer optional
Apr 17, 2018
c532b34
Update deprecated string count
Apr 17, 2018
a786e93
Update deprecated timer method
Apr 17, 2018
cf03a7d
Update readme
Apr 17, 2018
0faa228
Cleanup whitespace
Apr 17, 2018
5f2992d
Update Example project
Apr 17, 2018
4ce906d
Fix typo
Apr 17, 2018
3e70157
Update tests to ensure connection is made in setUp before running tests
Apr 18, 2018
192f7bb
Remove extraneous } from example project
Apr 19, 2018
6af7031
Ensure callbacks are handled on the main thread
Apr 19, 2018
6bcc516
Remove new reconnecting session feature for now
Apr 19, 2018
ec89c52
Cleanup error handling
Apr 19, 2018
cc1cd83
Add ping/heartbeat callback
Apr 19, 2018
5b5dd86
Make error Equatable
Apr 19, 2018
75e63eb
Cleanup private/fileprivate
Apr 19, 2018
2f55907
General formatting cleanup
Apr 19, 2018
420b53c
Update tests and add end-to-end subscribe, publish, receive test
Apr 19, 2018
e47815d
Remove new reconnecting session feature for now
Apr 20, 2018
70671d6
Add description for errors
Apr 20, 2018
e86f89c
Remove Broker class
Apr 20, 2018
1ff2997
Don't dispatch to main thread as already on main by default
Apr 20, 2018
8bffcef
Expose desired dispatch queue for delegate callbacks, default to main
Apr 20, 2018
aa6ae85
Fix bug with reading ping packets
Apr 21, 2018
e6f86ff
Call completion blocks on delegate thread
Apr 21, 2018
c42103f
Clear the delegate when deinit'd
Apr 21, 2018
cfe64dc
Include framework as project dependency
Apr 21, 2018
35531d1
Update closure error handling
Apr 21, 2018
576d657
Use description instead of localizedDescription
Apr 21, 2018
d4dc464
Update readme
Apr 21, 2018
0a79238
Add Swift Package Manager support
Apr 21, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
@@ -1,8 +1,8 @@
language: objective-c
osx_image: xcode8
osx_image: xcode9.2
before_install:
- brew update
- brew install mosquitto
script:
- /usr/local/opt/mosquitto/sbin/mosquitto -d
- xcodebuild -project SwiftMQTT/SwiftMQTT.xcodeproj -scheme SwiftMQTT -sdk iphonesimulator -destination "name=iPhone 6s" test
- xcodebuild -project SwiftMQTT/SwiftMQTT.xcodeproj -scheme SwiftMQTT -sdk iphonesimulator -destination "name=iPhone 8 Plus" test
24 changes: 24 additions & 0 deletions Package.swift
@@ -0,0 +1,24 @@
// swift-tools-version:4.0

import PackageDescription

let package = Package(
name: "SwiftMQTT",
products: [
.library(name: "SwiftMQTT", targets: ["SwiftMQTT"]),
],
dependencies: [],
targets: [
.target(
name: "SwiftMQTT",
dependencies: [],
path: "SwiftMQTT/SwiftMQTT/"
),
.testTarget(
name: "SwiftMQTTTests",
dependencies: ["SwiftMQTT"],
path: "SwiftMQTT/SwiftMQTTTests/"
),
]
)

109 changes: 75 additions & 34 deletions README.md
@@ -1,72 +1,98 @@
# SwiftMQTT

MQTT Client in pure Swift ❤️️
MQTT Client

[![Build Status](https://travis-ci.org/aciidb0mb3r/SwiftMQTT.svg)](https://travis-ci.org/aciidb0mb3r/SwiftMQTT)
[![Version](https://img.shields.io/cocoapods/v/SwiftMQTT.svg?style=flat)](http://cocoapods.org/pods/SwiftMQTT)
[![License](https://img.shields.io/cocoapods/l/SwiftMQTT.svg?style=flat)](http://cocoapods.org/pods/SwiftMQTT)

## Info
* Fully written in Swift from ground up
* Closures everywhere 😃
* Includes test cases and sample project
* Based on MQTT Version 3.1.1 (http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718043)
* Fully written in Swift 4
* Robust error handling
* Performant
* Based on [MQTT 3.1.1 Specification](http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html)

![Sample Project Screenshot](http://i.imgur.com/9lefVmVl.png)

## How to use
## Usage

### Create Session
```swift
mqttSession = MQTTSession(host: "localhost", port: 1883, clientID: "swift", cleanSession: true, keepAlive: 15, useSSL: false)
mqttSession = MQTTSession(
host: "localhost",
port: 1883,
clientID: "swift", // must be unique to the client
cleanSession: true,
keepAlive: 15,
useSSL: false
)
```

### Connect
```swift
mqttSession.connect { (succeeded, error) -> Void in
if succeeded {
print("Connected!")
}
mqttSession.connect { error in
if error == .none {
print("Connected!")
} else {
print(error.description)
}
}
```

### Subscribe
```swift
mqttSession.subscribe(to: "/hey/cool", delivering: .atLeastOnce) { (succeeded, error) -> Void in
if succeeded {
print("Subscribed!")
}
let topic = "mytopic"
mqttSession.subscribe(to: topic, delivering: .atLeastOnce) { error in
if error == .none {
print("Subscribed to \(topic)!")
} else {
print(error.description)
}
}
```

### Unsubscribe
```swift
mqttSession.unSubscribe(from: ["/ok/cool", "/no/ok"]) { (succeeded, error) -> Void in
if succeeded {
print("unSubscribed!")
}
let topic = "mytopic"
mqttSession.unSubscribe(from: topic) { error in
if error == .none {
print("Unsubscribed from \(topic)!")
} else {
print(error.description)
}
}
```

### Publish
```swift
let jsonDict = ["hey" : "sup"]
let data = try! JSONSerialization.data(withJSONObject: jsonDict, options: .prettyPrinted)

mqttSession.publish(data, in: "/hey/wassap", delivering: .atLeastOnce, retain: false) { (succeeded, error) -> Void in
if succeeded {
print("Published!")
}
```swift
let json = ["key" : "value"]
let data = try! JSONSerialization.data(withJSONObject: json, options: .prettyPrinted)
let topic = "mytopic"

mqttSession.publish(data, in: topic, delivering: .atLeastOnce, retain: false) { error in
if error == .none {
print("Published data in \(topic)!")
} else {
print(error.description)
}
}

```

### Conform to `MQTTSessionDelegate` to receive messages
```swift
mqttSession.delegate = self
```
```swift
func mqttSession(session: MQTTSession, received message: Data, in topic: String) {
let string = String(data: message, encoding: .utf8)!
func mqttDidReceive(message: MQTTMessage, from session: MQTTSession) {
print(message.topic)
print(message.stringRepresentation)
}
```
```swift
func mqttDidDisconnect(session: MQTTSession, error: MQTTSessionError) {
if error == .none {
print("Successfully disconnected from MQTT broker")
} else {
print(error.description)
}
}
```

Expand All @@ -77,9 +103,24 @@ func mqttSession(session: MQTTSession, received message: Data, in topic: String)
Install using [CocoaPods](http://cocoapods.org) by adding the following lines to your Podfile:

````ruby
use_frameworks!
pod 'SwiftMQTT'
target 'MyApp' do
use_frameworks!
pod 'SwiftMQTT'
end
````

### Carthage

```
github "aciidb0mb3r/SwiftMQTT"
```

### Swift Package Manager

```swift
dependencies: [
.package(url: "https://github.com/aciidb0mb3r/SwiftMQTT.git", from: "3.0.0")
]
```
## License
MIT
6 changes: 4 additions & 2 deletions SwiftMQTT.podspec
Expand Up @@ -2,17 +2,19 @@
Pod::Spec.new do |s|

s.name = "SwiftMQTT"
s.version = "2.0.0"
s.version = "3.0.0"
s.summary = "MQTT Client in pure Swift"
s.description = <<-DESC
MQTT Client in Swift 3.0 based on MQTT Version 3.1.1
MQTT Client in Swift 4.1 based on MQTT Version 3.1.1
DESC

s.homepage = "https://github.com/aciidb0mb3r/SwiftMQTT"
s.license = { :type => "MIT", :file => "LICENSE" }
s.author = { "Ankit Agarwal" => "ankit.spd@gmail.com" }
s.source = { :git => "https://github.com/aciidb0mb3r/SwiftMQTT.git", :tag => s.version.to_s }

s.swift_version = "4.1"

s.ios.deployment_target = "8.0"
s.osx.deployment_target = "10.10"
s.tvos.deployment_target = "9.0"
Expand Down