Skip to content

Commit 7b521e0

Browse files
authored
iOS beta 6 (#503)
* Upgrade to iOS beta 6 * Add credentials examples * Update install and SDK docs links for beta.6
1 parent ae39152 commit 7b521e0

18 files changed

+357
-145
lines changed

conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@
106106
'guides': ('https://docs.mongodb.com/guides%s', ''),
107107
'java-sdk': ('https://docs.mongodb.com/realm-sdks/java/10.0.0-BETA.8/%s', ''),
108108
'kotlin-sdk': ('https://docs.mongodb.com/realm-sdks/kotlin/10.0.0-BETA.8/%s', ''),
109-
'swift-sdk': ('https://docs.mongodb.com/realm-sdks/swift/10.0.0-beta.5/%s', ''),
110-
'objc-sdk': ('https://docs.mongodb.com/realm-sdks/objc/10.0.0-beta.5/%s', ''),
109+
'swift-sdk': ('https://docs.mongodb.com/realm-sdks/swift/10.0.0-beta.6/%s', ''),
110+
'objc-sdk': ('https://docs.mongodb.com/realm-sdks/objc/10.0.0-beta.6/%s', ''),
111111
'js-sdk': ('https://docs.mongodb.com/realm-sdks/js/latest/%s', ''),
112112
# True External Links
113113
'android': ('https://developer.android.com/%s', ''),
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
//
2+
// Authenticate.swift
3+
// RealmExamples
4+
//
5+
// Created by Chris Bush on 2020-10-01.
6+
// Copyright © 2020 MongoDB, Inc. All rights reserved.
7+
//
8+
9+
import XCTest
10+
import RealmSwift
11+
12+
class Authenticate: XCTestCase {
13+
func testGoogleCredentials() {
14+
let expectation = XCTestExpectation(description: "login completes")
15+
16+
// :code-block-start: google
17+
// Fetch Google token via the Google SDK
18+
let credentials = Credentials(googleAuthCode: "<token>")
19+
app.login(credentials: credentials) { (user, error) in
20+
DispatchQueue.main.sync {
21+
guard error == nil else {
22+
print("Login failed: \(error!)")
23+
// :hide-start:
24+
expectation.fulfill()
25+
// :hide-end:
26+
return
27+
}
28+
29+
// Now logged in, do something with user
30+
}
31+
}
32+
// :code-block-end:
33+
wait(for: [expectation], timeout: 10)
34+
}
35+
36+
func testAppleCredentials() {
37+
let expectation = XCTestExpectation(description: "login completes")
38+
39+
// :code-block-start: apple
40+
// Fetch Apple token via the Apple SDK
41+
let credentials = Credentials(appleToken: "<token>")
42+
app.login(credentials: credentials) { (user, error) in
43+
DispatchQueue.main.sync {
44+
guard error == nil else {
45+
print("Login failed: \(error!)")
46+
// :hide-start:
47+
expectation.fulfill()
48+
// :hide-end:
49+
return
50+
}
51+
52+
// Now logged in, do something with user
53+
}
54+
}
55+
// :code-block-end:
56+
wait(for: [expectation], timeout: 10)
57+
}
58+
59+
func testFacebookCredentials() {
60+
let expectation = XCTestExpectation(description: "login completes")
61+
62+
// :code-block-start: facebook
63+
// Fetch Facebook token via the Facebook SDK
64+
let credentials = Credentials(facebookToken: "<token>")
65+
app.login(credentials: credentials) { (user, error) in
66+
DispatchQueue.main.sync {
67+
guard error == nil else {
68+
print("Login failed: \(error!)")
69+
// :hide-start:
70+
expectation.fulfill()
71+
// :hide-end:
72+
return
73+
}
74+
75+
// Now logged in, do something with user
76+
}
77+
}
78+
// :code-block-end:
79+
wait(for: [expectation], timeout: 10)
80+
}
81+
82+
func testJwtCredentials() {
83+
let expectation = XCTestExpectation(description: "login completes")
84+
85+
// :code-block-start: jwt
86+
let credentials = Credentials(jwt: "<jwt>")
87+
app.login(credentials: credentials) { (user, error) in
88+
DispatchQueue.main.sync {
89+
guard error == nil else {
90+
print("Login failed: \(error!)")
91+
// :hide-start:
92+
expectation.fulfill()
93+
// :hide-end:
94+
return
95+
}
96+
97+
// Now logged in, do something with user
98+
}
99+
}
100+
// :code-block-end:
101+
wait(for: [expectation], timeout: 10)
102+
}
103+
104+
func testCustomFunctionCredentials() {
105+
let expectation = XCTestExpectation(description: "login completes")
106+
107+
// :code-block-start: function
108+
let params = [
109+
"username": "bob"
110+
]
111+
112+
var e: NSError?
113+
114+
app.login(credentials: Credentials(functionPayload: params, error: &e)) { (user, error) in
115+
DispatchQueue.main.sync {
116+
guard error == nil else {
117+
print("Login failed: \(error!)")
118+
// :hide-start:
119+
expectation.fulfill()
120+
// :hide-end:
121+
return
122+
}
123+
// Now logged in, do something with user
124+
}
125+
}
126+
// :code-block-end:
127+
wait(for: [expectation], timeout: 10)
128+
}
129+
130+
func testApiKeyCredentials() {
131+
let expectation = XCTestExpectation(description: "login completes")
132+
133+
// :code-block-start: api-key
134+
let credentials = Credentials(userAPIKey: "<api-key>")
135+
app.login(credentials: credentials) { (user, error) in
136+
DispatchQueue.main.sync {
137+
guard error == nil else {
138+
print("Login failed: \(error!)")
139+
// :hide-start:
140+
expectation.fulfill()
141+
// :hide-end:
142+
return
143+
}
144+
145+
// Now logged in, do something with user
146+
}
147+
}
148+
// :code-block-end:
149+
wait(for: [expectation], timeout: 10)
150+
}
151+
152+
func testEmailPasswordCredentials() {
153+
let expectation = XCTestExpectation(description: "login completes")
154+
155+
// :code-block-start: email-password
156+
let email = "[email protected]"
157+
let password = "12345"
158+
app.login(credentials: Credentials(email: email, password: password)) { (user, error) in
159+
DispatchQueue.main.sync {
160+
guard error == nil else {
161+
print("Login failed: \(error!)")
162+
// :hide-start:
163+
expectation.fulfill()
164+
// :hide-end:
165+
return
166+
}
167+
168+
// Now logged in, do something with user
169+
}
170+
}
171+
// :code-block-end:
172+
wait(for: [expectation], timeout: 10)
173+
}
174+
175+
func testAnonymousCredentials() {
176+
let expectation = XCTestExpectation(description: "login completes")
177+
178+
// :code-block-start: anonymous
179+
let anonymousCredentials = Credentials.anonymous()
180+
app.login(credentials: anonymousCredentials) { (user, error) in
181+
DispatchQueue.main.sync {
182+
guard error == nil else {
183+
print("Login failed: \(error!)")
184+
return
185+
}
186+
187+
// Now logged in, do something with user
188+
// :hide-start:
189+
expectation.fulfill()
190+
// :hide-end:
191+
}
192+
}
193+
// :code-block-end:
194+
wait(for: [expectation], timeout: 10)
195+
}
196+
197+
override func tearDown() {
198+
guard app.currentUser() != nil else {
199+
return
200+
}
201+
let expectation = XCTestExpectation(description: "logout completes")
202+
// :code-block-start: logout
203+
app.currentUser()?.logOut { (error) in
204+
// user is logged out or there was an error
205+
// :hide-start:
206+
expectation.fulfill()
207+
// :hide-end:
208+
}
209+
// :code-block-end:
210+
wait(for: [expectation], timeout: 10)
211+
}
212+
}

examples/ios/Podfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ target 'RealmExamples' do
66
use_frameworks!
77

88
# Pods for RealmObjcExamples
9-
pod 'Realm', '=10.0.0-beta.5'
10-
pod 'RealmSwift', '=10.0.0-beta.5'
9+
pod 'Realm', '=10.0.0-beta.6'
10+
pod 'RealmSwift', '=10.0.0-beta.6'
1111
end

examples/ios/Podfile.lock

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
PODS:
2-
- Realm (10.0.0-beta.5):
3-
- Realm/Headers (= 10.0.0-beta.5)
4-
- Realm/Headers (10.0.0-beta.5)
5-
- RealmSwift (10.0.0-beta.5):
6-
- Realm (= 10.0.0-beta.5)
2+
- Realm (10.0.0-beta.6):
3+
- Realm/Headers (= 10.0.0-beta.6)
4+
- Realm/Headers (10.0.0-beta.6)
5+
- RealmSwift (10.0.0-beta.6):
6+
- Realm (= 10.0.0-beta.6)
77

88
DEPENDENCIES:
9-
- Realm (= 10.0.0-beta.5)
10-
- RealmSwift (= 10.0.0-beta.5)
9+
- Realm (= 10.0.0-beta.6)
10+
- RealmSwift (= 10.0.0-beta.6)
1111

1212
SPEC REPOS:
1313
trunk:
1414
- Realm
1515
- RealmSwift
1616

1717
SPEC CHECKSUMS:
18-
Realm: e30d3a77421b1b64932ce5843ba7d08afad749fd
19-
RealmSwift: 80488a4f1388b2c5681066f0f26757989034edfb
18+
Realm: 9233fe295925af06c4ea582c3eb43b3fc4de0de9
19+
RealmSwift: 70983e668d1dbda0ae226faf825f093a9cb8be78
2020

21-
PODFILE CHECKSUM: 237135f215039625f091a5b7d7b46875b21c1f1a
21+
PODFILE CHECKSUM: e0d8cccbcb6e16e45b194d76697df33234990f2d
2222

2323
COCOAPODS: 1.9.1

examples/ios/RealmExamples.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
48BF341F251129AD004139AF /* MyRealmApp.m in Sources */ = {isa = PBXBuildFile; fileRef = 48BF341E251129AD004139AF /* MyRealmApp.m */; };
2626
48C072042511B5D5004B02BB /* ManageEmailPasswordUsers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48C072032511B5D5004B02BB /* ManageEmailPasswordUsers.swift */; };
2727
48C072062511B6DB004B02BB /* ManageEmailPasswordUsers.m in Sources */ = {isa = PBXBuildFile; fileRef = 48C072052511B6DB004B02BB /* ManageEmailPasswordUsers.m */; };
28+
48E63FB8252646A700F883B1 /* Authenticate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48E63FB7252646A700F883B1 /* Authenticate.swift */; };
2829
/* End PBXBuildFile section */
2930

