-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Arnaud Dorgans
committed
Apr 3, 2018
1 parent
5af912c
commit e78e10f
Showing
8 changed files
with
113 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ it, simply add the following line to your Podfile: | |
|
||
```ruby | ||
pod 'RxFirebase/Firestore' | ||
pod 'RxFirebase/RemoteConfig' | ||
``` | ||
|
||
## Usage | ||
|
@@ -76,7 +77,7 @@ db.collection("cities") | |
// https://firebase.google.com/docs/firestore/manage-data/add-data | ||
``` | ||
|
||
Get a document | ||
Get a document: | ||
```swift | ||
let db = Firestore.firestore() | ||
|
||
|
@@ -97,7 +98,7 @@ db.collection("cities") | |
// https://firebase.google.com/docs/firestore/query-data/get-data | ||
``` | ||
|
||
Get Realtime Updates | ||
Get Realtime Updates: | ||
```swift | ||
let db = Firestore.firestore() | ||
|
||
|
@@ -135,7 +136,7 @@ db.collection("cities") | |
// https://firebase.google.com/docs/firestore/query-data/listen | ||
``` | ||
|
||
Batched writes | ||
Batched writes: | ||
```swift | ||
let db = Firestore.firestore() | ||
|
||
|
@@ -158,7 +159,7 @@ batch.rx | |
// https://firebase.google.com/docs/firestore/manage-data/transactions | ||
``` | ||
|
||
Transactions | ||
Transactions: | ||
```swift | ||
let db = Firestore.firestore() | ||
let sfReference = db.collection("cities").document("SF") | ||
|
@@ -195,6 +196,26 @@ db.rx.runTransaction { transaction, errorPointer in | |
// https://firebase.google.com/docs/firestore/manage-data/transactions | ||
``` | ||
|
||
### RemoteConfig | ||
|
||
Fetch: | ||
```swift | ||
// TimeInterval is set to expirationDuration here, indicating the next fetch request will use | ||
// data fetched from the Remote Config service, rather than cached parameter values, if cached | ||
// parameter values are more than expirationDuration seconds old. See Best Practices in the | ||
// README for more information. | ||
RemoteConfig.remoteConfig() | ||
.rx | ||
.fetch(withExpirationDuration: TimeInterval(expirationDuration), activateFetched: true) | ||
.subscribe(onNext: { status in | ||
print("Config fetched! with success:\(status == .success)") | ||
}, onError: { error in | ||
print("Error: \(error)") | ||
}).disposed(by: disposeBag) | ||
|
||
// https://firebase.google.com/docs/remote-config/ios | ||
``` | ||
|
||
## Author | ||
|
||
Arnaud Dorgans, [email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// | ||
// RemoteConfig+Rx.swift | ||
// RxFirebase | ||
// | ||
// Created by Arnaud Dorgans on 03/04/2018. | ||
// | ||
|
||
import UIKit | ||
import RxSwift | ||
import FirebaseRemoteConfig | ||
|
||
extension Reactive where Base: RemoteConfig { | ||
|
||
/// Fetches Remote Config data with a callback. Call activateFetched to make fetched data available | ||
/// to your app. | ||
/// @param completionHandler Fetch operation callback. | ||
public func fetch(activateFetched: Bool = false) -> Observable<RemoteConfigFetchStatus> { | ||
return Observable<RemoteConfigFetchStatus>.create { observer in | ||
self.base.fetch { status, error in | ||
guard let error = error else { | ||
if activateFetched, status == .success { | ||
self.base.activateFetched() | ||
} | ||
observer.onNext(status) | ||
observer.onCompleted() | ||
return | ||
} | ||
observer.onError(error) | ||
} | ||
return Disposables.create() | ||
} | ||
} | ||
|
||
/// Fetches Remote Config data and sets a duration that specifies how long config data lasts. | ||
/// Call activateFetched to make fetched data available to your app. | ||
/// @param expirationDuration Duration that defines how long fetched config data is available, in | ||
/// seconds. When the config data expires, a new fetch is required. | ||
/// @param completionHandler Fetch operation callback. | ||
public func fetch(withExpirationDuration duration: TimeInterval, activateFetched: Bool = false) -> Observable<RemoteConfigFetchStatus> { | ||
return Observable<RemoteConfigFetchStatus>.create { observer in | ||
self.base.fetch(withExpirationDuration: duration) { status, error in | ||
guard let error = error else { | ||
if activateFetched, status == .success { | ||
self.base.activateFetched() | ||
} | ||
observer.onNext(status) | ||
observer.onCompleted() | ||
return | ||
} | ||
observer.onError(error) | ||
} | ||
return Disposables.create() | ||
} | ||
} | ||
} |