Skip to content

Commit

Permalink
Fix subscription on Xcode-10.2 (aciidgh#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Yurkevich committed Jun 28, 2019
1 parent 6667e19 commit 50d64ca
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
language: objective-c
osx_image: xcode9.2
language: objective-c
os: osx
osx_image: xcode10.2
xcode_sdk: iphonesimulator10.2

before_install:
- brew update
- brew install mosquitto
Expand Down
18 changes: 14 additions & 4 deletions SwiftMQTT/SwiftMQTT/Models/MQTTStreamable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,42 @@ extension Data: MQTTStreamable {
mutating func read(from read: StreamReader) -> Bool {
let totalLength = self.count
var readLength: Int = 0
self.withUnsafeBytes { (buffer: UnsafePointer<UInt8>) in

let _ = self.withUnsafeMutableBytes { (buffer) -> UInt8 in
repeat {
let b = UnsafeMutablePointer(mutating: buffer) + readLength
let point = buffer.bindMemory(to: UInt8.self)
let unsafePointer = point.baseAddress!
let b = UnsafeMutablePointer(mutating: unsafePointer) + readLength
let bytesRead = read(b, totalLength - readLength)
if bytesRead < 0 {
break
}
readLength += bytesRead
} while readLength < totalLength
return 0
}

return readLength == totalLength
}


func write(to write: StreamWriter) -> Bool {
let totalLength = self.count
guard totalLength <= 128*128*128 else { return false }
var writeLength: Int = 0
self.withUnsafeBytes { (buffer: UnsafePointer<UInt8>) in

let _ = self.withUnsafeBytes { (buffer) -> UInt8 in
repeat {
let b = UnsafeMutablePointer(mutating: buffer) + writeLength
let point = buffer.bindMemory(to: UInt8.self)
let unsafePointer = point.baseAddress!
let b = UnsafeMutablePointer(mutating: unsafePointer) + writeLength
let byteWritten = write(b, totalLength - writeLength)
if byteWritten < 0 {
break
}
writeLength += byteWritten
} while writeLength < totalLength
return 0
}
return writeLength == totalLength
}
Expand Down
6 changes: 3 additions & 3 deletions SwiftMQTTExample/SwiftMQTTExample/MQTTViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class MQTTViewController: UIViewController, MQTTSessionDelegate {
textView.text = nil
establishConnection()

NotificationCenter.default.addObserver(self, selector: #selector(MQTTViewController.keyboardWillShow(_:)), name: .UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(MQTTViewController.keyboardWillHide(_:)), name: .UIKeyboardWillHide, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(MQTTViewController.keyboardWillShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(MQTTViewController.keyboardWillHide(_:)), name: UIResponder.keyboardWillHideNotification, object: nil)

let tapGesture = UITapGestureRecognizer(target: self, action: #selector(MQTTViewController.hideKeyboard))
view.addGestureRecognizer(tapGesture)
Expand All @@ -37,7 +37,7 @@ class MQTTViewController: UIViewController, MQTTSessionDelegate {

@objc func keyboardWillShow(_ notification: Notification) {
let userInfo = (notification as NSNotification).userInfo! as NSDictionary
let kbHeight = (userInfo.object(forKey: UIKeyboardFrameBeginUserInfoKey) as! NSValue).cgRectValue.size.height
let kbHeight = (userInfo.object(forKey: UIResponder.keyboardFrameBeginUserInfoKey) as! NSValue).cgRectValue.size.height
bottomConstraint.constant = kbHeight
}

Expand Down

0 comments on commit 50d64ca

Please sign in to comment.