3031
/* Begin PBXContainerItemProxy section */
@@ -63,6 +64,7 @@
6364
48BF342025112A7F004139AF /* MyRealmApp.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MyRealmApp.h; sourceTree = "<group>"; };
6465
48C072032511B5D5004B02BB /* ManageEmailPasswordUsers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ManageEmailPasswordUsers.swift; sourceTree = "<group>"; };
6566
48C072052511B6DB004B02BB /* ManageEmailPasswordUsers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ManageEmailPasswordUsers.m; sourceTree = "<group>"; };
67+
48E63FB7252646A700F883B1 /* Authenticate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Authenticate.swift; sourceTree = "<group>"; };
6668
4B040991139BCE878C9D6C0A /* Pods-RealmExamples.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RealmExamples.release.xcconfig"; path = "Target Support Files/Pods-RealmExamples/Pods-RealmExamples.release.xcconfig"; sourceTree = "<group>"; };
6769
68EA0F823D8002EF83FC15E5 /* Pods_RealmSwiftExampleTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RealmSwiftExampleTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6870
6C55D4D8147A41A52A10E3EF /* Pods_RealmObjcExampleTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RealmObjcExampleTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -127,6 +129,7 @@
127129
48BF341C25111194004139AF /* Task.swift */,
128130
48924B892514EAD900CC9567 /* MultipleUsers.swift */,
129131
48924BBA2515309F00CC9567 /* MultipleUsers.m */,
132+
48E63FB7252646A700F883B1 /* Authenticate.swift */,
130133
48BF34172511095C004139AF /* RealmApp.swift */,
131134
48BF341E251129AD004139AF /* MyRealmApp.m */,
132135
48BF342025112A7F004139AF /* MyRealmApp.h */,
@@ -355,6 +358,7 @@
355358
48C072062511B6DB004B02BB /* ManageEmailPasswordUsers.m in Sources */,
356359
48BF34182511095C004139AF /* RealmApp.swift in Sources */,
357360
48BF341D25111194004139AF /* Task.swift in Sources */,
361+
48E63FB8252646A700F883B1 /* Authenticate.swift in Sources */,
358362
48924B8A2514EAD900CC9567 /* MultipleUsers.swift in Sources */,
359363
48BF341F251129AD004139AF /* MyRealmApp.m in Sources */,
360364
48C072042511B5D5004B02BB /* ManageEmailPasswordUsers.swift in Sources */,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
let anonymousCredentials = Credentials.anonymous()
2+
app.login(credentials: anonymousCredentials) { (user, error) in
3+
DispatchQueue.main.sync {
4+
guard error == nil else {
5+
print("Login failed: \(error!)")
6+
return
7+
}
8+
9+
// Now logged in, do something with user
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
let credentials = Credentials(userAPIKey: "<api-key>")
2+
app.login(credentials: credentials) { (user, error) in
3+
DispatchQueue.main.sync {
4+
guard error == nil else {
5+
print("Login failed: \(error!)")
6+
return
7+
}
8+
9+
// Now logged in, do something with user
10+
}
11+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Fetch Apple token via the Apple SDK
2+
let credentials = Credentials(appleToken: "<token>")
3+
app.login(credentials: credentials) { (user, error) in
4+
DispatchQueue.main.sync {
5+
guard error == nil else {
6+
print("Login failed: \(error!)")
7+
return
8+
}
9+
10+
// Now logged in, do something with user
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
let email = "[email protected]"
2+
let password = "12345"
3+
app.login(credentials: Credentials(email: email, password: password)) { (user, error) in
4+
DispatchQueue.main.sync {
5+
guard error == nil else {
6+
print("Login failed: \(error!)")
7+
return
8+
}
9+
10+
// Now logged in, do something with user
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Fetch Facebook token via the Facebook SDK
2+
let credentials = Credentials(facebookToken: "<token>")
3+
app.login(credentials: credentials) { (user, error) in
4+
DispatchQueue.main.sync {
5+
guard error == nil else {
6+
print("Login failed: \(error!)")
7+
return
8+
}
9+
10+
// Now logged in, do something with user
11+
}
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
let params = [
2+
"username": "bob"
3+
]
4+
5+
var e: NSError?
6+
7+
app.login(credentials: Credentials(functionPayload: params, error: &e)) { (user, error) in
8+
DispatchQueue.main.sync {
9+
guard error == nil else {
10+
print("Login failed: \(error!)")
11+
return
12+
}
13+
// Now logged in, do something with user
14+
}
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Fetch Google token via the Google SDK
2+
let credentials = Credentials(googleAuthCode: "<token>")
3+
app.login(credentials: credentials) { (user, error) in
4+
DispatchQueue.main.sync {
5+
guard error == nil else {
6+
print("Login failed: \(error!)")
7+
return
8+
}
9+
10+
// Now logged in, do something with user
11+
}
12+
}

0 commit comments

Comments
 (0)