আপনি আপনার অ্যাপ্লিকেশনটিতে পরামিতিগুলি সংজ্ঞায়িত করতে এবং ক্লাউডে তাদের মানগুলি আপডেট করতে Firebase Remote Config ব্যবহার করতে পারেন, আপনাকে কোনও অ্যাপ্লিকেশন আপডেট বিতরণ না করে আপনার অ্যাপ্লিকেশনটির উপস্থিতি এবং আচরণ সংশোধন করতে দেয়। এই গাইডটি আপনাকে শুরু করার পদক্ষেপগুলির মধ্যে দিয়ে চলেছে এবং কিছু নমুনা কোড সরবরাহ করে, যার সবগুলিই ফায়ারবেস/কুইকস্টার্ট-আইওএস গিটহাব সংগ্রহস্থল থেকে ক্লোন বা ডাউনলোড করার জন্য উপলব্ধ।
পদক্ষেপ 1: আপনার অ্যাপ্লিকেশনটিতে Remote Config যুক্ত করুন
যদি আপনি ইতিমধ্যেই না করে থাকেন, তাহলে আপনার Apple প্রকল্পে Firebase যোগ করুন ।
Remote Config জন্য, Google Analytics ব্যবহারকারীর বৈশিষ্ট্য এবং শ্রোতাদের কাছে অ্যাপ্লিকেশন দৃষ্টান্তের শর্তসাপেক্ষ লক্ষ্যমাত্রার জন্য প্রয়োজনীয়। আপনি আপনার প্রকল্পে Google Analytics সক্ষম করেছেন তা নিশ্চিত করুন।
সিঙ্গেলটন Remote Config অবজেক্টটি তৈরি করুন, যেমনটি নিম্নলিখিত উদাহরণে দেখানো হয়েছে:
সুইফট
remoteConfig = RemoteConfig.remoteConfig() let settings = RemoteConfigSettings() settings.minimumFetchInterval = 0 remoteConfig.configSettings = settings
উদ্দেশ্য-C
self.remoteConfig = [FIRRemoteConfig remoteConfig]; FIRRemoteConfigSettings *remoteConfigSettings = [[FIRRemoteConfigSettings alloc] init]; remoteConfigSettings.minimumFetchInterval = 0; self.remoteConfig.configSettings = remoteConfigSettings;
এই অবজেক্টটি অ্যাপ্লিকেশন ডিফল্ট প্যারামিটার মানগুলি সংরক্ষণ করতে ব্যবহৃত হয়, Remote Config ব্যাকেন্ড থেকে আপডেট হওয়া প্যারামিটার মানগুলি আনতে এবং যখন আপনার অ্যাপ্লিকেশনটিতে আনার মানগুলি উপলব্ধ করা হয় তখন নিয়ন্ত্রণ করে।
বিকাশের সময়, এটি একটি অপেক্ষাকৃত কম ন্যূনতম আনার ব্যবধান সেট করার পরামর্শ দেওয়া হয়। আরও তথ্যের জন্য থ্রোটলিং দেখুন।
পদক্ষেপ 2: অ্যাপ্লিকেশন ডিফল্ট প্যারামিটার মান সেট করুন
আপনি Remote Config অবজেক্টে অ্যাপ্লিকেশন ডিফল্ট প্যারামিটার মানগুলি সেট করতে পারেন, যাতে আপনার অ্যাপ্লিকেশনটি Remote Config ব্যাকএন্ডের সাথে সংযোগ স্থাপনের আগে উদ্দেশ্য হিসাবে আচরণ করে এবং যাতে কোনও ব্যাকএন্ডে সেট না করা থাকলে ডিফল্ট মানগুলি পাওয়া যায়।
একটি
NSDictionary
অবজেক্ট বা প্লিস্ট ফাইল ব্যবহার করে প্যারামিটারের নামগুলির একটি সেট এবং ডিফল্ট প্যারামিটার মানগুলি সংজ্ঞায়িত করুন।আপনি যদি ইতিমধ্যে Remote Config ব্যাকেন্ড প্যারামিটার মানগুলি কনফিগার করে থাকেন তবে আপনি একটি উত্পন্ন
plist
ফাইল ডাউনলোড করতে পারেন যা সমস্ত ডিফল্ট মান অন্তর্ভুক্ত করে এবং এটি আপনার এক্সকোড প্রকল্পে সংরক্ষণ করতে পারে।বিশ্রাম
curl --compressed -D headers -H "Authorization: Bearer token -X GET https://firebaseremoteconfig.googleapis.com/v1/projects/my-project-id/remoteConfig:downloadDefaults?format=PLIST -o RemoteConfigDefaults.plist
Firebase কনসোল
প্যারামিটার ট্যাবে, মেনুটি খুলুন এবং ডাউনলোড ডিফল্ট মানগুলি নির্বাচন করুন।
যখন অনুরোধ করা হয়, আইওএসের জন্য .প্লিস্ট সক্ষম করুন, তারপরে ডাউনলোড ফাইলটি ক্লিক করুন।
setDefaults:
ব্যবহার করে Remote Config অবজেক্টে এই মানগুলি যুক্ত করুন :। নিম্নলিখিত উদাহরণটি একটি প্লিস্ট ফাইল থেকে অ্যাপ্লিকেশন ডিফল্ট মান সেট করে:সুইফট
remoteConfig.setDefaults(fromPlist: "RemoteConfigDefaults")
উদ্দেশ্য-C
[self.remoteConfig setDefaultsFromPlistFileName:@"RemoteConfigDefaults"];
পদক্ষেপ 3: আপনার অ্যাপ্লিকেশনটিতে ব্যবহারের জন্য প্যারামিটার মানগুলি পান
এখন আপনি Remote Config অবজেক্ট থেকে প্যারামিটার মান পেতে পারেন। আপনি যদি পরে Remote Config ব্যাকেন্ডে মানগুলি সেট করেন তবে সেগুলি আনুন এবং তারপরে সেগুলি সক্রিয় করুন, সেই মানগুলি আপনার অ্যাপ্লিকেশনটিতে উপলব্ধ। অন্যথায়, আপনি setDefaults:
। এই মানগুলি পেতে, configValueForKey:
পদ্ধতিটি কল করুন, একটি যুক্তি হিসাবে প্যারামিটার কী সরবরাহ করে।
let remoteConfig = RemoteConfig.remoteConfig()
// Retrieve a parameter value using configValueForKey
let welcomeMessageValue = remoteConfig.configValue(forKey: "welcome_message")
let welcomeMessage = welcomeMessageValue.stringValue
let featureFlagValue = remoteConfig.configValue(forKey: "new_feature_flag")
let isFeatureEnabled = featureFlagValue.boolValue
সুইফটে এই মানগুলি অ্যাক্সেস করার আরও বেশি পঠনযোগ্য এবং সুবিধাজনক উপায় হ'ল সুইফ্টের সাবস্ক্রিপ্ট স্বরলিপি:
let remoteConfig = RemoteConfig.remoteConfig()
// Retrieve a string parameter value
let welcomeMessage = remoteConfig["welcome_message"].stringValue
// Retrieve a boolean parameter value
let isFeatureEnabled = remoteConfig["new_feature_flag"].boolValue
// Retrieve a number parameter value
let maxItemCount = remoteConfig["max_items"].numberValue.intValue
টাইপ-নিরাপদ কনফিগারেশনের জন্য কোডেবল ব্যবহার করুন
আরও জটিল কনফিগারেশনের জন্য, আপনি Remote Config থেকে কাঠামোগত ডেটা ডিকোড করতে সুইফটের Codable
প্রোটোকল ব্যবহার করতে পারেন। এটি টাইপ-নিরাপদ কনফিগারেশন পরিচালনা সরবরাহ করে এবং জটিল অবজেক্টগুলির সাথে কাজ করা সহজ করে।
// Define a Codable struct for your configuration
struct AppFeatureConfig: Codable {
let isNewFeatureEnabled: Bool
let maxUploadSize: Int
let themeColors: [String: String]
}
// Fetch and decode the configuration
func configureAppFeatures() {
let remoteConfig = RemoteConfig.remoteConfig()
remoteConfig.fetchAndActivate { status, error in
guard error == nil else { return }
do {
let featureConfig = try remoteConfig["app_feature_config"].decoded(asType: AppFeatureConfig.self)
configureApp(with: featureConfig)
} catch {
// Handle decoding errors
print("Failed to decode configuration: \(error)")
}
}
}
এই পদ্ধতিটি আপনাকে দেয়:
- জটিল কনফিগারেশন কাঠামো সংজ্ঞায়িত করুন।
- স্বয়ংক্রিয়ভাবে JSON কনফিগারেশনগুলি পার্স করুন।
- Remote Config মানগুলি অ্যাক্সেস করার সময় সুরক্ষার প্রকারটি নিশ্চিত করুন।
- কাঠামোগত Remote Config টেম্পলেটগুলি পরিচালনা করার জন্য পরিষ্কার, পঠনযোগ্য কোড সরবরাহ করুন।
সুইফটুইতে ঘোষণামূলক কনফিগারেশনের জন্য সম্পত্তি র্যাপারগুলি ব্যবহার করুন
সম্পত্তি মোড়ক একটি শক্তিশালী সুইফট বৈশিষ্ট্য যা আপনাকে সম্পত্তি ঘোষণায় কাস্টম আচরণ যুক্ত করতে দেয়। সুইফটুইয়ে, সম্পত্তি র্যাপারগুলি রাষ্ট্র, বাইন্ডিং এবং অন্যান্য সম্পত্তি আচরণ পরিচালনা করতে ব্যবহৃত হয়। আরও তথ্যের জন্য, সুইফট ভাষা গাইড দেখুন।
struct ContentView: View {
@RemoteConfigProperty(key: "cardColor", fallback: "#f05138")
var cardColor
var body: some View {
VStack {
Text("Dynamic Configuration")
.background(Color(hex: cardColor))
}
.onAppear {
RemoteConfig.remoteConfig().fetchAndActivate()
}
}
}
আপনি যখন ডিফল্ট মান এবং সরলীকৃত কনফিগারেশন পরিচালনার জন্য অন্তর্নির্মিত সমর্থন সহ সুইফটুইতে Remote Config মানগুলি অ্যাক্সেস করার জন্য একটি ঘোষণামূলক উপায় চান তখন @RemoteConfigProperty
প্রপার্টি র্যাপারটি ব্যবহার করুন।
পদক্ষেপ 4: প্যারামিটার মান সেট করুন
Firebase কনসোল বা Remote Config ব্যাকেন্ড এপিআই ব্যবহার করে আপনি নতুন ব্যাকএন্ড ডিফল্ট মান তৈরি করতে পারেন যা আপনার পছন্দসই শর্তসাপেক্ষ যুক্তি বা ব্যবহারকারীর লক্ষ্য অনুযায়ী অ্যাপ্লিকেশন মানগুলিকে ওভাররাইড করে। এই বিভাগটি আপনাকে এই মানগুলি তৈরি করতে Firebase কনসোল পদক্ষেপের মধ্য দিয়ে চলেছে।
- Firebase কনসোলে , আপনার প্রকল্প খুলুন।
- রিমোট Remote Config ড্যাশবোর্ড দেখতে মেনু থেকে Remote Config নির্বাচন করুন।
- আপনি আপনার অ্যাপ্লিকেশনটিতে সংজ্ঞায়িত প্যারামিটারগুলির মতো একই নামগুলির সাথে পরামিতিগুলি সংজ্ঞায়িত করুন। প্রতিটি প্যারামিটারের জন্য, আপনি একটি ডিফল্ট মান সেট করতে পারেন (যা শেষ পর্যন্ত অ্যাপ্লিকেশন ডিফল্ট মানটি ওভাররাইড করবে) এবং আপনি শর্তাধীন মানও সেট করতে পারেন। আরও জানতে, Remote Config পরামিতি এবং শর্তাদি দেখুন।
যদি কাস্টম সিগন্যাল শর্তগুলি ব্যবহার করে তবে বৈশিষ্ট্যগুলি এবং তাদের মানগুলি সংজ্ঞায়িত করুন। নিম্নলিখিত উদাহরণগুলি কীভাবে কাস্টম সংকেত শর্তটি সংজ্ঞায়িত করতে হয় তা দেখায়।
সুইফট
Task { let customSignals: [String: CustomSignalValue?] = [ "city": .string("Tokyo"), "preferred_event_category": .string("sports") ] do { try await remoteConfig.setCustomSignals(customSignals) print("Custom signals set successfully!") } catch { print("Error setting custom signals: \(error)") } }
উদ্দেশ্য-C
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSDictionary *customSignals = @{ @"city": @"Tokyo", @"preferred_event_category": @"sports" }; [self.remoteConfig setCustomSignals:customSignals withCompletion:^(NSError * _Nullable error) { if (error) { NSLog(@"Error setting custom signals: %@", error); } else { NSLog(@"Custom signals set successfully!"); } }]; });
পদক্ষেপ 5: মান আনুন এবং সক্রিয় করুন
Remote Config থেকে প্যারামিটার মানগুলি আনতে, fetchWithCompletionHandler:
বা fetchWithExpirationDuration:completionHandler:
পদ্ধতি। আপনি ব্যাকএন্ডে সেট করা যে কোনও মানগুলি Remote Config অবজেক্টে আনা এবং ক্যাশে করা হয়।
যেসব ক্ষেত্রে আপনি একটি কলটিতে মান আনতে এবং সক্রিয় করতে চান এমন ক্ষেত্রে, fetchAndActivateWithCompletionHandler:
।
এই উদাহরণটি Remote Config ব্যাকএন্ড (ক্যাশেড মান নয়) থেকে মানগুলি নিয়ে আসে এবং activateWithCompletionHandler:
অ্যাপ্লিকেশনটিতে এগুলি উপলব্ধ করার জন্য:
সুইফট
remoteConfig.fetch { (status, error) -> Void in if status == .success { print("Config fetched!") self.remoteConfig.activate { changed, error in // ... } } else { print("Config not fetched") print("Error: \(error?.localizedDescription ?? "No error available.")") } self.displayWelcome() }
উদ্দেশ্য-C
[self.remoteConfig fetchWithCompletionHandler:^(FIRRemoteConfigFetchStatus status, NSError *error) { if (status == FIRRemoteConfigFetchStatusSuccess) { NSLog(@"Config fetched!"); [self.remoteConfig activateWithCompletion:^(BOOL changed, NSError * _Nullable error) { if (error != nil) { NSLog(@"Activate error: %@", error.localizedDescription); } else { dispatch_async(dispatch_get_main_queue(), ^{ [self displayWelcome]; }); } }]; } else { NSLog(@"Config not fetched"); NSLog(@"Error %@", error.localizedDescription); } }];
যেহেতু এই আপডেট হওয়া প্যারামিটার মানগুলি আপনার অ্যাপ্লিকেশনটির আচরণ এবং উপস্থিতিকে প্রভাবিত করে, আপনার এমন সময়ে আনার মানগুলি সক্রিয় করা উচিত যা আপনার ব্যবহারকারীর জন্য একটি মসৃণ অভিজ্ঞতা নিশ্চিত করে, যেমন পরের বার ব্যবহারকারী আপনার অ্যাপ্লিকেশনটি খোলেন। আরও তথ্য এবং উদাহরণগুলির জন্য রিমোট কনফিগার লোডিং কৌশলগুলি দেখুন।
পদক্ষেপ 6: রিয়েল টাইমে আপডেটের জন্য শুনুন
আপনি প্যারামিটার মানগুলি আনার পরে, আপনি Remote Config ব্যাকেন্ড থেকে আপডেটগুলি শুনতে রিয়েল-টাইম Remote Config ব্যবহার করতে পারেন। রিয়েল-টাইম Remote Config সংকেত সংযুক্ত ডিভাইসে যখন আপডেটগুলি পাওয়া যায় এবং আপনি একটি নতুন Remote Config সংস্করণ প্রকাশের পরে স্বয়ংক্রিয়ভাবে পরিবর্তনগুলি আনেন।
রিয়েল-টাইম আপডেটগুলি Apple প্ল্যাটফর্ম ভি 10.7.0+ এবং উচ্চতর জন্য Firebase এসডিকে দ্বারা সমর্থিত।
আপনার অ্যাপ্লিকেশনটিতে, আপডেটগুলি শুনতে শুরু করতে
addOnConfigUpdateListener
কল করুন এবং স্বয়ংক্রিয়ভাবে কোনও নতুন বা আপডেট হওয়া প্যারামিটার মান আনুন। নিম্নলিখিত উদাহরণটি আপডেটের জন্য শুনে এবং যখনactivateWithCompletionHandler
বলা হয়, তখন একটি আপডেট হওয়া স্বাগত বার্তা প্রদর্শন করতে সদ্য আনা মানগুলি ব্যবহার করে।সুইফট
remoteConfig.addOnConfigUpdateListener { configUpdate, error in guard let configUpdate, error == nil else { print("Error listening for config updates: \(error)") } print("Updated keys: \(configUpdate.updatedKeys)") self.remoteConfig.activate { changed, error in guard error == nil else { return self.displayError(error) } DispatchQueue.main.async { self.displayWelcome() } } }
উদ্দেশ্য-C
__weak __typeof__(self) weakSelf = self; [self.remoteConfig addOnConfigUpdateListener:^(FIRRemoteConfigUpdate * _Nonnull configUpdate, NSError * _Nullable error) { if (error != nil) { NSLog(@"Error listening for config updates %@", error.localizedDescription); } else { NSLog(@"Updated keys: %@", configUpdate.updatedKeys); __typeof__(self) strongSelf = weakSelf; [strongSelf.remoteConfig activateWithCompletion:^(BOOL changed, NSError * _Nullable error) { if (error != nil) { NSLog(@"Activate error %@", error.localizedDescription); } dispatch_async(dispatch_get_main_queue(), ^{ [strongSelf displayWelcome]; }); }]; } }];
পরের বার আপনি যখন আপনার Remote Config একটি নতুন সংস্করণ প্রকাশ করবেন, এমন ডিভাইসগুলি যা আপনার অ্যাপ্লিকেশন চালাচ্ছে এবং পরিবর্তনের জন্য শোনাচ্ছে তা সম্পূর্ণ হ্যান্ডলারকে কল করবে।
থ্রটলিং
যদি কোনও অ্যাপ্লিকেশন স্বল্প সময়ের মধ্যে অনেকবার আগত হয় তবে আনার কলগুলি থ্রোটল করা হয় এবং এসডিকে FIRRemoteConfigFetchStatusThrottled
ফেরত দেয়। এসডিকে সংস্করণ 6.3.0 এর আগে, সীমাটি 60 মিনিটের উইন্ডোতে 5 টি অনুরোধ ছিল (নতুন সংস্করণগুলিতে আরও অনুমোদিত সীমা রয়েছে)।
অ্যাপ্লিকেশন বিকাশের সময়, আপনি আপনার অ্যাপ্লিকেশনটি বিকাশ করতে এবং পরীক্ষা করার সাথে সাথে আপনাকে দ্রুত পুনরাবৃত্তি করতে খুব ঘন ঘন (প্রতি ঘন্টা বহুবার) ক্যাশে রিফ্রেশ করতে আপনি আরও প্রায়শই আনতে চাইতে পারেন। রিয়েল-টাইম রিমোট কনফিগারেশন যখন কনফিগারেশনটি সার্ভারে আপডেট হয় তখন স্বয়ংক্রিয়ভাবে ক্যাশে বাইপাস করে। অসংখ্য বিকাশকারীদের সাথে একটি প্রকল্পে দ্রুত পুনরাবৃত্তির সমন্বয় করতে, আপনি আপনার অ্যাপ্লিকেশনটিতে কম ন্যূনতম ফেচ ইন্টারভাল ( MinimumFetchInterval
) সহ অস্থায়ীভাবে একটি FIRRemoteConfigSettings
সম্পত্তি যুক্ত করতে পারেন।
Remote Config জন্য ডিফল্ট এবং প্রস্তাবিত উত্পাদন আনার ব্যবধানটি 12 ঘন্টা, যার অর্থ 12 ঘন্টা উইন্ডোতে কনফিগারগুলি ব্যাকএন্ড থেকে একাধিকবার আনতে হবে না, যতগুলি ফেচ কল আসলে তৈরি করা হয় তা নির্বিশেষে। বিশেষত, ন্যূনতম আনার অন্তরটি এই নিম্নলিখিত ক্রমে নির্ধারিত হয়:
-
fetch(long)
-
FIRRemoteConfigSettings.MinimumFetchInterval
এর প্যারামিটার - 12 ঘন্টা ডিফল্ট মান
পরবর্তী পদক্ষেপ
যদি আপনি ইতিমধ্যে না থাকেন তবে Remote Config ব্যবহারের কেসগুলি অন্বেষণ করুন এবং কিছু মূল ধারণা এবং উন্নত কৌশল ডকুমেন্টেশন সহ একবার দেখুন:
,You can use Firebase Remote Config to define parameters in your app and update their values in the cloud, allowing you to modify the appearance and behavior of your app without distributing an app update. This guide walks you through the steps to get started and provides some sample code, all of which is available to clone or download from the firebase/quickstart-ios GitHub repository.
Step 1: Add Remote Config to your app
যদি আপনি ইতিমধ্যেই না করে থাকেন, তাহলে আপনার Apple প্রকল্পে Firebase যোগ করুন ।
For Remote Config , Google Analytics is required for the conditional targeting of app instances to user properties and audiences. Make sure that you enable Google Analytics in your project.
Create the singleton Remote Config object, as shown in the following example:
সুইফট
remoteConfig = RemoteConfig.remoteConfig() let settings = RemoteConfigSettings() settings.minimumFetchInterval = 0 remoteConfig.configSettings = settings
উদ্দেশ্য-C
self.remoteConfig = [FIRRemoteConfig remoteConfig]; FIRRemoteConfigSettings *remoteConfigSettings = [[FIRRemoteConfigSettings alloc] init]; remoteConfigSettings.minimumFetchInterval = 0; self.remoteConfig.configSettings = remoteConfigSettings;
This object is used to store in-app default parameter values, fetch updated parameter values from the Remote Config backend, and control when fetched values are made available to your app.
বিকাশের সময়, এটি একটি অপেক্ষাকৃত কম ন্যূনতম আনার ব্যবধান সেট করার পরামর্শ দেওয়া হয়। See Throttling for more information.
Step 2: Set in-app default parameter values
You can set in-app default parameter values in the Remote Config object, so that your app behaves as intended before it connects to the Remote Config backend, and so that default values are available if none are set in the backend.
Define a set of parameter names, and default parameter values using an
NSDictionary
object or a plist file .If you have already configured Remote Config backend parameter values, you can download a generated
plist
file that includes all default values and save it to your Xcode project.বিশ্রাম
curl --compressed -D headers -H "Authorization: Bearer token -X GET https://firebaseremoteconfig.googleapis.com/v1/projects/my-project-id/remoteConfig:downloadDefaults?format=PLIST -o RemoteConfigDefaults.plist
Firebase console
In the Parameters tab, open the Menu , and select Download default values .
When prompted, enable .plist for iOS , then click Download file .
Add these values to the Remote Config object using
setDefaults:
. The following example sets in-app default values from a plist file:সুইফট
remoteConfig.setDefaults(fromPlist: "RemoteConfigDefaults")
উদ্দেশ্য-C
[self.remoteConfig setDefaultsFromPlistFileName:@"RemoteConfigDefaults"];
Step 3: Get parameter values to use in your app
Now you can get parameter values from the Remote Config object. If you later set values in the Remote Config backend, fetch them, and then activate them, those values are available to your app. Otherwise, you get the in-app parameter values configured using setDefaults:
. To get these values, call the configValueForKey:
method, providing the parameter key as an argument.
let remoteConfig = RemoteConfig.remoteConfig()
// Retrieve a parameter value using configValueForKey
let welcomeMessageValue = remoteConfig.configValue(forKey: "welcome_message")
let welcomeMessage = welcomeMessageValue.stringValue
let featureFlagValue = remoteConfig.configValue(forKey: "new_feature_flag")
let isFeatureEnabled = featureFlagValue.boolValue
A more readable and convenient way to access these values in Swift is through Swift's subscript notation:
let remoteConfig = RemoteConfig.remoteConfig()
// Retrieve a string parameter value
let welcomeMessage = remoteConfig["welcome_message"].stringValue
// Retrieve a boolean parameter value
let isFeatureEnabled = remoteConfig["new_feature_flag"].boolValue
// Retrieve a number parameter value
let maxItemCount = remoteConfig["max_items"].numberValue.intValue
Use Codable for type-safe configuration
For more complex configurations, you can use Swift's Codable
protocol to decode structured data from Remote Config . This provides type-safe configuration management and simplifies working with complex objects.
// Define a Codable struct for your configuration
struct AppFeatureConfig: Codable {
let isNewFeatureEnabled: Bool
let maxUploadSize: Int
let themeColors: [String: String]
}
// Fetch and decode the configuration
func configureAppFeatures() {
let remoteConfig = RemoteConfig.remoteConfig()
remoteConfig.fetchAndActivate { status, error in
guard error == nil else { return }
do {
let featureConfig = try remoteConfig["app_feature_config"].decoded(asType: AppFeatureConfig.self)
configureApp(with: featureConfig)
} catch {
// Handle decoding errors
print("Failed to decode configuration: \(error)")
}
}
}
This method lets you:
- Define complex configuration structures.
- Automatically parse JSON configurations.
- Ensure type safety when accessing Remote Config values.
- Provide clean, readable code for handling structured Remote Config templates.
Use Property Wrappers for declarative configuration in SwiftUI
Property wrappers are a powerful Swift feature that lets you add custom behavior to property declarations. In SwiftUI, property wrappers are used to manage state, bindings, and other property behaviors. For more information, see the Swift Language Guide .
struct ContentView: View {
@RemoteConfigProperty(key: "cardColor", fallback: "#f05138")
var cardColor
var body: some View {
VStack {
Text("Dynamic Configuration")
.background(Color(hex: cardColor))
}
.onAppear {
RemoteConfig.remoteConfig().fetchAndActivate()
}
}
}
Use the @RemoteConfigProperty
property wrapper when you want a declarative way to access Remote Config values in SwiftUI, with built-in support for default values and simplified configuration management.
Step 4: Set parameter values
Using the Firebase console or the Remote Config backend APIs , you can create new backend default values that override the in-app values according to your desired conditional logic or user targeting. This section walks you through the Firebase console steps to create these values.
- Firebase কনসোলে , আপনার প্রকল্প খুলুন।
- Select Remote Config from the menu to view the Remote Config dashboard.
- Define parameters with the same names as the parameters that you defined in your app. For each parameter, you can set a default value (which will eventually override the in-app default value) and you can also set conditional values. To learn more, see Remote Config Parameters and Conditions .
If using custom signal conditions , define the attributes and their values. The following examples show how to define a custom signal condition.
সুইফট
Task { let customSignals: [String: CustomSignalValue?] = [ "city": .string("Tokyo"), "preferred_event_category": .string("sports") ] do { try await remoteConfig.setCustomSignals(customSignals) print("Custom signals set successfully!") } catch { print("Error setting custom signals: \(error)") } }
উদ্দেশ্য-C
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSDictionary *customSignals = @{ @"city": @"Tokyo", @"preferred_event_category": @"sports" }; [self.remoteConfig setCustomSignals:customSignals withCompletion:^(NSError * _Nullable error) { if (error) { NSLog(@"Error setting custom signals: %@", error); } else { NSLog(@"Custom signals set successfully!"); } }]; });
Step 5: Fetch and activate values
To fetch parameter values from Remote Config , call the fetchWithCompletionHandler:
or fetchWithExpirationDuration:completionHandler:
method. Any values that you set on the backend are fetched and cached in the Remote Config object.
For cases where you want to fetch and activate values in one call, use fetchAndActivateWithCompletionHandler:
.
This example fetches values from the Remote Config backend (not cached values) and calls activateWithCompletionHandler:
to make them available to the app:
সুইফট
remoteConfig.fetch { (status, error) -> Void in if status == .success { print("Config fetched!") self.remoteConfig.activate { changed, error in // ... } } else { print("Config not fetched") print("Error: \(error?.localizedDescription ?? "No error available.")") } self.displayWelcome() }
উদ্দেশ্য-C
[self.remoteConfig fetchWithCompletionHandler:^(FIRRemoteConfigFetchStatus status, NSError *error) { if (status == FIRRemoteConfigFetchStatusSuccess) { NSLog(@"Config fetched!"); [self.remoteConfig activateWithCompletion:^(BOOL changed, NSError * _Nullable error) { if (error != nil) { NSLog(@"Activate error: %@", error.localizedDescription); } else { dispatch_async(dispatch_get_main_queue(), ^{ [self displayWelcome]; }); } }]; } else { NSLog(@"Config not fetched"); NSLog(@"Error %@", error.localizedDescription); } }];
Because these updated parameter values affect the behavior and appearance of your app, you should activate the fetched values at a time that ensures a smooth experience for your user, such as the next time that the user opens your app. See Remote Config loading strategies for more information and examples.
Step 6: Listen for updates in real time
After you fetch parameter values, you can use real-time Remote Config to listen for updates from the Remote Config backend. Real-time Remote Config signals to connected devices when updates are available and automatically fetches the changes after you publish a new Remote Config version.
Real-time updates are supported by the Firebase SDK for Apple platforms v10.7.0+ and higher.
In your app, call
addOnConfigUpdateListener
to start listening for updates and automatically fetch any new or updated parameter values. The following example listens for updates and whenactivateWithCompletionHandler
is called, uses the newly fetched values to display an updated welcome message.সুইফট
remoteConfig.addOnConfigUpdateListener { configUpdate, error in guard let configUpdate, error == nil else { print("Error listening for config updates: \(error)") } print("Updated keys: \(configUpdate.updatedKeys)") self.remoteConfig.activate { changed, error in guard error == nil else { return self.displayError(error) } DispatchQueue.main.async { self.displayWelcome() } } }
উদ্দেশ্য-C
__weak __typeof__(self) weakSelf = self; [self.remoteConfig addOnConfigUpdateListener:^(FIRRemoteConfigUpdate * _Nonnull configUpdate, NSError * _Nullable error) { if (error != nil) { NSLog(@"Error listening for config updates %@", error.localizedDescription); } else { NSLog(@"Updated keys: %@", configUpdate.updatedKeys); __typeof__(self) strongSelf = weakSelf; [strongSelf.remoteConfig activateWithCompletion:^(BOOL changed, NSError * _Nullable error) { if (error != nil) { NSLog(@"Activate error %@", error.localizedDescription); } dispatch_async(dispatch_get_main_queue(), ^{ [strongSelf displayWelcome]; }); }]; } }];
The next time you publish a new version of your Remote Config , devices that are running your app and listening for changes will call the completion handler.
থ্রটলিং
If an app fetches too many times in a short time period, fetch calls are throttled and the SDK returns FIRRemoteConfigFetchStatusThrottled
. Before SDK version 6.3.0, the limit was 5 fetch requests in a 60 minute window (newer versions have more permissive limits).
During app development,you might want to fetch more often to refresh the cache very frequently (many times per hour) to let you rapidly iterate as you develop and test your app. Real-time Remote Config updates automatically bypass the cache when the config is updated on the server. To accommodate rapid iteration on a project with numerous developers, you can temporarily add a FIRRemoteConfigSettings
property with a low minimum fetch interval ( MinimumFetchInterval
) in your app.
The default and recommended production fetch interval for Remote Config is 12 hours, which means that configs won't be fetched from the backend more than once in a 12 hour window, regardless of how many fetch calls are actually made. Specifically, the minimum fetch interval is determined in this following order:
- The parameter in
fetch(long)
- The parameter in
FIRRemoteConfigSettings.MinimumFetchInterval
- The default value of 12 hours
পরবর্তী পদক্ষেপ
If you haven't already, explore the Remote Config use cases , and take a look at some of the key concepts and advanced strategies documentation, including: