Skip to content

Commit

Permalink
add a completion closure param for the aync apis
Browse files Browse the repository at this point in the history
  • Loading branch information
zihejia committed Sep 23, 2021
1 parent ecf22ae commit d4fcc2c
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions Sources/MixpanelInstance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -612,9 +612,10 @@ extension MixpanelInstance {

- parameter distinctId: string that uniquely identifies the current user
- parameter usePeople: boolean that controls whether or not to set the people distinctId to the event distinctId.
This should only be set to false if you wish to prevent people profile updates for that user.
This should only be set to false if you wish to prevent people profile updates for that user.
- parameter completion: an optional completion handler for when the identify has completed.
*/
open func identify(distinctId: String, usePeople: Bool = true) {
open func identify(distinctId: String, usePeople: Bool = true, completion: (() -> Void)? = nil) {
if hasOptedOutTracking() {
return
}
Expand Down Expand Up @@ -660,6 +661,9 @@ extension MixpanelInstance {
userId: self.userId,
alias: self.alias,
hadPersistedDistinctId: self.hadPersistedDistinctId), apiToken: self.apiToken)
if let completion = completion {
DispatchQueue.main.async(execute: completion)
}
}

if MixpanelInstance.isiOSAppExtension() {
Expand All @@ -682,9 +686,10 @@ extension MixpanelInstance {
- parameter alias: A unique identifier that you want to use as an identifier for this user.
- parameter distinctId: The current user identifier.
- parameter usePeople: boolean that controls whether or not to set the people distinctId to the event distinctId.
- parameter completion: an optional completion handler for when the createAlias has completed.
This should only be set to false if you wish to prevent people profile updates for that user.
*/
open func createAlias(_ alias: String, distinctId: String, usePeople: Bool = true) {
open func createAlias(_ alias: String, distinctId: String, usePeople: Bool = true, completion: (() -> Void)? = nil) {
if hasOptedOutTracking() {
return
}
Expand Down Expand Up @@ -717,17 +722,22 @@ extension MixpanelInstance {
let properties = ["distinct_id": distinctId, "alias": alias]
track(event: "$create_alias", properties: properties)
identify(distinctId: distinctId, usePeople: usePeople)
flush()
flush(completion: completion)
} else {
Logger.error(message: "alias: \(alias) matches distinctId: \(distinctId) - skipping api call.")
if let completion = completion {
DispatchQueue.main.async(execute: completion)
}
}
}

/**
Clears all stored properties including the distinct Id.
Useful if your app's user logs out.

- parameter completion: an optional completion handler for when the reset has completed.
*/
open func reset() {
open func reset(completion: (() -> Void)? = nil) {

This comment has been minimized.

Copy link
@igled7

igled7 Jan 19, 2022

Contributor

You added a completion here but it is not invoked.

This comment has been minimized.

Copy link
@zihejia

zihejia Jan 20, 2022

Author Contributor

sorry, we will fix it.

flush()
trackingQueue.async { [weak self] in
self?.readWriteLock.write { [weak self] in
Expand Down

0 comments on commit d4fcc2c

Please sign in to comment.