Skip to content

Commit 7038557

Browse files
authored
Merge pull request #220 from zapcannon87/master
release: 16.5.0
2 parents d00b604 + 4efef54 commit 7038557

26 files changed

+1523
-948
lines changed

LeanCloud.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 = 'LeanCloud'
3-
s.version = '16.4.0'
3+
s.version = '16.5.0'
44
s.license = { :type => 'Apache License, Version 2.0', :file => 'LICENSE' }
55
s.summary = 'LeanCloud Swift SDK'
66
s.homepage = 'https://leancloud.cn/'

LeanCloud.xcodeproj/project.pbxproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
D363343622CDB0D300995DC1 /* LCEngineTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D363343522CDB0D300995DC1 /* LCEngineTestCase.swift */; };
9191
D3662F9222019B590046A390 /* test.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = D3662F9122019B590046A390 /* test.mp3 */; };
9292
D3665C3721FEAAC1005B44B0 /* IMMessageTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3665C3621FEAAC1005B44B0 /* IMMessageTestCase.swift */; };
93+
D36E6C7022EC56A800CC1989 /* LiveQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = D36E6C6F22EC56A800CC1989 /* LiveQuery.swift */; };
9394
D3783A1221F453C3006F6635 /* IMConversationTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3783A1121F453C3006F6635 /* IMConversationTestCase.swift */; };
9495
D393EDBE21D38206001CBB2B /* IMMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = D393EDBD21D38206001CBB2B /* IMMessage.swift */; };
9596
D39C50A822D4683C00CFCB43 /* Push.swift in Sources */ = {isa = PBXBuildFile; fileRef = D39C50A722D4683C00CFCB43 /* Push.swift */; };
@@ -100,13 +101,12 @@
100101
D3B600842281679400F2E556 /* LCApplicationTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3B600832281679400F2E556 /* LCApplicationTestCase.swift */; };
101102
D3BBFB41225D944100B75BA1 /* LCLocalStorageContextTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3BBFB40225D944100B75BA1 /* LCLocalStorageContextTestCase.swift */; };
102103
D3C3782F21E48D3C00EA9AC9 /* IMConversationQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3C3782E21E48D3C00EA9AC9 /* IMConversationQuery.swift */; };
104+
D3D73BEB22EAA4EE00ECAE2B /* LiveQueryClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3D73BEA22EAA4EE00ECAE2B /* LiveQueryClient.swift */; };
103105
D3DAD03C218DA402008BCD37 /* RTMConnectionTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3DAD03B218DA402008BCD37 /* RTMConnectionTestCase.swift */; };
104-
D3E1F48D2193EDF3007B6FFB /* ConnectionTestViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3E1F48C2193EDF3007B6FFB /* ConnectionTestViewController.swift */; };
105106
D3E1F4AE21940E8E007B6FFB /* SwiftProtobuf.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D3872641217726B500DD8FBF /* SwiftProtobuf.framework */; };
106107
D3E1F4AF21940E8E007B6FFB /* SwiftProtobuf.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = D3872641217726B500DD8FBF /* SwiftProtobuf.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
107108
D3E1F4B321940E95007B6FFB /* Alamofire.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 837E04EE1CABA688008CC3FF /* Alamofire.framework */; };
108109
D3E1F4B421940E95007B6FFB /* Alamofire.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 837E04EE1CABA688008CC3FF /* Alamofire.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
109-
D3F030E4222FB31F009F6C67 /* MessagePushTestViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3F030E3222FB31F009F6C67 /* MessagePushTestViewController.swift */; };
110110
D3FE04522277EA6C0008C88A /* IMLocalStorageTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3FE04512277EA6C0008C88A /* IMLocalStorageTestCase.swift */; };
111111
/* End PBXBuildFile section */
112112

