Skip to content

Commit

Permalink
Fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
dkrutskikh committed Apr 15, 2021
1 parent ccf5238 commit eb5e809
Show file tree
Hide file tree
Showing 6 changed files with 416 additions and 52 deletions.

This file was deleted.

5 changes: 0 additions & 5 deletions ios/Classes/Date.swift

This file was deleted.

46 changes: 34 additions & 12 deletions ios/Classes/SwiftTelematicsSDKPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,16 @@ public class SwiftTelematicsSDKPlugin: NSObject, FlutterPlugin, RPLowPowerModeDe
var res = [String]()

tags?.tags.forEach { element in
let str = String(data: element.toJSON() as! Data, encoding: .utf8)!
res.append(str)
do {
let json = try JSONSerialization.data(withJSONObject: element.toJSON(), options: .prettyPrinted)
let str = String(data: json, encoding: .utf8)!
res.append(str)
} catch {
result(FlutterError(code: FlutterPluginCode.failure,
message: "Json serialization of tag failed",
details: nil)
)
}
}

result(res)
Expand All @@ -209,7 +217,7 @@ public class SwiftTelematicsSDKPlugin: NSObject, FlutterPlugin, RPLowPowerModeDe
return RPTag.init(json: json)!
} catch {
result(FlutterError(code: FlutterPluginCode.failure,
message: "Json deserialization of track failed",
message: "Json deserialization of tag failed",
details: nil)
)
}
Expand All @@ -223,8 +231,16 @@ public class SwiftTelematicsSDKPlugin: NSObject, FlutterPlugin, RPLowPowerModeDe
var res = [String]()

tags?.tags.forEach { element in
let str = String(data: element.toJSON() as! Data, encoding: .utf8)!
res.append(str)
do {
let json = try JSONSerialization.data(withJSONObject: element.toJSON(), options: .prettyPrinted)
let str = String(data: json, encoding: .utf8)!
res.append(str)
} catch {
result(FlutterError(code: FlutterPluginCode.failure,
message: "Json serialization of tag failed",
details: nil)
)
}
}

result(res)
Expand All @@ -243,7 +259,7 @@ public class SwiftTelematicsSDKPlugin: NSObject, FlutterPlugin, RPLowPowerModeDe
return RPTag.init(json: json)!
} catch {
result(FlutterError(code: FlutterPluginCode.failure,
message: "Json deserialization of track failed",
message: "Json deserialization of tag failed",
details: nil)
)
}
Expand All @@ -257,19 +273,25 @@ public class SwiftTelematicsSDKPlugin: NSObject, FlutterPlugin, RPLowPowerModeDe
var res = [String]()

tags?.tags.forEach { element in
let str = String(data: element.toJSON() as! Data, encoding: .utf8)!
res.append(str)
do {
let json = try JSONSerialization.data(withJSONObject: element.toJSON(), options: .prettyPrinted)
let str = String(data: json, encoding: .utf8)!
res.append(str)
} catch {
result(FlutterError(code: FlutterPluginCode.failure,
message: "Json serialization of tag failed",
details: nil)
)
}
}

result(res)
}

}

private func getFutureTrackTags(_ result: @escaping FlutterResult) {
let timestamp = Date().currentTimeMillis()

RPEntry.instance().api.getFutureTrackTag(timestamp, completion: nil)
private func getFutureTrackTags(_ result: @escaping FlutterResult) {
RPEntry.instance().api.getFutureTrackTag(0, completion: nil)

result(nil)
}
Expand Down
50 changes: 32 additions & 18 deletions ios/Classes/TagStateDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,33 @@ class TagStateDelegate: NSObject, RPTagsServerStateDelegate {
}

func addTag(_ status: RPTagStatus, tag: RPTag!, timestamp: Int) {
let json: [String : Any?] = [
"status": String(describing: status),
"tag": String(data: tag.toJSON() as! Data, encoding: .utf8),
"activationTime": timestamp
]

channel?.invokeMethod("onAddTag", arguments: json)
do {
let jsonTag = try JSONSerialization.data(withJSONObject: tag.toJSON(), options: .prettyPrinted)
let strTag = String(data: jsonTag, encoding: .utf8)!

let json: [String : Any?] = [
"status": String(describing: status),
"tag": strTag,
"activationTime": timestamp
]

channel?.invokeMethod("onAddTag", arguments: json)
} catch {}
}

func deleteTag(_ status: RPTagStatus, tag: RPTag!, timestamp: Int) {
let json: [String : Any?] = [
"status": String(describing: status),
"tag": String(data: tag.toJSON() as! Data, encoding: .utf8),
"deactivationTime": timestamp
]

channel?.invokeMethod("onTagRemove", arguments: json)
do {
let jsonTag = try JSONSerialization.data(withJSONObject: tag.toJSON(), options: .prettyPrinted)
let strTag = String(data: jsonTag, encoding: .utf8)!

let json: [String : Any?] = [
"status": String(describing: status),
"tag": strTag,
"deactivationTime": timestamp
]

channel?.invokeMethod("onTagRemove", arguments: json)
} catch {}
}

func removeAll(_ status: RPTagStatus, timestamp: Int) {
Expand All @@ -38,14 +48,18 @@ class TagStateDelegate: NSObject, RPTagsServerStateDelegate {
channel?.invokeMethod("onAllTagsRemove", arguments: json)
}

func getTags(_ status: RPTagStatus, tags: Any!, timestamp: Int) {
func getTags(_ status: RPTagStatus, tags: Any, timestamp: Int) {
let _tags = tags as? RPTags

var strTags = [String]()

_tags?.tags.forEach { element in
let str = String(data: element.toJSON() as! Data, encoding: .utf8)!
strTags.append(str)
do {
let jsonTag = try JSONSerialization.data(withJSONObject: element.toJSON(), options: .prettyPrinted)
let strTag = String(data: jsonTag, encoding: .utf8)!

strTags.append(strTag)
} catch {}
}

let json: [String : Any?] = [
Expand Down
10 changes: 0 additions & 10 deletions lib/src/permission_wizard_result.dart

This file was deleted.

Loading

0 comments on commit eb5e809

Please sign in to comment.