Skip to content

Commit

Permalink
Merge pull request #660 from zapcannon87/master
Browse files Browse the repository at this point in the history
feat(user): option for clearing anonymous id
  • Loading branch information
zapcannon87 authored Sep 7, 2021
2 parents dd0dca5 + 864eaa2 commit 5353ae5
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 14 deletions.
41 changes: 37 additions & 4 deletions AVOS/LeanCloudObjcTests/LCUserTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class LCUserTestCase: BaseTestCase {
static let testablePhoneNumber = "+8618622223333"
static let testableSMSCode = "170402"

/*
func testVerifyPhoneNumberBySMSCode() {
/*
let user = LCUser()
let username = uuid
let password = uuid
Expand Down Expand Up @@ -58,11 +58,11 @@ class LCUserTestCase: BaseTestCase {
exp.fulfill()
}
}
*/
}
*/

/*
func testUpdatePhoneNumberBySMSCode() {
/*
let user = LCUser()
let username = uuid
let password = uuid
Expand Down Expand Up @@ -105,7 +105,40 @@ class LCUserTestCase: BaseTestCase {
exp.fulfill()
}
}
*/
}
*/

func testLogOut() {
var uid1: String?
expecting { exp in
LCUser.loginAnonymously { user, error in
uid1 = user?.objectId
XCTAssertNotNil(uid1)
XCTAssertNil(error)
exp.fulfill()
}
}

LCUser.logOut(withClearingAnonymousId: false)

expecting { exp in
LCUser.loginAnonymously { user, error in
XCTAssertEqual(uid1, user?.objectId)
XCTAssertNil(error)
exp.fulfill()
}
}

LCUser.logOut()

expecting { exp in
LCUser.loginAnonymously { user, error in
XCTAssertNotNil(user?.objectId)
XCTAssertNotEqual(uid1, user?.objectId)
XCTAssertNil(error)
exp.fulfill()
}
}
}

func testFriendshipRequestAccept() {
Expand Down
12 changes: 7 additions & 5 deletions AVOS/Sources/Foundation/User/LCUser.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,16 @@ FOUNDATION_EXPORT LeanCloudSocialPlatform const LeanCloudSocialPlatformWeiXin;
password:(NSString *)password
block:(LCUserResultBlock)block;

// MARK: Log out

/** @name Logging Out */

/*!
Logs out the currently logged in user on disk.
*/
/// Clearing local persistent cache data of the current user and set it to `nil`.
/// It will also clearing local persistent cache of anonymous id.
+ (void)logOut;

/// Clearing local persistent cache data of the current user and set it to `nil`.
/// @param clearingAnonymousId `true` means clearing local persistent cache of anonymous id, `false` means NOT.
+ (void)logOutWithClearingAnonymousId:(BOOL)clearingAnonymousId;

/** @name Requesting a Password Reset */


Expand Down
12 changes: 9 additions & 3 deletions AVOS/Sources/Foundation/User/LCUser.m
Original file line number Diff line number Diff line change
Expand Up @@ -647,11 +647,17 @@ + (void)signUpOrLoginWithMobilePhoneNumberInBackground:(NSString *)phoneNumber
}];
}

// MARK: - logout
// MARK: Log out

+ (void)logOut {
[[NSUserDefaults standardUserDefaults] removeObjectForKey:AnonymousIdKey];
[[self class] changeCurrentUser:nil save:YES];
[self logOutWithClearingAnonymousId:true];
}

+ (void)logOutWithClearingAnonymousId:(BOOL)clearingAnonymousId {
if (clearingAnonymousId) {
[[NSUserDefaults standardUserDefaults] removeObjectForKey:AnonymousIdKey];
}
[self changeCurrentUser:nil save:true];
}

// MARK: - password reset
Expand Down
2 changes: 1 addition & 1 deletion AVOS/Sources/Foundation/UserAgent.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define SDK_VERSION @"13.3.1"
#define SDK_VERSION @"13.4.0"
2 changes: 1 addition & 1 deletion LeanCloudObjc.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'LeanCloudObjc'
s.version = '13.3.1'
s.version = '13.4.0'
s.homepage = 'https://leancloud.cn/'
s.summary = 'LeanCloud Objective-C SDK'
s.authors = 'LeanCloud'
Expand Down

0 comments on commit 5353ae5

Please sign in to comment.