@@ -418,6 +418,7 @@
418418
D363343522CDB0D300995DC1 /* LCEngineTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LCEngineTestCase.swift; sourceTree = "<group>"; };
419419
D3662F9122019B590046A390 /* test.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = test.mp3; sourceTree = "<group>"; };
420420
D3665C3621FEAAC1005B44B0 /* IMMessageTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IMMessageTestCase.swift; sourceTree = "<group>"; };
421+
D36E6C6F22EC56A800CC1989 /* LiveQuery.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LiveQuery.swift; sourceTree = "<group>"; };
421422
D3783A1121F453C3006F6635 /* IMConversationTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IMConversationTestCase.swift; sourceTree = "<group>"; };
422423
D387262A217726B500DD8FBF /* SwiftProtobuf.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SwiftProtobuf.xcodeproj; path = SwiftProtobuf/SwiftProtobuf.xcodeproj; sourceTree = "<group>"; };
423424
D393EDBD21D38206001CBB2B /* IMMessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IMMessage.swift; sourceTree = "<group>"; };
@@ -429,9 +430,8 @@
429430
D3B600832281679400F2E556 /* LCApplicationTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LCApplicationTestCase.swift; sourceTree = "<group>"; };
430431
D3BBFB40225D944100B75BA1 /* LCLocalStorageContextTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LCLocalStorageContextTestCase.swift; sourceTree = "<group>"; };
431432
D3C3782E21E48D3C00EA9AC9 /* IMConversationQuery.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IMConversationQuery.swift; sourceTree = "<group>"; };
433+
D3D73BEA22EAA4EE00ECAE2B /* LiveQueryClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LiveQueryClient.swift; sourceTree = "<group>"; };
432434
D3DAD03B218DA402008BCD37 /* RTMConnectionTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RTMConnectionTestCase.swift; sourceTree = "<group>"; };
433-
D3E1F48C2193EDF3007B6FFB /* ConnectionTestViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectionTestViewController.swift; sourceTree = "<group>"; };
434-
D3F030E3222FB31F009F6C67 /* MessagePushTestViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessagePushTestViewController.swift; sourceTree = "<group>"; };
435435
D3F030F2222FB411009F6C67 /* RuntimeTests-iOS.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "RuntimeTests-iOS.entitlements"; sourceTree = "<group>"; };
436436
D3FE04512277EA6C0008C88A /* IMLocalStorageTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IMLocalStorageTestCase.swift; sourceTree = "<group>"; };
437437
/* End PBXFileReference section */
@@ -662,8 +662,6 @@
662662
D3F030F2222FB411009F6C67 /* RuntimeTests-iOS.entitlements */,
663663
D317983A2193DC860037DE57 /* AppDelegate.swift */,
664664
D317983C2193DC860037DE57 /* ViewController.swift */,
665-
D3E1F48C2193EDF3007B6FFB /* ConnectionTestViewController.swift */,
666-
D3F030E3222FB31F009F6C67 /* MessagePushTestViewController.swift */,
667665
D317983E2193DC860037DE57 /* Main.storyboard */,
668666
D31798412193DC880037DE57 /* Assets.xcassets */,
669667
D31798432193DC880037DE57 /* LaunchScreen.storyboard */,
@@ -711,6 +709,8 @@
711709
D393EDBD21D38206001CBB2B /* IMMessage.swift */,
712710
D3C3782E21E48D3C00EA9AC9 /* IMConversationQuery.swift */,
713711
D34F1BB82268263000251BC8 /* IMLocalStorage.swift */,
712+
D3D73BEA22EAA4EE00ECAE2B /* LiveQueryClient.swift */,
713+
D36E6C6F22EC56A800CC1989 /* LiveQuery.swift */,
714714
);
715715
path = IM;
716716
sourceTree = "<group>";
@@ -1103,6 +1103,7 @@
11031103
D3C3782F21E48D3C00EA9AC9 /* IMConversationQuery.swift in Sources */,
11041104
835F5D791D7E6808004D1A0E /* Extension.swift in Sources */,
11051105
835F5D7D1D7E6808004D1A0E /* ObjectProfiler.swift in Sources */,
1106+
D3D73BEB22EAA4EE00ECAE2B /* LiveQueryClient.swift in Sources */,
11061107
1113D80421AB963B000677BD /* IMConversation.swift in Sources */,
11071108
835F5D821D7E6808004D1A0E /* Response.swift in Sources */,
11081109
835F5D861D7E6808004D1A0E /* SMSClient.swift in Sources */,
@@ -1116,6 +1117,7 @@
11161117
11D9C0FB216DF63B00A620B7 /* Application.swift in Sources */,
11171118
835F5D6B1D7E6808004D1A0E /* Bool.swift in Sources */,
11181119
835F5D751D7E6808004D1A0E /* String.swift in Sources */,
1120+
D36E6C7022EC56A800CC1989 /* LiveQuery.swift in Sources */,
11191121
835F5D7B1D7E6808004D1A0E /* LeanCloud.swift in Sources */,
11201122
835F5D741D7E6808004D1A0E /* Role.swift in Sources */,
11211123
D3301279217727870007286A /* Command.pb.swift in Sources */,
@@ -1157,8 +1159,6 @@
11571159
buildActionMask = 2147483647;
11581160
files = (
11591161
D317983D2193DC860037DE57 /* ViewController.swift in Sources */,
1160-
D3E1F48D2193EDF3007B6FFB /* ConnectionTestViewController.swift in Sources */,
1161-
D3F030E4222FB31F009F6C67 /* MessagePushTestViewController.swift in Sources */,
11621162
D317983B2193DC860037DE57 /* AppDelegate.swift in Sources */,
11631163
);
11641164
runOnlyForDeploymentPostprocessing = 0;

