Skip to content

Commit f9ea2be

Browse files
committed
fix sending location
- We were previously sending `lat` and `long` in 2 separate update requests. - While the backend was returning success for these 2 requests, it wasn't actually updating and it seems we need to send both in one request
1 parent 6e1ba68 commit f9ea2be

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSPropertiesModel.swift

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,37 @@ struct OSPropertiesDeltas {
4545
}
4646
}
4747

48+
// Both lat and long must exist to be accepted by the server
49+
class OSLocationPoint: NSObject, NSCoding {
50+
let lat: Float
51+
let long: Float
52+
53+
init(lat: Float, long: Float) {
54+
self.lat = lat
55+
self.long = long
56+
}
57+
58+
public func encode(with coder: NSCoder) {
59+
coder.encode(lat, forKey: "lat")
60+
coder.encode(long, forKey: "long")
61+
}
62+
63+
public required init?(coder: NSCoder) {
64+
self.lat = coder.decodeFloat(forKey: "lat")
65+
self.long = coder.decodeFloat(forKey: "long")
66+
}
67+
}
68+
4869
class OSPropertiesModel: OSModel {
4970
var language: String? {
5071
didSet {
5172
self.set(property: "language", newValue: language)
5273
}
5374
}
5475

55-
var lat: Float? {
56-
didSet {
57-
self.set(property: "lat", newValue: lat)
58-
}
59-
}
60-
61-
var long: Float? {
76+
var location: OSLocationPoint? {
6277
didSet {
63-
self.set(property: "long", newValue: long)
78+
self.set(property: "location", newValue: location)
6479
}
6580
}
6681

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserInternalImpl.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ class OSUserInternalImpl: NSObject, OSUserInternal {
125125
func setLocation(lat: Float, long: Float) {
126126
OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OneSignal.User setLocation called with lat: \(lat) long: \(long)")
127127

128-
propertiesModel.lat = lat
129-
propertiesModel.long = long
128+
propertiesModel.location = OSLocationPoint(lat: lat, long: long)
130129
}
131130

132131
// MARK: - Language

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserRequests.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,8 +900,14 @@ class OSRequestUpdateProperties: OneSignalRequest, OSUserRequest {
900900
self.stringDescription = "OSRequestUpdateProperties with properties: \(properties) deltas: \(String(describing: deltas)) refreshDeviceMetadata: \(String(describing: refreshDeviceMetadata))"
901901
super.init()
902902

903+
var propertiesObject = properties
904+
if let location = propertiesObject["location"] as? OSLocationPoint {
905+
propertiesObject["lat"] = location.lat
906+
propertiesObject["long"] = location.long
907+
propertiesObject.removeValue(forKey: "location")
908+
}
903909
var params: [String: Any] = [:]
904-
params["properties"] = properties
910+
params["properties"] = propertiesObject
905911
params["refresh_device_metadata"] = refreshDeviceMetadata
906912
if let deltas = deltas {
907913
params["deltas"] = deltas

0 commit comments

Comments
 (0)