Skip to content
This repository has been archived by the owner on Nov 2, 2019. It is now read-only.

Commit

Permalink
Add userId and user properties to AppEventsLogger. (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
nlutsenko committed Apr 9, 2017
1 parent 442b843 commit a09021e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
36 changes: 36 additions & 0 deletions Sources/Core/AppEvents/AppEventsLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,40 @@ public class AppEventsLogger {
return FBSDKAppEvents.setLoggingOverrideAppID(newValue)
}
}

//--------------------------------------
// MARK: - User Id
//--------------------------------------

///
/// A custom user identifier to associate with all app events.
/// The `userId` is persisted until it is cleared by passing `nil`.
///
public static var userId: String? {
get {
return FBSDKAppEvents.userID() as String?
}
set {
FBSDKAppEvents.setUserID(userId)
}
}

//--------------------------------------
// MARK: - User Parameters
//--------------------------------------

/**
Sends a request to update the properties for the current user, set by `AppEventsLogger.userId`.
- properties: A dictionary of key-value pairs representing user properties and their values.
Values should be strings or numbers only. Each key must be less than 40 character in length,
and the key can contain only letters, number, whitespace, hyphens (`-`), or underscores (`_`).
Each value must be less than 100 characters.
- completion: Optional completion closure that is going to be called when the request finishes or fails.
*/
public static func updateUserProperties(_ properties: [String : Any],
completion: @escaping (_ httpResponse: HTTPURLResponse?, _ result: GraphRequestResult<GraphRequest>) -> Void) {
FBSDKAppEvents.updateUserProperties(properties,
handler: GraphRequestConnection.sdkRequestCompletion(from: completion))
}
}
6 changes: 3 additions & 3 deletions Sources/Core/GraphRequest/GraphRequestConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ extension GraphRequestConnection {
batchParameters: [String : Any]?,
completion: Completion<T>? = nil) {
sdkConnection.add(request.sdkRequest,
completionHandler: completion.map(sdkRequestCompletion),
completionHandler: completion.map(type(of: self).sdkRequestCompletion),
batchParameters: batchParameters)
}

Expand Down Expand Up @@ -137,9 +137,9 @@ extension GraphRequestConnection {

extension GraphRequestConnection {
/// Custom typealias that is the same as FBSDKGraphRequestHandler, but without implicitly unwrapped optionals.
fileprivate typealias SDKRequestCompletion = (_ connection: FBSDKGraphRequestConnection?, _ rawResponse: Any?, _ error: Error?) -> Void
internal typealias SDKRequestCompletion = (_ connection: FBSDKGraphRequestConnection?, _ rawResponse: Any?, _ error: Error?) -> Void

fileprivate func sdkRequestCompletion<T: GraphRequestProtocol>(from completion: @escaping Completion<T>) -> SDKRequestCompletion {
internal static func sdkRequestCompletion<T: GraphRequestProtocol>(from completion: @escaping Completion<T>) -> SDKRequestCompletion {
return { connection, rawResponse, error in
let result: GraphRequestResult<T> = {
switch error {
Expand Down

0 comments on commit a09021e

Please sign in to comment.