Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
cherry pick Work around login crash #728
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekatz committed May 20, 2016
1 parent 884e581 commit 20ad744
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Source/LoggingAnalyticsTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import UIKit
class LoggingAnalyticsTracker: NSObject, OEXAnalyticsTracker {
private let ANALYTICS = "ANALYTICS"

func identifyUser(user: OEXUserDetails) {
func identifyUser(user: OEXUserDetails?) {
Logger.logInfo(ANALYTICS, "Identified User: \(user)")
}

Expand Down
2 changes: 1 addition & 1 deletion Source/OEXAnalyticsTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ NS_ASSUME_NONNULL_BEGIN

@protocol OEXAnalyticsTracker <NSObject>

- (void)identifyUser:(OEXUserDetails*)user;
- (void)identifyUser:(nullable OEXUserDetails*)user;
- (void)clearIdentifiedUser;

- (void)trackEvent:(OEXAnalyticsEvent*)event forComponent:(nullable NSString*)component withProperties:(NSDictionary<NSString*, id>*)properties;
Expand Down
12 changes: 11 additions & 1 deletion Source/OEXAuthentication.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "OEXAuthentication.h"

#import "NSDictionary+OEXEncoding.h"
#import "NSError+OEXKnownErrors.h"
#import "NSMutableDictionary+OEXSafeAccess.h"
#import "NSString+OEXFormatting.h"

Expand Down Expand Up @@ -189,7 +190,16 @@ + (void)handleSuccessfulLoginWithToken:(OEXAccessToken*)token completionHandler:
if(httpResp.statusCode == 200) {
NSDictionary* dictionary = [NSJSONSerialization JSONObjectWithData:userdata options:kNilOptions error:nil];
OEXUserDetails* userDetails = [[OEXUserDetails alloc] initWithUserDictionary:dictionary];
[[OEXSession sharedSession] saveAccessToken:token userDetails:userDetails];
if(token != nil && userDetails != nil) {
[[OEXSession sharedSession] saveAccessToken:token userDetails:userDetails];
}
else {
// On the off chance that something messed up and we have nil
// for token or user details,
// stub in some error values
usererror = [NSError oex_unknownError];
userresponse = [[NSHTTPURLResponse alloc] initWithURL:userresponse.URL statusCode:OEXHTTPStatusCode400BadRequest HTTPVersion:nil headerFields:nil];
}
}
dispatch_async(dispatch_get_main_queue(), ^{
OEXWrapURLCompletion(completionHandler)(userdata, userresponse, usererror);
Expand Down
7 changes: 6 additions & 1 deletion Source/OEXSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ - (id)init {
- (void)saveAccessToken:(OEXAccessToken*)token userDetails:(OEXUserDetails*)userDetails {
[self.credentialStore clear];
[self.credentialStore saveAccessToken:token userDetails:userDetails];
[self loadTokenFromStore];

self.token = token;
self.currentUser = userDetails;
if(token != nil && userDetails != nil) {
[[NSNotificationCenter defaultCenter] postNotificationName:OEXSessionStartedNotification object:nil userInfo:@{OEXSessionStartedUserDetailsKey : userDetails}];
}
}

- (void)loadTokenFromStore {
Expand Down
8 changes: 4 additions & 4 deletions Source/SegmentAnalyticsTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class SegmentAnalyticsTracker : NSObject, OEXAnalyticsTracker {
}
}

func identifyUser(user : OEXUserDetails) {
if let userID = user.userId {
func identifyUser(user : OEXUserDetails?) {
if let userID = user?.userId {
var traits : [String:AnyObject] = [:]
if let email = user.email {
if let email = user?.email {
traits[key_email] = email
}
if let username = user.username {
if let username = user?.username {
traits[key_username] = username
}
SEGAnalytics.sharedAnalytics().identify(userID.description, traits:traits)
Expand Down
2 changes: 1 addition & 1 deletion Test/MockAnalyticsTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class MockAnalyticsTracker : NSObject, OEXAnalyticsTracker {

let eventStream = Sink<MockAnalyticsRecord>()

func identifyUser(user: OEXUserDetails) {
func identifyUser(user: OEXUserDetails?) {
currentUser = user
}

Expand Down

0 comments on commit 20ad744

Please sign in to comment.