Skip to content

Commit

Permalink
Correctly clear Apple Health Integration (#437)
Browse files Browse the repository at this point in the history
Previously when attempting to disconnect Apple Health goals they would
enter a state where they no longer updated, but beeminder.com still
considered them autodata, and thus e.g. changing the deadline was
forbidden. This was because we were setting the autodata name to an
empty string, rather than null. Sending null was not supported via the
URL encoding schema the app was using, so switch to sending parameters
as JSON instead and send nil.

Fixes #248
  • Loading branch information
theospears authored Jan 28, 2024
1 parent a5a1701 commit 35c43ed
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion BeeKit/Managers/RequestManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public class RequestManager {
private let logger = Logger(subsystem: "com.beeminder.beeminder", category: "RequestManager")

func rawRequest(url: String, method: HTTPMethod, parameters: [String: Any]?) async throws -> Any? {
let response = await AF.request("\(baseURLString)/\(url)", method: method, parameters: parameters, encoding: URLEncoding.default, headers: HTTPHeaders.default)
let encoding: ParameterEncoding = if method == .get { URLEncoding.default } else { JSONEncoding.default }
let response = await AF.request("\(baseURLString)/\(url)", method: method, parameters: parameters, encoding: encoding, headers: HTTPHeaders.default)
.validate()
.serializingData(emptyRequestMethods: [HTTPMethod.post])
.response
Expand Down
2 changes: 1 addition & 1 deletion BeeSwift/Settings/RemoveHKMetricViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class RemoveHKMetricViewController: UIViewController {
@objc func removeButtonPressed() {
guard self.goal != nil else { return }
self.goal?.autodata = ""
let params: [String: [String: String]] = ["ii_params": ["name": "", "metric": ""]]
let params: [String: [String: String?]] = ["ii_params": ["name": nil, "metric": ""]]
let hud = MBProgressHUD.showAdded(to: self.view, animated: true)
hud.mode = .indeterminate

Expand Down

0 comments on commit 35c43ed

Please sign in to comment.