Skip to content

Commit

Permalink
Merge pull request #70 from olgadanylova/master
Browse files Browse the repository at this point in the history
messaging methods that use deviceId are separated for watchOS
  • Loading branch information
Olha Danylova authored May 21, 2019
2 parents 579b9d9 + 57e8bbd commit 0cc8331
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 22 deletions.
4 changes: 2 additions & 2 deletions BackendlessSwift.podspec
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Pod::Spec.new do |s|
s.name = "BackendlessSwift"
s.module_name = "Backendless"
s.version = "0.0.7"
s.source = { :git => 'https://github.com/Backendless/Swift-SDK.git', :tag => '0.0.7' }
s.version = "0.0.6"
s.source = { :git => 'https://github.com/Backendless/Swift-SDK.git', :tag => '0.0.6' }
s.license = { :type => 'MIT', :text => 'Copyright (c) 2013-2019 by Backendless Corp' }
s.homepage = "http://backendless.com"
s.authors = { 'Mark Piller' => '[email protected]', 'Olha Danylova' => '[email protected]' }
Expand Down
3 changes: 0 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# RELEASE HISTORY

### 0.0.7, / May, 21 2019
* fixed podspec bugs of v0.0.6

### 0.0.6, / May, 21 2019
* added functions to FileService:
```
Expand Down
35 changes: 18 additions & 17 deletions Sources/SwiftSDK/Messaging/MessagingService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@
}
#endif

open func getDeviceRegistrations(responseHandler: (([DeviceRegistration]) -> Void)!, errorHandler: ((Fault) -> Void)!) {
let deviceId = deviceHelper.deviceId
open func getDeviceRegistrations(deviceId: String, responseHandler: (([DeviceRegistration]) -> Void)!, errorHandler: ((Fault) -> Void)!) {
BackendlessRequestManager(restMethod: "messaging/registrations/\(deviceId)", httpMethod: .GET, headers: nil, parameters: nil).makeRequest(getResponse: { response in
if let result = self.processResponse.adapt(response: response, to: [DeviceRegistration].self) {
if result is Fault {
Expand All @@ -169,41 +168,42 @@
})
}

open func getDeviceRegistrations(deviceId: String, responseHandler: (([DeviceRegistration]) -> Void)!, errorHandler: ((Fault) -> Void)!) {
BackendlessRequestManager(restMethod: "messaging/registrations/\(deviceId)", httpMethod: .GET, headers: nil, parameters: nil).makeRequest(getResponse: { response in
if let result = self.processResponse.adapt(response: response, to: [DeviceRegistration].self) {
open func unregisterDevice(deviceId: String, responseHandler: ((Bool) -> Void)!, errorHandler: ((Fault) -> Void)!) {
BackendlessRequestManager(restMethod: "messaging/registrations/\(deviceId)", httpMethod: .DELETE, headers: nil, parameters: nil).makeRequest(getResponse: { response in
if let result = self.processResponse.adapt(response: response, to: JSON.self) {
if result is Fault {
errorHandler(result as! Fault)
}
else {
responseHandler(result as! [DeviceRegistration])
else if let result = (result as! JSON).dictionaryObject {
responseHandler(result["result"] as! Bool)
}
}
})
}

open func unregisterDevice(responseHandler: ((Bool) -> Void)!, errorHandler: ((Fault) -> Void)!) {
#if !os(watchOS)
open func getDeviceRegistrations(responseHandler: (([DeviceRegistration]) -> Void)!, errorHandler: ((Fault) -> Void)!) {
let deviceId = deviceHelper.deviceId
unregisterDevice(deviceId: deviceId, responseHandler: responseHandler, errorHandler: errorHandler)
}

open func unregisterDevice(deviceId: String, responseHandler: ((Bool) -> Void)!, errorHandler: ((Fault) -> Void)!) {
BackendlessRequestManager(restMethod: "messaging/registrations/\(deviceId)", httpMethod: .DELETE, headers: nil, parameters: nil).makeRequest(getResponse: { response in
if let result = self.processResponse.adapt(response: response, to: JSON.self) {
BackendlessRequestManager(restMethod: "messaging/registrations/\(deviceId)", httpMethod: .GET, headers: nil, parameters: nil).makeRequest(getResponse: { response in
if let result = self.processResponse.adapt(response: response, to: [DeviceRegistration].self) {
if result is Fault {
errorHandler(result as! Fault)
}
else if let result = (result as! JSON).dictionaryObject {
responseHandler(result["result"] as! Bool)
else {
responseHandler(result as! [DeviceRegistration])
}
}
})
}

open func unregisterDevice(responseHandler: ((Bool) -> Void)!, errorHandler: ((Fault) -> Void)!) {
let deviceId = deviceHelper.deviceId
unregisterDevice(deviceId: deviceId, responseHandler: responseHandler, errorHandler: errorHandler)
}

open func unregisterDevice(channels: [String], responseHandler: ((Bool) -> Void)!, errorHandler: ((Fault) -> Void)!) {
let dataQueryBuilder = DataQueryBuilder()
dataQueryBuilder.setWhereClause(whereClause: String(format: "deviceId='%@'", deviceHelper.deviceId))

Backendless.shared.data.of(DeviceRegistration.self).find(queryBuilder: dataQueryBuilder, responseHandler: { deviceRegs in
if let deviceRegs = deviceRegs as? [DeviceRegistration] {
let group = DispatchGroup()
Expand Down Expand Up @@ -250,6 +250,7 @@
errorHandler(fault)
})
}
#endif

open func publish(channelName: String, message: Any, responseHandler: ((MessageStatus) -> Void)!, errorHandler: ((Fault) -> Void)!) {
publishMessage(channelName: channelName, message: message, publishOptions: nil, deliveryOptions: nil, responseHandler: responseHandler, errorHandler: errorHandler)
Expand Down
Binary file not shown.

0 comments on commit 0cc8331

Please sign in to comment.