-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add custom signals support in Remote Config. #13976
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
Changes from 10 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
2455ff8
[Config] Add custom signal setter API
ncooke3 372538c
Make API test clearer
ncooke3 2d840c4
Rename to CustomSignal to CustomSignalValue
ncooke3 4a25d7b
Work for interpolated strings cc: @andrewheard
ncooke3 4c2bc89
Add support for deleting key
ncooke3 a8e3617
Complete implementation for setting/updating custom signals with tests
tusharkhandelwal8 b047554
Fix lint errors and code formatting.
tusharkhandelwal8 8d0f566
Set minimum iOS version to 13 for setCustomSignals
tusharkhandelwal8 aebbcf5
Add limits, input validation, and unit tests for custom signals
tusharkhandelwal8 b2de614
Move last completionHandler block outside if condition
tusharkhandelwal8 548eefe
Add limits as constants and dispatch all completion blocks to global …
tusharkhandelwal8 6df9e32
Store Custom Signals value as String instead of Object in iOS SDK
tusharkhandelwal8 de73b8f
Extend CustomSignalValue to include Double type
tusharkhandelwal8 d024203
Add debug logs to print custom signals during updates and fetches.
tusharkhandelwal8 cff4d27
Fix Lint
tusharkhandelwal8 7fa9ed0
Dispatch completion blocks to main queue and update enum values.
tusharkhandelwal8 9f25a01
Refactor API to enforce non-null dictionary and improve naming
tusharkhandelwal8 a7ab377
Add Swift tests and immutable signal map
tusharkhandelwal8 1d99846
Use descriptionWithLocale instead of description to convert NSNumber …
tusharkhandelwal8 ec58080
Use stringValue to convert NSNumber to NSString
tusharkhandelwal8 c2d859d
Improve documentation for setCustomSignals.
tusharkhandelwal8 b51e459
Log only keys of custom signals.
tusharkhandelwal8 0af9d34
Update changelog file to include custom signals feature.
tusharkhandelwal8 52108dc
Merge branch 'main' into nc/custom-signal
tusharkhandelwal8 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
tusharkhandelwal8 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,86 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import Foundation | ||
#if SWIFT_PACKAGE | ||
@_exported import FirebaseRemoteConfigInternal | ||
#endif // SWIFT_PACKAGE | ||
|
||
// TODO: Document. | ||
public struct CustomSignalValue { | ||
private enum Kind { | ||
case string(String) | ||
case integer(Int) | ||
} | ||
|
||
private let kind: Kind | ||
|
||
private init(kind: Kind) { | ||
self.kind = kind | ||
} | ||
|
||
/// Returns a string backed custom signal. | ||
/// - Parameter string: The given string to back the custom signal with. | ||
/// - Returns: A string backed custom signal. | ||
public static func string(_ string: String) -> Self { | ||
Self(kind: .string(string)) | ||
} | ||
|
||
/// Returns an integer backed custom signal. | ||
/// - Parameter integer: The given integer to back the custom signal with. | ||
/// - Returns: An integer backed custom signal. | ||
public static func integer(_ integer: Int) -> Self { | ||
Self(kind: .integer(integer)) | ||
} | ||
|
||
fileprivate func toNSObject() -> NSObject { | ||
switch kind { | ||
case let .string(string): | ||
return string as NSString | ||
case let .integer(int): | ||
return int as NSNumber | ||
} | ||
} | ||
} | ||
|
||
extension CustomSignalValue: ExpressibleByStringInterpolation { | ||
public init(stringLiteral value: String) { | ||
self = .string(value) | ||
} | ||
} | ||
|
||
extension CustomSignalValue: ExpressibleByIntegerLiteral { | ||
public init(integerLiteral value: Int) { | ||
self = .integer(value) | ||
} | ||
} | ||
|
||
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *) | ||
public extension RemoteConfig { | ||
/// Sets custom signals for this Remote Config instance. | ||
/// - Parameter customSignals: A dictionary mapping string keys to custom | ||
/// signals to be set for the app instance. | ||
func setCustomSignals(_ customSignals: [String: CustomSignalValue?]) async throws { | ||
tusharkhandelwal8 marked this conversation as resolved.
Show resolved
Hide resolved
tusharkhandelwal8 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return try await withCheckedThrowingContinuation { continuation in | ||
let customSignals = customSignals.mapValues { $0?.toNSObject() ?? NSNull() } | ||
self.__setCustomSignals(customSignals) { error in | ||
if let error { | ||
continuation.resume(throwing: error) | ||
} else { | ||
continuation.resume() | ||
} | ||
} | ||
} | ||
} | ||
} |
tusharkhandelwal8 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.