Beacon 클래스의 키 값 쌍을 반환하는 "toDictionary()"메서드가있는 Beacon이라는 사용자 정의 클래스가 있습니다.배열이있는 사전을 신속하게 요청할 수있는 배열을 전달할 수 없습니다.
let detectedBeacon = Beacon(id: "QA",
strength: Float(234),
proximity: "far",
time: self.getISODateFormat(),
wasOffline: false,
osVersion: "ios 10",
batteryLevel: "12",
uuid: "adadaad",
majorId: 4,
minorId: 5,
section: "QA",
region: "temp")
let array = [detectedBeacon.toDictionary()]
이 사전 항목이있는 배열을 만들었습니다 (현재 배열에 하나의 항목이 있음). 이제이 배열을 API 본문에 전달하기 위해 사전에 래핑했습니다.
let locationParams : Dictionary<String, AnyObject> = ["locations" : array as AnyObject]
LocationApiManager.updateLastLocationOf(deviceId: deviceId, parameter: locationParams as [String : AnyObject]?) {
(response, errorMessage) in
}
"updateLastLocation"메소드는 alamofire 게시 요청을 호출합니다.
{ 'locations[][section]': 'QA',
'locations[][uuid]': 'adadaad',
'locations[][region]': 'temp',
'locations[][userId]': '0001',
'locations[][minorId]': '5',
'locations[][proximity]': 'far',
'locations[][batteryLevel]': '12',
'locations[][majorId]': '4',
'locations[][beaconStrength]': '234',
'locations[][time]': '2017-02-01 06:42:03 +0000',
'locations[][osVersion]': 'ios 10',
'locations[][beaconId]': 'QA',
'locations[][wasOffline]': '0' }
이 왜 그렇게 그 것이다 다음과 같이
그러나 서버는이 매개 변수를 수신?
업데이트
내 toDictionary 방법
func toDictionary() -> [String : AnyObject] {
return (
["beaconId": self.beaconId as AnyObject,
"beaconStrength": self.beaconStrength as AnyObject,
"proximity": self.proximity as AnyObject,
"time": NSDate() as AnyObject,
"wasOffline": self.wasOffline as AnyObject,
"osVersion": self.osVersion as AnyObject,
"batteryLevel": self.batteryLevel as AnyObject,
"uuid": self.uuid as AnyObject,
"majorId": self.majorId as AnyObject,
"minorId": self.minorId as AnyObject,
"section": self.section as AnyObject,
"region": self.region as AnyObject,
"userId": "0001" as AnyObject]
)
}
업데이트 위치 메서드는이 같은 일부 무엇 유사한 코드가 포함
class func postData(apiEndPoint: String,
parameters: [String: AnyObject]?,
headers: HTTPHeaders,
completion:
@escaping (_ responseFromBaseAPI : [String : AnyObject]?) ->()) -> Bool {
UIApplication.shared.isNetworkActivityIndicatorVisible = true
Alamofire.request(apiEndPoint,
method: .post,
parameters: parameters,
encoding: URLEncoding.httpBody,
headers: headers).responseJSON { result in
completion(result.result.value as? [String: AnyObject])
UIApplication.shared.isNetworkActivityIndicatorVisible = false
}
return true
}
@EricAya 업데이트 –