Skip to content

Commit 5353ae5

Browse files
authored
Merge pull request #660 from zapcannon87/master
feat(user): option for clearing anonymous id
2 parents dd0dca5 + 864eaa2 commit 5353ae5

File tree

5 files changed

+55
-14
lines changed

5 files changed

+55
-14
lines changed

AVOS/LeanCloudObjcTests/LCUserTestCase.swift

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class LCUserTestCase: BaseTestCase {
1414
static let testablePhoneNumber = "+8618622223333"
1515
static let testableSMSCode = "170402"
1616

17+
/*
1718
func testVerifyPhoneNumberBySMSCode() {
18-
/*
1919
let user = LCUser()
2020
let username = uuid
2121
let password = uuid
@@ -58,11 +58,11 @@ class LCUserTestCase: BaseTestCase {
5858
exp.fulfill()
5959
}
6060
}
61-
*/
6261
}
62+
*/
6363

64+
/*
6465
func testUpdatePhoneNumberBySMSCode() {
65-
/*
6666
let user = LCUser()
6767
let username = uuid
6868
let password = uuid
@@ -105,7 +105,40 @@ class LCUserTestCase: BaseTestCase {
105105
exp.fulfill()
106106
}
107107
}
108-
*/
108+
}
109+
*/
110+
111+
func testLogOut() {
112+
var uid1: String?
113+
expecting { exp in
114+
LCUser.loginAnonymously { user, error in
115+
uid1 = user?.objectId
116+
XCTAssertNotNil(uid1)
117+
XCTAssertNil(error)
118+
exp.fulfill()
119+
}
120+
}
121+
122+
LCUser.logOut(withClearingAnonymousId: false)
123+
124+
expecting { exp in
125+
LCUser.loginAnonymously { user, error in
126+
XCTAssertEqual(uid1, user?.objectId)
127+
XCTAssertNil(error)
128+
exp.fulfill()
129+
}
130+
}
131+
132+
LCUser.logOut()
133+
134+
expecting { exp in
135+
LCUser.loginAnonymously { user, error in
136+
XCTAssertNotNil(user?.objectId)
137+
XCTAssertNotEqual(uid1, user?.objectId)
138+
XCTAssertNil(error)
139+
exp.fulfill()
140+
}
141+
}
109142
}
110143

111144
func testFriendshipRequestAccept() {

AVOS/Sources/Foundation/User/LCUser.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,16 @@ FOUNDATION_EXPORT LeanCloudSocialPlatform const LeanCloudSocialPlatformWeiXin;
322322
password:(NSString *)password
323323
block:(LCUserResultBlock)block;
324324

325+
// MARK: Log out
325326

326-
/** @name Logging Out */
327-
328-
/*!
329-
Logs out the currently logged in user on disk.
330-
*/
327+
/// Clearing local persistent cache data of the current user and set it to `nil`.
328+
/// It will also clearing local persistent cache of anonymous id.
331329
+ (void)logOut;
332330

331+
/// Clearing local persistent cache data of the current user and set it to `nil`.
332+
/// @param clearingAnonymousId `true` means clearing local persistent cache of anonymous id, `false` means NOT.
333+
+ (void)logOutWithClearingAnonymousId:(BOOL)clearingAnonymousId;
334+
333335
/** @name Requesting a Password Reset */
334336

335337

AVOS/Sources/Foundation/User/LCUser.m

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -647,11 +647,17 @@ + (void)signUpOrLoginWithMobilePhoneNumberInBackground:(NSString *)phoneNumber
647647
}];
648648
}
649649

650-
// MARK: - logout
650+
// MARK: Log out
651651

652652
+ (void)logOut {
653-
[[NSUserDefaults standardUserDefaults] removeObjectForKey:AnonymousIdKey];
654-
[[self class] changeCurrentUser:nil save:YES];
653+
[self logOutWithClearingAnonymousId:true];
654+
}
655+
656+
+ (void)logOutWithClearingAnonymousId:(BOOL)clearingAnonymousId {
657+
if (clearingAnonymousId) {
658+
[[NSUserDefaults standardUserDefaults] removeObjectForKey:AnonymousIdKey];
659+
}
660+
[self changeCurrentUser:nil save:true];
655661
}
656662

657663
// MARK: - password reset
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#define SDK_VERSION @"13.3.1"
1+
#define SDK_VERSION @"13.4.0"

LeanCloudObjc.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'LeanCloudObjc'
3-
s.version = '13.3.1'
3+
s.version = '13.4.0'
44
s.homepage = 'https://leancloud.cn/'
55
s.summary = 'LeanCloud Objective-C SDK'
66
s.authors = 'LeanCloud'

0 commit comments

Comments
 (0)