Notice
Recent Posts
Recent Comments
Link
투케이2K
187. (Objective-C/objc) [간단 소스] Firebase RemoteConfig 파어베이스 리모트 컨피그 원격 알림 공지 확인 방법 본문
Objective-C
187. (Objective-C/objc) [간단 소스] Firebase RemoteConfig 파어베이스 리모트 컨피그 원격 알림 공지 확인 방법
투케이2K 2025. 2. 14. 11:19[개발 환경 설정]
개발 툴 : XCODE
개발 언어 : OBJECTIVE-C

[소스 코드]
// --------------------------------------------------------------------------------------
[개발 및 테스트 환경]
// --------------------------------------------------------------------------------------
- 언어 : Objective-c
- 개발 툴 : Xcode
- 기술 구분 : Firebase / RemoteConfig / 원격 알림
// --------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------
[사전) 필요 설정]
// --------------------------------------------------------------------------------------
1. Firebase SDK를 프로젝트에 추가한 후, GoogleService-Info.plist 파일을 추가해야 합니다
2. AppDelegate.m에서 Firebase를 초기화해야 합니다
>> [FIRApp configure];
// --------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------
[소스 코드]
// --------------------------------------------------------------------------------------
--------------------------------------------------
[Remote Config 초기화]
--------------------------------------------------
#import <FirebaseRemoteConfig/FirebaseRemoteConfig.h>
FIRRemoteConfig *remoteConfig; // [전역 변수 선언]
- (void)initializeRemoteConfig {
// FIRRemoteConfig 초기화
remoteConfig = [FIRRemoteConfig remoteConfig];
// 개발 환경에서는 짧은 Fetch 간격을 설정 (실시간 변경 상태 확인)
FIRRemoteConfigSettings *configSettings = [[FIRRemoteConfigSettings alloc] initWithMinimumFetchInterval:0];
remoteConfig.configSettings = configSettings;
// 기본값 설정 (앱이 처음 실행될 때 사용)
NSDictionary *defaultConfig = @{
@"welcome_message" : @"Firebase Remote Config 입니다.",
@"feature_enabled" : @NO
};
[remoteConfig setDefaults:defaultConfig];
NSLog(@">>>>>>>>>>>>>>>>> Remote Config 초기화 완료 >>>>>>>>>>>>>>>>>");
}
--------------------------------------------------
최신 설정 가져오기 (Fetch & Activate)
--------------------------------------------------
- (void)fetchRemoteConfig {
[remoteConfig fetchWithCompletionHandler:^(FIRRemoteConfigFetchStatus status, NSError * _Nullable error) {
if (status == FIRRemoteConfigFetchStatusSuccess) {
NSLog(@">>>>>>>>>>>>>>>>> Remote Config 가져오기 성공 >>>>>>>>>>>>>>>>>");
// 적용하기
[remoteConfig activateWithCompletion:^(BOOL changed, NSError * _Nullable error) {
if (changed) {
NSLog(@">>>>>>>>>>>>>>>>> Remote Config 업데이트 적용됨 >>>>>>>>>>>>>>>>>");
} else {
NSLog(@">>>>>>>>>>>>>>>>> Remote Config 변경 없음 >>>>>>>>>>>>>>>>>");
}
// 업데이트된 값을 가져오기
[self applyRemoteConfigValues];
}];
} else {
NSLog(@">>>>>>>>>>>>>>>>> Remote Config 가져오기 실패 : %@ >>>>>>>>>>>>>>>>>", error.localizedDescription);
}
}];
}
--------------------------------------------------
설정된 값 사용하기
--------------------------------------------------
NSString *welcomeMessage = self.remoteConfig[@"welcome_message"].stringValue;
BOOL featureEnabled = self.remoteConfig[@"feature_enabled"].boolValue;
NSLog(@">>>>>>>>>>>>>>>>> 환영 메시지 : %@ >>>>>>>>>>>>>>>>>", welcomeMessage);
NSLog(@">>>>>>>>>>>>>>>>> 기능 활성화 여부 : %d >>>>>>>>>>>>>>>>>", featureEnabled);
// --------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------
[참고 사이트]
// --------------------------------------------------------------------------------------
[C_FirebaseRemoteConfig - 파이어베이스 리모트 컨피그 원격 공지 확인 클래스]
https://blog.naver.com/kkh0977/223375315936
// --------------------------------------------------------------------------------------
반응형
'Objective-C' 카테고리의 다른 글
Comments