Skip to content

iOS beta 6 #503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@
'guides': ('https://docs.mongodb.com/guides%s', ''),
'java-sdk': ('https://docs.mongodb.com/realm-sdks/java/10.0.0-BETA.8/%s', ''),
'kotlin-sdk': ('https://docs.mongodb.com/realm-sdks/kotlin/10.0.0-BETA.8/%s', ''),
'swift-sdk': ('https://docs.mongodb.com/realm-sdks/swift/10.0.0-beta.5/%s', ''),
'objc-sdk': ('https://docs.mongodb.com/realm-sdks/objc/10.0.0-beta.5/%s', ''),
'swift-sdk': ('https://docs.mongodb.com/realm-sdks/swift/10.0.0-beta.6/%s', ''),
'objc-sdk': ('https://docs.mongodb.com/realm-sdks/objc/10.0.0-beta.6/%s', ''),
'js-sdk': ('https://docs.mongodb.com/realm-sdks/js/latest/%s', ''),
# True External Links
'android': ('https://developer.android.com/%s', ''),
Expand Down
212 changes: 212 additions & 0 deletions examples/ios/Examples/Authenticate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
//
// Authenticate.swift
// RealmExamples
//
// Created by Chris Bush on 2020-10-01.
// Copyright © 2020 MongoDB, Inc. All rights reserved.
//

import XCTest
import RealmSwift

class Authenticate: XCTestCase {
func testGoogleCredentials() {
let expectation = XCTestExpectation(description: "login completes")

// :code-block-start: google
// Fetch Google token via the Google SDK
let credentials = Credentials(googleAuthCode: "<token>")
app.login(credentials: credentials) { (user, error) in
DispatchQueue.main.sync {
guard error == nil else {
print("Login failed: \(error!)")
// :hide-start:
expectation.fulfill()
// :hide-end:
return
}

// Now logged in, do something with user
}
}
// :code-block-end:
wait(for: [expectation], timeout: 10)
}

func testAppleCredentials() {
let expectation = XCTestExpectation(description: "login completes")

// :code-block-start: apple
// Fetch Apple token via the Apple SDK
let credentials = Credentials(appleToken: "<token>")
app.login(credentials: credentials) { (user, error) in
DispatchQueue.main.sync {
guard error == nil else {
print("Login failed: \(error!)")
// :hide-start:
expectation.fulfill()
// :hide-end:
return
}

// Now logged in, do something with user
}
}
// :code-block-end:
wait(for: [expectation], timeout: 10)
}

func testFacebookCredentials() {
let expectation = XCTestExpectation(description: "login completes")

// :code-block-start: facebook
// Fetch Facebook token via the Facebook SDK
let credentials = Credentials(facebookToken: "<token>")
app.login(credentials: credentials) { (user, error) in
DispatchQueue.main.sync {
guard error == nil else {
print("Login failed: \(error!)")
// :hide-start:
expectation.fulfill()
// :hide-end:
return
}

// Now logged in, do something with user
}
}
// :code-block-end:
wait(for: [expectation], timeout: 10)
}

func testJwtCredentials() {
let expectation = XCTestExpectation(description: "login completes")

// :code-block-start: jwt
let credentials = Credentials(jwt: "<jwt>")
app.login(credentials: credentials) { (user, error) in
DispatchQueue.main.sync {
guard error == nil else {
print("Login failed: \(error!)")
// :hide-start:
expectation.fulfill()
// :hide-end:
return
}

// Now logged in, do something with user
}
}
// :code-block-end:
wait(for: [expectation], timeout: 10)
}

func testCustomFunctionCredentials() {
let expectation = XCTestExpectation(description: "login completes")

// :code-block-start: function
let params = [
"username": "bob"
]

var e: NSError?

app.login(credentials: Credentials(functionPayload: params, error: &e)) { (user, error) in
DispatchQueue.main.sync {
guard error == nil else {
print("Login failed: \(error!)")
// :hide-start:
expectation.fulfill()
// :hide-end:
return
}
// Now logged in, do something with user
}
}
// :code-block-end:
wait(for: [expectation], timeout: 10)
}

func testApiKeyCredentials() {
let expectation = XCTestExpectation(description: "login completes")

// :code-block-start: api-key
let credentials = Credentials(userAPIKey: "<api-key>")
app.login(credentials: credentials) { (user, error) in
DispatchQueue.main.sync {
guard error == nil else {
print("Login failed: \(error!)")
// :hide-start:
expectation.fulfill()
// :hide-end:
return
}

// Now logged in, do something with user
}
}
// :code-block-end:
wait(for: [expectation], timeout: 10)
}

func testEmailPasswordCredentials() {
let expectation = XCTestExpectation(description: "login completes")

// :code-block-start: email-password
let email = "[email protected]"
let password = "12345"
app.login(credentials: Credentials(email: email, password: password)) { (user, error) in
DispatchQueue.main.sync {
guard error == nil else {
print("Login failed: \(error!)")
// :hide-start:
expectation.fulfill()
// :hide-end:
return
}

// Now logged in, do something with user
}
}
// :code-block-end:
wait(for: [expectation], timeout: 10)
}

func testAnonymousCredentials() {
let expectation = XCTestExpectation(description: "login completes")

// :code-block-start: anonymous
let anonymousCredentials = Credentials.anonymous()
app.login(credentials: anonymousCredentials) { (user, error) in
DispatchQueue.main.sync {
guard error == nil else {
print("Login failed: \(error!)")
return
}

// Now logged in, do something with user
// :hide-start:
expectation.fulfill()
// :hide-end:
}
}
// :code-block-end:
wait(for: [expectation], timeout: 10)
}

override func tearDown() {
guard app.currentUser() != nil else {
return
}
let expectation = XCTestExpectation(description: "logout completes")
// :code-block-start: logout
app.currentUser()?.logOut { (error) in
// user is logged out or there was an error
// :hide-start:
expectation.fulfill()
// :hide-end:
}
// :code-block-end:
wait(for: [expectation], timeout: 10)
}
}
4 changes: 2 additions & 2 deletions examples/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ target 'RealmExamples' do
use_frameworks!