LeanCloudTests/IMClientTestCase.swift

Lines changed: 114 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,7 @@ import XCTest
1111

1212
class IMClientTestCase: RTMBaseTestCase {
1313

14-
func testInitWithUser() {
15-
let user = LCUser()
16-
user.username = UUID().uuidString.lcString
17-
user.password = UUID().uuidString.lcString
18-
19-
XCTAssertTrue(user.signUp().isSuccess)
20-
21-
do {
22-
let client = try IMClient(user: user)
23-
XCTAssertNotNil(client.user)
24-
XCTAssertEqual(client.ID, user.objectId?.stringValue)
25-
} catch {
26-
XCTFail("\(error)")
27-
}
28-
}
29-
30-
func testDeinit() {
14+
func testInit() {
3115
do {
3216
let invalidID: String = Array<String>.init(repeating: "a", count: 65).joined()
3317
let _ = try IMClient(ID: invalidID)
@@ -45,23 +29,42 @@ class IMClientTestCase: RTMBaseTestCase {
4529
}
4630

4731
do {
48-
var client: IMClient? = try IMClient(ID: "qweasd", tag: "mobile")
49-
XCTAssertNotNil(client?.deviceTokenObservation)
50-
XCTAssertNotNil(client?.fallbackUDID)
51-
client = nil
52-
XCTAssertNil(client)
32+
let _ = try IMClient(ID: uuid)
33+
let _ = try IMClient(ID: uuid, tag: uuid)
5334
} catch {
54-
XCTFail()
35+
XCTFail("\(error)")
5536
}
5637
}
38+
39+
func testInitWithUser() {
40+
let user = LCUser()
41+
user.username = UUID().uuidString.lcString
42+
user.password = UUID().uuidString.lcString
43+
44+
XCTAssertTrue(user.signUp().isSuccess)
45+
46+
do {
47+
let client = try IMClient(user: user)
48+
XCTAssertNotNil(client.user)
49+
XCTAssertEqual(client.ID, user.objectId?.stringValue)
50+
} catch {
51+
XCTFail("\(error)")
52+
}
53+
}
54+
55+
func testDeinit() {
56+
var client: IMClient? = try! IMClient(ID: uuid, tag: uuid)
57+
weak var wClient: IMClient? = client
58+
client = nil
59+
delay()
60+
XCTAssertNil(wClient)
61+
}
5762

5863
func testOpenAndClose() {
5964
let client: IMClient = try! IMClient(ID: uuid)
6065

61-
for _ in 0..<3 {
62-
let exp = expectation(description: "open and close")
63-
exp.expectedFulfillmentCount = 3
64-
client.open { (result) in
66+
expecting { (exp) in
67+
client.open(completion: { (result) in
6568
XCTAssertTrue(Thread.isMainThread)
6669
XCTAssertTrue(result.isSuccess)
6770
XCTAssertNil(result.error)
@@ -70,24 +73,66 @@ class IMClientTestCase: RTMBaseTestCase {
7073
XCTAssertNil(client.openingOptions)
7174
XCTAssertNil(client.openingCompletion)
7275
XCTAssertEqual(client.sessionState, .opened)
76+
XCTAssertNotNil(client.connectionDelegator.delegate)
77+
exp.fulfill()
78+
})
79+
}
80+
81+
expecting { (exp) in
82+
client.open { (result) in
83+
XCTAssertTrue(result.isFailure)
84+
XCTAssertNotNil(result.error)
85+
exp.fulfill()
86+
}
87+
}
88+
89+
expecting { (exp) in
90+
client.close() { (result) in
91+
XCTAssertTrue(Thread.isMainThread)
92+
XCTAssertTrue(result.isSuccess)
93+
XCTAssertNil(result.error)
94+
XCTAssertNil(client.sessionToken)
95+
XCTAssertNil(client.sessionTokenExpiration)
96+
XCTAssertNil(client.openingOptions)
97+
XCTAssertNil(client.openingCompletion)
98+
XCTAssertEqual(client.sessionState, .closed)
99+
XCTAssertNil(client.connectionDelegator.delegate)
73100
exp.fulfill()
74-
client.open { (result) in
75-
XCTAssertNotNil(result.error)
101+
}
102+
}
103+
}
104+
105+
func testOpenWithSignature() {
106+
let user = LCUser()
107+
user.username = UUID().uuidString.lcString
108+
user.password = UUID().uuidString.lcString
109+
110+
XCTAssertTrue(user.signUp().isSuccess)
111+
112+
if let objectID = user.objectId?.value, let sessionToken = user.sessionToken?.value {
113+
114+
var clientWithUser: IMClient! = try! IMClient(user: user)
115+
expecting { (exp) in
116+
clientWithUser.open(completion: { (result) in
117+
XCTAssertTrue(result.isSuccess)
118+
XCTAssertNil(result.error)
76119
exp.fulfill()
77-
client.close() { (result) in
78-
XCTAssertTrue(Thread.isMainThread)
79-
XCTAssertTrue(result.isSuccess)
80-
XCTAssertNil(result.error)
81-
XCTAssertNil(client.sessionToken)
82-
XCTAssertNil(client.sessionTokenExpiration)
83-
XCTAssertNil(client.openingOptions)
84-
XCTAssertNil(client.openingCompletion)
85-
XCTAssertEqual(client.sessionState, .closed)
86-
exp.fulfill()
87-
}
88-
}
120+
})
121+
}
122+
123+
clientWithUser = nil
124+
delay()
125+
126+
let signatureDelegator = SignatureDelegator()
127+
signatureDelegator.sessionToken = sessionToken
128+
let clientWithID = try! IMClient(ID: objectID, signatureDelegate: signatureDelegator)
129+
expecting { (exp) in
130+
clientWithID.open(completion: { (result) in
131+
XCTAssertTrue(result.isSuccess)
132+
XCTAssertNil(result.error)
133+
exp.fulfill()
134+
})
89135
}
90-
waitForExpectations(timeout: timeout, handler: nil)
91136
}
92137
}
93138

@@ -166,8 +211,8 @@ class IMClientTestCase: RTMBaseTestCase {
166211
}
167212
wait(for: [exp1], timeout: timeout)
168213

169-
RTMConnectionRefMap_protobuf1.removeAll()
170-
RTMConnectionRefMap_protobuf3.removeAll()
214+
RTMConnectionManager.default.protobuf1Map.removeAll()
215+
RTMConnectionManager.default.protobuf3Map.removeAll()
171216

172217
applicationRegistry.removeAll()
173218
let application2: LCApplication = try! LCApplication(
@@ -501,30 +546,6 @@ class IMClientTestCase: RTMBaseTestCase {
501546

502547
XCTAssertEqual(client.convCollection.count, 2)
503548
}
504-
505-
func testInitWithUserAndOpenWithSignature() {
506-
let user = LCUser()
507-
user.username = UUID().uuidString.lcString
508-
user.password = UUID().uuidString.lcString
509-
510-
XCTAssertTrue(user.signUp().isSuccess)
511-
512-
if let sessionToken = user.sessionToken?.stringValue {
513-
514-
let signatureDelegator = SignatureDelegator()
515-
signatureDelegator.sessionToken = sessionToken
516-
517-
let client = try! IMClient(user: user, signatureDelegate: signatureDelegator)
518-
519-
expecting { (exp) in
520-
client.open(completion: { (result) in
521-
XCTAssertTrue(result.isSuccess)
522-
XCTAssertNil(result.error)
523-
exp.fulfill()
524-
})
525-
}
526-
}
527-
}
528549

529550
}
530551

@@ -564,37 +585,40 @@ extension IMClientTestCase {
564585

565586
var sessionToken: String?
566587

588+
func getOpenSignature(client: IMClient, completion: @escaping (IMSignature) -> Void) {
589+
guard let sessionToken = self.sessionToken else {
590+
return
591+
}
592+
let application = client.application
593+
let httpClient: HTTPClient = application.httpClient
594+
let url = application.v2router.route(path: "rtm/clients/sign", module: .api)!
595+
let parameters: [String: Any] = ["session_token": sessionToken]
596+
_ = httpClient.request(url: url, method: .get, parameters: parameters) { (response) in
597+
guard
598+
let value = response.value as? [String: Any],
599+
let client_id = value["client_id"] as? String,
600+
client_id == client.ID,
601+
let signature = value["signature"] as? String,
602+
let timestamp = value["timestamp"] as? Int64,
603+
let nonce = value["nonce"] as? String else
604+
{
605+
return
606+
}
607+
completion(IMSignature(signature: signature, timestamp: timestamp, nonce: nonce))
608+
}
609+
}
610+
567611
func client(_ client: IMClient, action: IMSignature.Action, signatureHandler: @escaping (IMClient, IMSignature?) -> Void) {
568612
XCTAssertTrue(Thread.isMainThread)
569613
switch action {
570614
case .open:
571-
guard let sessionToken = self.sessionToken else {
572-
break
573-
}
574-
575-
let application = client.application
576-
let httpClient: HTTPClient = application.httpClient
577-
let url = application.v2router.route(path: "rtm/clients/sign", module: .api)!
578-
let parameters: [String: Any] = ["session_token": sessionToken]
579-
580-
let _ = httpClient.request(url: url, method: .get, parameters: parameters) { (response) in
581-
guard
582-
let value = response.value as? [String: Any],
583-
let client_id = value["client_id"] as? String,
584-
client_id == client.ID,
585-
let signature = value["signature"] as? String,
586-
let timestamp = value["timestamp"] as? Int64,
587-
let nonce = value["nonce"] as? String else
588-
{
589-
return
590-
}
591-
signatureHandler(client, IMSignature(signature: signature, timestamp: timestamp, nonce: nonce))
615+
self.getOpenSignature(client: client) { (signature) in
616+
signatureHandler(client, signature)
592617
}
593618
default:
594619
break
595620
}
596621
}
597-
598622
}
599623

600624
}

0 commit comments

Comments
 (0)