Skip to content

Commit 9e7f393

Browse files
authored
fix: ParseAnalytics trackAppOpened had ambiguous inits (#55)
* fix: ParseAnalytics trackAppOpened had ambiguous inits * improve trackAppOpen
1 parent 2494b3f commit 9e7f393

File tree

6 files changed

+46
-7
lines changed

6 files changed

+46
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ __New features__
3737
* The max connection attempts for LiveQuery can now be changed when initializing the SDK ([#43](https://github.com/netreconlab/Parse-Swift/pull/43)), thanks to [Corey Baker](https://github.com/cbaker6).
3838

3939
__Fixes__
40+
* Fixed ambiguous ParseAnalytics trackAppOpenned ([#55](https://github.com/netreconlab/Parse-Swift/pull/55)), thanks to [Corey Baker](https://github.com/cbaker6).
4041
* Refactored playground mount to be "/parse" instead "/1". Also do not require url when decoding a ParseFile ([#52](https://github.com/netreconlab/Parse-Swift/pull/52)), thanks to [Corey Baker](https://github.com/cbaker6).
4142
* Fixed issues that can cause cache misses when querying ([#46](https://github.com/netreconlab/Parse-Swift/pull/46)), thanks to [Corey Baker](https://github.com/cbaker6).
4243
* Fixed a threading issue with .current objects that can cause apps to crash

Sources/ParseSwift/ParseConstants.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Foundation
1010

1111
enum ParseConstants {
1212
static let sdk = "swift"
13-
static let version = "5.0.0-beta.6"
13+
static let version = "5.0.0-beta.7"
1414
static let fileManagementDirectory = "parse/"
1515
static let fileManagementPrivateDocumentsDirectory = "Private Documents/"
1616
static let fileManagementLibraryDirectory = "Library/"

Sources/ParseSwift/Types/ParseAnalytics+async.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public extension ParseAnalytics {
1818
// MARK: Aysnc/Await
1919

2020
#if os(iOS)
21+
2122
/**
2223
Tracks *asynchronously* this application being launched. If this happened as the result of the
2324
user opening a push notification, this method sends along information to
@@ -31,9 +32,10 @@ public extension ParseAnalytics {
3132
- parameter options: A set of header options sent to the server. Defaults to an empty set.
3233
- throws: An error of type `ParseError`.
3334
*/
34-
static func trackAppOpened(launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil,
35+
static func trackAppOpened(launchOptions: [UIApplication.LaunchOptionsKey: Any],
3536
at date: Date? = nil,
3637
options: API.Options = []) async throws {
38+
3739
let result = try await withCheckedThrowingContinuation { continuation in
3840
Self.trackAppOpened(launchOptions: launchOptions,
3941
at: date,
@@ -43,7 +45,9 @@ public extension ParseAnalytics {
4345
if case let .failure(error) = result {
4446
throw error
4547
}
48+
4649
}
50+
4751
#endif
4852

4953
/**

Sources/ParseSwift/Types/ParseAnalytics+combine.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public extension ParseAnalytics {
1919
// MARK: Combine
2020

2121
#if os(iOS)
22+
2223
/**
2324
Tracks *asynchronously* this application being launched. If this happened as the result of the
2425
user opening a push notification, this method sends along information to
@@ -32,16 +33,18 @@ public extension ParseAnalytics {
3233
- parameter options: A set of header options sent to the server. Defaults to an empty set.
3334
- returns: A publisher that eventually produces a single value and then finishes or fails.
3435
*/
35-
static func trackAppOpenedPublisher(launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil,
36+
static func trackAppOpenedPublisher(launchOptions: [UIApplication.LaunchOptionsKey: Any],
3637
at date: Date? = nil,
3738
options: API.Options = []) -> Future<Void, ParseError> {
39+
3840
Future { promise in
3941
Self.trackAppOpened(launchOptions: launchOptions,
4042
at: date,
4143
options: options,
4244
completion: promise)
4345
}
4446
}
47+
4548
#endif
4649

4750
/**

Sources/ParseSwift/Types/ParseAnalytics.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public struct ParseAnalytics: ParseTypeable, Hashable {
8282
// MARK: Intents
8383

8484
#if os(iOS)
85+
8586
/**
8687
Tracks *asynchronously* this application being launched. If this happened as the result of the
8788
user opening a push notification, this method sends along information to
@@ -99,16 +100,20 @@ public struct ParseAnalytics: ParseTypeable, Hashable {
99100
- note: The default cache policy for this method is `.reloadIgnoringLocalCacheData`. If a developer
100101
desires a different policy, it should be inserted in `options`.
101102
*/
102-
static public func trackAppOpened(launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil,
103+
static public func trackAppOpened(launchOptions: [UIApplication.LaunchOptionsKey: Any],
103104
at date: Date? = nil,
104105
options: API.Options = [],
105106
callbackQueue: DispatchQueue = .main,
106107
completion: @escaping (Result<Void, ParseError>) -> Void) {
108+
107109
var options = options
108110
options.insert(.cachePolicy(.reloadIgnoringLocalCacheData))
109-
var userInfo: [String: String]?
110-
if let remoteOptions = launchOptions?[.remoteNotification] as? [String: String] {
111-
userInfo = remoteOptions
111+
var userInfo = [String: String]()
112+
launchOptions.forEach { (key, value) in
113+
guard let value = value as? String else {
114+
return
115+
}
116+
userInfo[key.rawValue] = value
112117
}
113118
let appOppened = ParseAnalytics(name: "AppOpened",
114119
dimensions: userInfo,

Tests/ParseSwiftTests/ParseAnalyticsTests.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,32 @@ class ParseAnalyticsTests: XCTestCase {
151151
return MockURLResponse(data: encoded, statusCode: 200)
152152
}
153153

154+
let expectation = XCTestExpectation(description: "Analytics save")
155+
let options = [UIApplication.LaunchOptionsKey.remoteNotification: "stop"]
156+
ParseAnalytics.trackAppOpened(launchOptions: options) { result in
157+
158+
if case .failure(let error) = result {
159+
XCTFail(error.localizedDescription)
160+
}
161+
expectation.fulfill()
162+
}
163+
wait(for: [expectation], timeout: 10.0)
164+
}
165+
166+
func testTrackAppOpenedUIKitNotStringValue() {
167+
let serverResponse = NoBody()
168+
let encoded: Data!
169+
do {
170+
encoded = try ParseCoding.jsonEncoder().encode(serverResponse)
171+
} catch {
172+
XCTFail("Should encode/decode. Error \(error)")
173+
return
174+
}
175+
176+
MockURLProtocol.mockRequests { _ in
177+
return MockURLResponse(data: encoded, statusCode: 200)
178+
}
179+
154180
let expectation = XCTestExpectation(description: "Analytics save")
155181
let options = [UIApplication.LaunchOptionsKey.remoteNotification: ["stop": "drop"]]
156182
ParseAnalytics.trackAppOpened(launchOptions: options) { result in

0 commit comments

Comments
 (0)