# Pods for RealmObjcExamples
pod 'Realm', '=10.0.0-beta.5'
pod 'RealmSwift', '=10.0.0-beta.5'
pod 'Realm', '=10.0.0-beta.6'
pod 'RealmSwift', '=10.0.0-beta.6'
end
20 changes: 10 additions & 10 deletions examples/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
PODS:
- Realm (10.0.0-beta.5):
- Realm/Headers (= 10.0.0-beta.5)
- Realm/Headers (10.0.0-beta.5)
- RealmSwift (10.0.0-beta.5):
- Realm (= 10.0.0-beta.5)
- Realm (10.0.0-beta.6):
- Realm/Headers (= 10.0.0-beta.6)
- Realm/Headers (10.0.0-beta.6)
- RealmSwift (10.0.0-beta.6):
- Realm (= 10.0.0-beta.6)

DEPENDENCIES:
- Realm (= 10.0.0-beta.5)
- RealmSwift (= 10.0.0-beta.5)
- Realm (= 10.0.0-beta.6)
- RealmSwift (= 10.0.0-beta.6)

SPEC REPOS:
trunk:
- Realm
- RealmSwift

SPEC CHECKSUMS:
Realm: e30d3a77421b1b64932ce5843ba7d08afad749fd
RealmSwift: 80488a4f1388b2c5681066f0f26757989034edfb
Realm: 9233fe295925af06c4ea582c3eb43b3fc4de0de9
RealmSwift: 70983e668d1dbda0ae226faf825f093a9cb8be78

PODFILE CHECKSUM: 237135f215039625f091a5b7d7b46875b21c1f1a
PODFILE CHECKSUM: e0d8cccbcb6e16e45b194d76697df33234990f2d

COCOAPODS: 1.9.1
4 changes: 4 additions & 0 deletions examples/ios/RealmExamples.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
48BF341F251129AD004139AF /* MyRealmApp.m in Sources */ = {isa = PBXBuildFile; fileRef = 48BF341E251129AD004139AF /* MyRealmApp.m */; };
48C072042511B5D5004B02BB /* ManageEmailPasswordUsers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48C072032511B5D5004B02BB /* ManageEmailPasswordUsers.swift */; };
48C072062511B6DB004B02BB /* ManageEmailPasswordUsers.m in Sources */ = {isa = PBXBuildFile; fileRef = 48C072052511B6DB004B02BB /* ManageEmailPasswordUsers.m */; };
48E63FB8252646A700F883B1 /* Authenticate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48E63FB7252646A700F883B1 /* Authenticate.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -63,6 +64,7 @@
48BF342025112A7F004139AF /* MyRealmApp.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MyRealmApp.h; sourceTree = "<group>"; };
48C072032511B5D5004B02BB /* ManageEmailPasswordUsers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ManageEmailPasswordUsers.swift; sourceTree = "<group>"; };
48C072052511B6DB004B02BB /* ManageEmailPasswordUsers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ManageEmailPasswordUsers.m; sourceTree = "<group>"; };
48E63FB7252646A700F883B1 /* Authenticate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Authenticate.swift; sourceTree = "<group>"; };
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>"; };
68EA0F823D8002EF83FC15E5 /* Pods_RealmSwiftExampleTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RealmSwiftExampleTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6C55D4D8147A41A52A10E3EF /* Pods_RealmObjcExampleTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RealmObjcExampleTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -127,6 +129,7 @@
48BF341C25111194004139AF /* Task.swift */,
48924B892514EAD900CC9567 /* MultipleUsers.swift */,
48924BBA2515309F00CC9567 /* MultipleUsers.m */,
48E63FB7252646A700F883B1 /* Authenticate.swift */,
48BF34172511095C004139AF /* RealmApp.swift */,
48BF341E251129AD004139AF /* MyRealmApp.m */,
48BF342025112A7F004139AF /* MyRealmApp.h */,
Expand Down Expand Up @@ -355,6 +358,7 @@
48C072062511B6DB004B02BB /* ManageEmailPasswordUsers.m in Sources */,
48BF34182511095C004139AF /* RealmApp.swift in Sources */,
48BF341D25111194004139AF /* Task.swift in Sources */,
48E63FB8252646A700F883B1 /* Authenticate.swift in Sources */,
48924B8A2514EAD900CC9567 /* MultipleUsers.swift in Sources */,
48BF341F251129AD004139AF /* MyRealmApp.m in Sources */,
48C072042511B5D5004B02BB /* ManageEmailPasswordUsers.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
let anonymousCredentials = Credentials.anonymous()
app.login(credentials: anonymousCredentials) { (user, error) in
DispatchQueue.main.sync {
guard error == nil else {
print("Login failed: \(error!)")
return
}

// Now logged in, do something with user
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
let credentials = Credentials(userAPIKey: "<api-key>")
app.login(credentials: credentials) { (user, error) in
DispatchQueue.main.sync {
guard error == nil else {
print("Login failed: \(error!)")
return
}

// Now logged in, do something with user
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Fetch Apple token via the Apple SDK
let credentials = Credentials(appleToken: "<token>")
app.login(credentials: credentials) { (user, error) in
DispatchQueue.main.sync {
guard error == nil else {
print("Login failed: \(error!)")
return
}

// Now logged in, do something with user
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
let email = "[email protected]"
let password = "12345"
app.login(credentials: Credentials(email: email, password: password)) { (user, error) in
DispatchQueue.main.sync {
guard error == nil else {
print("Login failed: \(error!)")
return
}

// Now logged in, do something with user
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Fetch Facebook token via the Facebook SDK
let credentials = Credentials(facebookToken: "<token>")
app.login(credentials: credentials) { (user, error) in
DispatchQueue.main.sync {
guard error == nil else {
print("Login failed: \(error!)")
return
}

// Now logged in, do something with user
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
let params = [
"username": "bob"
]

var e: NSError?

app.login(credentials: Credentials(functionPayload: params, error: &e)) { (user, error) in
DispatchQueue.main.sync {
guard error == nil else {
print("Login failed: \(error!)")
return
}
// Now logged in, do something with user
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Fetch Google token via the Google SDK
let credentials = Credentials(googleAuthCode: "<token>")
app.login(credentials: credentials) { (user, error) in
DispatchQueue.main.sync {
guard error == nil else {
print("Login failed: \(error!)")
return
}

// Now logged in, do something with user
}
}
Loading