Ver2.0 ๐ React Native์์ ํธ์ ์๋ฆผ ๊ตฌํํ๊ธฐ: ์ฑ ์ฌ์ฉ์์์ ์ค์๊ฐ ์ํต ๋น๋ฒ ๐

๐ React Native์์ ํธ์ ์๋ฆผ ๊ตฌํํ๊ธฐ: ์ฑ ์ฌ์ฉ์์์ ์ค์๊ฐ ์ํต ๋น๋ฒ ๐
์๋ , ๊ฐ๋ฐ์ ์น๊ตฌ๋ค! ์ค๋์ ๋ชจ๋ฐ์ผ ์ฑ ๊ฐ๋ฐ์์ ๋นผ๋์ ์ ์๋ ํธ์ ์๋ฆผ ๊ตฌํ ๋ฐฉ๋ฒ์ ๋ํด ํจ๊ป ์์๋ณผ ๊ฑฐ์ผ. React Native๋ก ๊ฐ๋ฐํ๋ ์ฑ์ ํธ์ ์๋ฆผ์ ์ถ๊ฐํ๋ฉด ์ฌ์ฉ์ ์ฐธ์ฌ๋๋ฅผ ๋์ด๊ณ ์ฑ์ ๊ฐ์น๋ฅผ ํ์ธต ๋ ๋์ด์ฌ๋ฆด ์ ์์ด. ์ด ๊ธ์ ํตํด ํธ์ ์๋ฆผ์ A๋ถํฐ Z๊น์ง ์ฝ๊ณ ์ฌ๋ฏธ์๊ฒ ์์๋ณด์! ๐
๐ ๋ชฉ์ฐจ
- ํธ์ ์๋ฆผ์ด ๋ญ๊ธธ๋? ๊ธฐ๋ณธ ๊ฐ๋ ์ดํดํ๊ธฐ
- React Native ํธ์ ์๋ฆผ ๊ตฌํ์ ์ํ ์ค๋น๋ฌผ
- Firebase Cloud Messaging(FCM) ์ค์ ํ๊ธฐ
- iOS์์ ํธ์ ์๋ฆผ ๊ตฌํํ๊ธฐ
- Android์์ ํธ์ ์๋ฆผ ๊ตฌํํ๊ธฐ
- react-native-push-notification ๋ผ์ด๋ธ๋ฌ๋ฆฌ ํ์ฉํ๊ธฐ
- ํธ์ ์๋ฆผ ๋์์ธ๊ณผ ์ฌ์ฉ์ ๊ฒฝํ ์ต์ ํ
- ํธ์ ์๋ฆผ ํ ์คํธ ๋ฐ ๋๋ฒ๊น ๋ฐฉ๋ฒ
- ์ค์ ํ์ฉ ์ฌ๋ก์ ๋ฒ ์คํธ ํ๋ํฐ์ค
- ์์ฃผ ๋ฐ์ํ๋ ๋ฌธ์ ์ ํด๊ฒฐ ๋ฐฉ๋ฒ
1. ํธ์ ์๋ฆผ์ด ๋ญ๊ธธ๋? ๊ธฐ๋ณธ ๊ฐ๋ ์ดํดํ๊ธฐ ๐ค
ํธ์ ์๋ฆผ์ ์ฑ์ ์คํํ์ง ์์๋ ์ฌ์ฉ์์ ๊ธฐ๊ธฐ์ ๋ฉ์์ง๋ฅผ ๋ณด๋ผ ์ ์๋ ๊ฐ๋ ฅํ ์ปค๋ฎค๋์ผ์ด์ ๋๊ตฌ์ผ. ์๋ก์ด ๋ฉ์์ง๊ฐ ๋์ฐฉํ์ ๋, ํน๋ณ ํ ์ธ ์ด๋ฒคํธ๊ฐ ์์๋์ ๋, ๋๋ ์ค์ํ ์ ๋ฐ์ดํธ๊ฐ ์์ ๋ ์ฌ์ฉ์์๊ฒ ์ฆ์ ์๋ ค์ค ์ ์์ง. ๋ง์น ์น๊ตฌ๊ฐ "์ผ, ์ด๊ฑฐ ๋ด๋ด!"๋ผ๊ณ ์ด๊นจ๋ฅผ ํญ ์น๋ ๊ฒ๊ณผ ๊ฐ์ ๋๋์ด๋๊น? ๐
ํธ์ ์๋ฆผ์ ์ข ๋ฅ
- ๋ก์ปฌ ํธ์ ์๋ฆผ: ์ฑ ๋ด์์ ์์ฑ๋์ด ๊ธฐ๊ธฐ ์์ฒด์์ ์ค์ผ์ค๋ง๋๋ ์๋ฆผ์ด์ผ. ์๋ฅผ ๋ค๋ฉด, ์๋ ์ฑ์์ ์ค์ ํ ์๊ฐ์ด ๋๋ฉด ์ธ๋ฆฌ๋ ์๋ฆผ์ด ๋ฐ๋ก ์ด๊ฑฐ์ง.
- ์๊ฒฉ ํธ์ ์๋ฆผ: ์๋ฒ์์ ๋ณด๋ด๋ ์๋ฆผ์ผ๋ก, ์ฑ์ด ์คํ ์ค์ด์ง ์์๋ ๋ฐ์ ์ ์์ด. ์ ๋ฉ์์ง ์๋ฆผ์ด๋ ๋ด์ค ์๋ณด ๊ฐ์ ๊ฒ๋ค์ด ์ฌ๊ธฐ์ ํด๋น๋ผ.
- ์ฌ์ผ๋ฐํธ ํธ์ ์๋ฆผ: ์ฌ์ฉ์์๊ฒ ๋ณด์ด์ง ์์ง๋ง ์ฑ์ ๊นจ์์ ๋ฐฑ๊ทธ๋ผ์ด๋ ์์ ์ ์ํํ๊ฒ ํ๋ ์๋ฆผ์ด์ผ. ๋ฐ์ดํฐ ๋๊ธฐํ ๊ฐ์ ์์ ์ ์ ์ฉํ์ง.
ํธ์ ์๋ฆผ์ ํต์ฌ ์ฅ์ ์ ์ฌ์ฉ์ ์ฐธ์ฌ๋๋ฅผ ๋์ด๊ณ ์ฑ์ ํ์ฑ ์ฌ์ฉ์ ์๋ฅผ ์ ์งํ๋ ๋ฐ ์์ด. ํนํ ์์ฆ์ฒ๋ผ ์ฑ์ด ๋์ณ๋๋ ์๋์ ์ฌ์ฉ์์ ๊ด์ฌ์ ๋ค์ ๋์ด์ค๋ ๊ฑด ์ ๋ง ์ค์ํ์ง. ์ฌ๋ฅ๋ท ๊ฐ์ ํ๋ซํผ์์๋ ์๋ก์ด ์ฌ๋ฅ์ด ๋ฑ๋ก๋๊ฑฐ๋ ๋ฉ์์ง๊ฐ ์์ ๋ ํธ์ ์๋ฆผ์ผ๋ก ์๋ ค์ฃผ๋ฉด ์ฌ์ฉ์ ๊ฒฝํ์ด ํจ์ฌ ์ข์์ง๋ค๋ ๊ฑธ ์ ์ ์์ด.
๐ ํธ์ ์๋ฆผ ํจ๊ณผ ํต๊ณ
โ ์ ์ ํ ํธ์ ์๋ฆผ์ ๋ฐ์ ์ฌ์ฉ์๋ ์ฑ ์ฐธ์ฌ์จ์ด ์ต๋ 88% ์ฆ๊ฐํด.
โ ๊ฐ์ธํ๋ ํธ์ ์๋ฆผ์ ์ผ๋ฐ ์๋ฆผ๋ณด๋ค ํด๋ฆญ๋ฅ ์ด 4๋ฐฐ ๋์.
โ ํ์ง๋ง ๊ณผ๋ํ ์๋ฆผ์ ์ฑ ์ญ์ ์ ์ฃผ์ ์์ธ ์ค ํ๋์ด๊ธฐ๋ ํด.
2. React Native ํธ์ ์๋ฆผ ๊ตฌํ์ ์ํ ์ค๋น๋ฌผ ๐งฐ
์, ์ด์ ๋ณธ๊ฒฉ์ ์ผ๋ก React Native์์ ํธ์ ์๋ฆผ์ ๊ตฌํํ๊ธฐ ์ํ ์ค๋น๋ฌผ์ ์์๋ณด์! ๋ง์น ์๋ฆฌ๋ฅผ ์์ํ๊ธฐ ์ ์ ์ฌ๋ฃ๋ฅผ ์ค๋นํ๋ ๊ฒ์ฒ๋ผ, ํธ์ ์๋ฆผ ๊ตฌํ๋ ๋ช ๊ฐ์ง ํ์ ๋๊ตฌ์ ์ค์ ์ด ํ์ํด. ๐ณ
ํ์ ์ค๋น๋ฌผ
- React Native ํ๋ก์ ํธ: ๋น์ฐํ React Native๋ก ๋ง๋ ์ฑ ํ๋ก์ ํธ๊ฐ ํ์ํ๊ฒ ์ง? ์์ง ์๋ค๋ฉด
npx react-native init MyPushApp์ผ๋ก ์ ํ๋ก์ ํธ๋ฅผ ๋ง๋ค์ด๋ณด์. - ํธ์ ์๋ฆผ ์๋น์ค: Firebase Cloud Messaging(FCM)์ด ๊ฐ์ฅ ๋๋ฆฌ ์ฌ์ฉ๋ผ. iOS์ Android ๋ชจ๋ ์ง์ํ๊ธฐ ๋๋ฌธ์ ํฌ๋ก์ค ํ๋ซํผ ์ฑ์ ๋ฑ์ด์ผ!
- iOS ๊ฐ๋ฐ์ ๊ณ์ : iOS ํธ์ ์๋ฆผ์ ํ ์คํธํ๋ ค๋ฉด Apple Developer Program ๋ฉค๋ฒ์ญ($99/๋ )์ด ํ์ํด.
- ์ธ์ฆ์์ ํค: iOS์ ๊ฒฝ์ฐ ํธ์ ์๋ฆผ ์ธ์ฆ์, Android๋ Firebase ํ๋ก์ ํธ์ ์๋ฒ ํค๊ฐ ํ์ํด.
- ํธ์ ์๋ฆผ ๋ผ์ด๋ธ๋ฌ๋ฆฌ:
react-native-push-notification์ด๋@react-native-firebase/messaging๊ฐ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ๋ฉด ๊ตฌํ์ด ํจ์ฌ ์ฌ์์ ธ.
๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค์นํ๊ธฐ
๊ฐ์ฅ ๋ง์ด ์ฌ์ฉ๋๋ ๋ ๊ฐ์ง ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์๊ฐํ ๊ฒ:
1. react-native-push-notification
npm install --save react-native-push-notification
# ๋๋
yarn add react-native-push-notification
# iOS์ ๊ฒฝ์ฐ ์ถ๊ฐ ์ค์น ํ์
cd ios && pod install
2. @react-native-firebase/messaging
npm install --save @react-native-firebase/app @react-native-firebase/messaging
# ๋๋
yarn add @react-native-firebase/app @react-native-firebase/messaging
# iOS์ ๊ฒฝ์ฐ ์ถ๊ฐ ์ค์น ํ์
cd ios && pod install
๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค ์ด๋ค ๊ฑธ ์ ํํด์ผ ํ ์ง ๊ณ ๋ฏผ๋๋ค๋ฉด, Firebase ์ํ๊ณ๋ฅผ ๋ ๋ง์ด ํ์ฉํ ๊ณํ์ด๋ผ๋ฉด @react-native-firebase/messaging์, ๋ ๊ฐ๋จํ ์ค์ ๊ณผ ๋ก์ปฌ ์๋ฆผ ๊ธฐ๋ฅ์ด ํ์ํ๋ค๋ฉด react-native-push-notification์ ์ถ์ฒํด. ์ด ๊ธ์์๋ ๋ ๊ฐ์ง ๋ฐฉ๋ฒ ๋ชจ๋ ๋ค๋ฃฐ ๊ฑฐ๋๊น ๊ฑฑ์ ํ์ง ๋ง! ๐
๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋น๊ต
| ๊ธฐ๋ฅ | react-native-push-notification | @react-native-firebase/messaging |
|---|---|---|
| ์ค์น ๋์ด๋ | โญโญโญ (์ค๊ฐ) | โญโญโญโญ (์ฝ๊ฐ ๋ณต์ก) |
| ๋ก์ปฌ ์๋ฆผ | โ ์ง์ | โ ๋ณ๋ ์ค์ ํ์ |
| ์๊ฒฉ ์๋ฆผ | โ ์ง์ | โ ์ง์ |
| Firebase ํตํฉ | โญโญ (๊ธฐ๋ณธ) | โญโญโญโญโญ (์๋ฒฝ) |
| ์ปค์คํฐ๋ง์ด์ง | โญโญโญโญ (๋ค์ํ ์ต์ ) | โญโญโญ (Firebase ๋ฐฉ์) |
| ๋ฌธ์ํ | โญโญโญ (์ ์ ํจ) | โญโญโญโญ (์์ธํจ) |
์ด์ ํ์ํ ๋๊ตฌ๋ค์ ์์์ผ๋, ๋ค์ ๋จ๊ณ๋ก ๋์ด๊ฐ์ Firebase Cloud Messaging์ ์ค์ ํด๋ณด์! ๐ฅ
3. Firebase Cloud Messaging(FCM) ์ค์ ํ๊ธฐ ๐ฅ
Firebase Cloud Messaging(FCM)์ ๊ตฌ๊ธ์์ ์ ๊ณตํ๋ ๋ฌด๋ฃ ํฌ๋ก์ค ํ๋ซํผ ๋ฉ์์ง ์๋ฃจ์ ์ด์ผ. iOS์ Android ๋ชจ๋ ์ง์ํ๊ธฐ ๋๋ฌธ์ React Native ์ฑ์์ ํธ์ ์๋ฆผ์ ๊ตฌํํ ๋ ๊ฐ์ฅ ๋ง์ด ์ฌ์ฉ๋ผ. ๋ง์น ์ฐ์ฒด๋ถ์ฒ๋ผ ์ฐ๋ฆฌ ์ฑ์ ๋ฉ์์ง๋ฅผ ์ฌ์ฉ์์๊ฒ ์์ ํ๊ฒ ์ ๋ฌํด์ฃผ๋ ์ญํ ์ ํ๋ค๊ณ ์๊ฐํ๋ฉด ๋ผ! ๐ฎ
Firebase ํ๋ก์ ํธ ์ค์ ๋จ๊ณ
-
Firebase ์ฝ์ ์ ์ํ๊ธฐ
๋จผ์ Firebase ์ฝ์์ ์ ์ํด์ Google ๊ณ์ ์ผ๋ก ๋ก๊ทธ์ธํด. ์์ง ๊ณ์ ์ด ์๋ค๋ฉด ๋ง๋ค์ด์ผ ํด.
-
์ ํ๋ก์ ํธ ๋ง๋ค๊ธฐ
"ํ๋ก์ ํธ ์ถ๊ฐ" ๋ฒํผ์ ํด๋ฆญํ๊ณ ํ๋ก์ ํธ ์ด๋ฆ์ ์ ๋ ฅํด. ์๋ฅผ ๋ค๋ฉด "MyPushApp"์ด๋ผ๊ณ ์ง์ ์ ์์ด. ๊ทธ๋ฆฌ๊ณ ์ฝ๊ด์ ๋์ํ๊ณ "๊ณ์" ๋ฒํผ์ ํด๋ฆญํด.
-
Google ์ ๋๋ฆฌํฑ์ค ์ค์
Google ์ ๋๋ฆฌํฑ์ค๋ฅผ ์ฌ์ฉํ ์ง ์ ํํด. ํธ์ ์๋ฆผ ์ฑ๊ณผ๋ฅผ ์ธก์ ํ๊ณ ์ถ๋ค๋ฉด ํ์ฑํํ๋ ๊ฒ์ด ์ข์. ์ค์ ์ ๋ง์น๊ณ "ํ๋ก์ ํธ ๋ง๋ค๊ธฐ" ๋ฒํผ์ ํด๋ฆญํด.
-
Android ์ฑ ๋ฑ๋กํ๊ธฐ
ํ๋ก์ ํธ๊ฐ ์์ฑ๋๋ฉด Android ์ฑ์ ์ถ๊ฐํด์ผ ํด. "Android" ์์ด์ฝ์ ํด๋ฆญํ๊ณ ํจํค์ง ์ด๋ฆ(์: com.mypushapp)์ ์ ๋ ฅํด. ์ด ํจํค์ง ์ด๋ฆ์
android/app/build.gradleํ์ผ์ applicationId์ ์ผ์นํด์ผ ํด. -
google-services.json ๋ค์ด๋ก๋
์ฑ ๋ฑ๋ก์ด ์๋ฃ๋๋ฉด google-services.json ํ์ผ์ ๋ค์ด๋ก๋ ๋ฐ์ ์ ์์ด. ์ด ํ์ผ์
android/app/๋๋ ํ ๋ฆฌ์ ๋ฃ์ด์ค. -
iOS ์ฑ ๋ฑ๋กํ๊ธฐ
iOS ์ฑ๋ ์ง์ํ๋ ค๋ฉด "iOS" ์์ด์ฝ์ ํด๋ฆญํ๊ณ Bundle ID(์: org.reactjs.native.example.MyPushApp)๋ฅผ ์ ๋ ฅํด. ์ด ID๋ Xcode ํ๋ก์ ํธ ์ค์ ์ Bundle Identifier์ ์ผ์นํด์ผ ํด.
-
GoogleService-Info.plist ๋ค์ด๋ก๋
iOS ์ฑ ๋ฑ๋ก์ด ์๋ฃ๋๋ฉด GoogleService-Info.plist ํ์ผ์ ๋ค์ด๋ก๋ ๋ฐ์ ์ ์์ด. ์ด ํ์ผ์ Xcode ํ๋ก์ ํธ์ ์ถ๊ฐํด์ผ ํด. Xcode๋ฅผ ์ด๊ณ ํ์ผ์ ๋๋๊ทธ ์ค ๋๋กญํ๋ฉด ๋ผ.
Android ํ๋ก์ ํธ ์ค์
Firebase์์ ๋ค์ด๋ก๋ํ google-services.json ํ์ผ์ ํ๋ก์ ํธ์ ์ถ๊ฐํ ํ, ๋ค์ ์ค์ ์ ํด์ค์ผ ํด:
-
ํ๋ก์ ํธ ์์ค build.gradle ์์
// android/build.gradle buildscript { dependencies { // ... ๊ธฐ์กด ์์กด์ฑ classpath 'com.google.gms:google-services:4.3.10' // Google Services ํ๋ฌ๊ทธ์ธ } } -
์ฑ ์์ค build.gradle ์์
// android/app/build.gradle apply plugin: 'com.android.application' apply plugin: 'com.google.gms.google-services' // Google Services ํ๋ฌ๊ทธ์ธ ์ ์ฉ dependencies { // ... ๊ธฐ์กด ์์กด์ฑ implementation 'com.google.firebase:firebase-messaging:23.0.0' // FCM ์์กด์ฑ ์ถ๊ฐ }
iOS ํ๋ก์ ํธ ์ค์
iOS์ ๊ฒฝ์ฐ ๋ช ๊ฐ์ง ์ถ๊ฐ ์ค์ ์ด ํ์ํด:
-
Podfile ์์
// ios/Podfile target 'MyPushApp' do # ... pod 'Firebase/Core' pod 'Firebase/Messaging' end -
AppDelegate.m ์์
#import <UserNotifications/UserNotifications.h> #import <Firebase.h> @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // ... [FIRApp configure]; // Firebase ์ด๊ธฐํ // ํธ์ ์๋ฆผ ๊ถํ ์์ฒญ if ([UNUserNotificationCenter class] != nil) { UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; center.delegate = self; [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error) { }]; } [application registerForRemoteNotifications]; return YES; } -
Capabilities ์ค์
Xcode์์ ํ๋ก์ ํธ ์ค์ > Signing & Capabilities ํญ์ผ๋ก ์ด๋ํด์ "+" ๋ฒํผ์ ํด๋ฆญํ๊ณ "Push Notifications"์ "Background Modes"๋ฅผ ์ถ๊ฐํด. Background Modes์์๋ "Remote notifications"๋ฅผ ์ฒดํฌํด์ค.
์ฌ๊ธฐ๊น์ง Firebase ์ค์ ์ด ์๋ฃ๋์ด! ์ด์ FCM์ ํตํด ํธ์ ์๋ฆผ์ ๋ณด๋ด๊ณ ๋ฐ์ ์ค๋น๊ฐ ๋ ๊ฑฐ์ผ. ๋ค์ ๋จ๊ณ์์๋ iOS์ Android์์ ๊ฐ๊ฐ ํธ์ ์๋ฆผ์ ๊ตฌํํ๋ ๋ฐฉ๋ฒ์ ์์ธํ ์์๋ณผ๊ฒ. ๐
4. iOS์์ ํธ์ ์๋ฆผ ๊ตฌํํ๊ธฐ ๐
iOS์์ ํธ์ ์๋ฆผ์ ๊ตฌํํ๋ ๊ฑด Android๋ณด๋ค ์กฐ๊ธ ๋ ๊น๋ค๋ก์ธ ์ ์์ด. Apple์ ์๊ฒฉํ ๋ณด์ ์ ์ฑ ๋๋ฌธ์ด์ง. ํ์ง๋ง ์ฐจ๊ทผ์ฐจ๊ทผ ๋ฐ๋ผ์ค๋ฉด ์ด๋ ต์ง ์์! ๋ง์น ์ ํ ํ์ด๋ฅผ ๋ง๋๋ ๊ฒ์ฒ๋ผ ์ ํํ ๋ ์ํผ๋ง ๋ฐ๋ฅด๋ฉด ๋ผ. ๐ฅง
iOS ํธ์ ์๋ฆผ ๊ตฌํ ์ ํ์ ์์
- Apple Developer Program ๋ฉค๋ฒ์ญ: iOS ํธ์ ์๋ฆผ์ ํ ์คํธํ๋ ค๋ฉด ๋ฐ๋์ ํ์ํด ($99/๋ ).
- ์ค์ iOS ๊ธฐ๊ธฐ: ์๋ฎฌ๋ ์ดํฐ์์๋ ํธ์ ์๋ฆผ์ ํ ์คํธํ ์ ์์ด. ์ค์ iPhone์ด๋ iPad๊ฐ ํ์ํด.
- APNs ์ธ์ฆ์: Apple Push Notification service ์ธ์ฆ์๋ฅผ ๋ฐ๊ธ๋ฐ์์ผ ํด.
APNs ์ธ์ฆ์ ๋ฐ๊ธ ๋ฐฉ๋ฒ
-
Apple Developer ๊ณ์ ๋ก๊ทธ์ธ
Apple Developer ์ฌ์ดํธ์ ๋ก๊ทธ์ธํด.
-
์ธ์ฆ์ ์์ฑ
Certificates, Identifiers & Profiles > Certificates > "+" ๋ฒํผ ํด๋ฆญ > Apple Push Notification service SSL (Sandbox & Production) ์ ํ.
-
App ID ์ ํ
์ธ์ฆ์๋ฅผ ์์ฑํ App ID๋ฅผ ์ ํํด. ์ด App ID๋ ์ฑ์ Bundle Identifier์ ์ผ์นํด์ผ ํด.
-
CSR ํ์ผ ์
๋ก๋
Certificate Signing Request(CSR) ํ์ผ์ด ํ์ํด. Mac์ ํค์ฒด์ธ ์ ๊ทผ์์ "์ธ์ฆ์ ์ง์ > ์ธ์ฆ ๊ธฐ๊ด์์ ์ธ์ฆ์ ์์ฒญ" ๋ฉ๋ด๋ฅผ ํตํด ์์ฑํ ์ ์์ด.
-
์ธ์ฆ์ ๋ค์ด๋ก๋ ๋ฐ ์ค์น
์์ฑ๋ ์ธ์ฆ์๋ฅผ ๋ค์ด๋ก๋ํ๊ณ ๋๋ธํด๋ฆญํด์ ํค์ฒด์ธ์ ์ค์นํด.
-
p12 ํ์ผ ๋ด๋ณด๋ด๊ธฐ
ํค์ฒด์ธ์์ ์ค์น๋ ์ธ์ฆ์๋ฅผ ์ฐพ์ ์ฐํด๋ฆญ > "๋ด๋ณด๋ด๊ธฐ"๋ฅผ ์ ํํด p12 ํ์์ผ๋ก ์ ์ฅํด. ์ด ํ์ผ์ Firebase ์ฝ์์์ ์ฌ์ฉํ ๊ฑฐ์ผ.
Firebase์ APNs ์ธ์ฆ์ ์ ๋ก๋
- Firebase ์ฝ์์์ ํ๋ก์ ํธ ์ค์ ์ผ๋ก ์ด๋ํด.
- "Cloud Messaging" ํญ์ ์ ํํด.
- iOS ์ฑ ๊ตฌ์ฑ ์น์ ์์ "APNs ์ธ์ฆ์ ์ ๋ก๋" ๋ฒํผ์ ํด๋ฆญํด.
- ์์ ๋ด๋ณด๋ธ p12 ํ์ผ๊ณผ ๋น๋ฐ๋ฒํธ๋ฅผ ์ ๋ ฅํ๊ณ ์ ๋ก๋ํด.
React Native ์ฝ๋ ๊ตฌํ
์ด์ React Native ์ฝ๋์์ ํธ์ ์๋ฆผ์ ์ฒ๋ฆฌํ๋ ๋ฐฉ๋ฒ์ ์์๋ณด์. ์ฌ๊ธฐ์๋ @react-native-firebase/messaging ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ ๊ฒ:
import React, { useEffect } from 'react';
import { Alert, Platform } from 'react-native';
import messaging from '@react-native-firebase/messaging';
function App() {
// FCM ํ ํฐ ์์ฒญ ๋ฐ ์ ์ฅ
async function requestUserPermission() {
const authStatus = await messaging().requestPermission();
const enabled =
authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
authStatus === messaging.AuthorizationStatus.PROVISIONAL;
if (enabled) {
console.log('Authorization status:', authStatus);
getFcmToken();
}
}
// FCM ํ ํฐ ๊ฐ์ ธ์ค๊ธฐ
const getFcmToken = async () => {
const fcmToken = await messaging().getToken();
if (fcmToken) {
console.log('Your Firebase Token is:', fcmToken);
// ์ฌ๊ธฐ์ ํ ํฐ์ ์๋ฒ์ ์ ์ฅํ๋ API ํธ์ถ
} else {
console.log('Failed to get FCM token');
}
};
useEffect(() => {
// iOS์์๋ง ๊ถํ ์์ฒญ์ด ํ์ํจ
if (Platform.OS === 'ios') {
requestUserPermission();
} else {
getFcmToken();
}
// ํฌ๊ทธ๋ผ์ด๋ ์ํ์์ ๋ฉ์์ง ์์
const unsubscribe = messaging().onMessage(async remoteMessage => {
Alert.alert('์ ์๋ฆผ!', JSON.stringify(remoteMessage));
});
// ๋ฐฑ๊ทธ๋ผ์ด๋์์ ์ฑ์ด ์ด๋ ธ์ ๋
messaging().onNotificationOpenedApp(remoteMessage => {
console.log(
'Notification caused app to open from background state:',
remoteMessage,
);
// ์ฌ๊ธฐ์ ํน์ ํ๋ฉด์ผ๋ก ๋ค๋น๊ฒ์ด์
์ฒ๋ฆฌ
});
// ์ฑ์ด ์ข
๋ฃ๋ ์ํ์์ ์ด๋ ธ์ ๋
messaging()
.getInitialNotification()
.then(remoteMessage => {
if (remoteMessage) {
console.log(
'Notification caused app to open from quit state:',
remoteMessage,
);
// ์ฌ๊ธฐ์ ํน์ ํ๋ฉด์ผ๋ก ๋ค๋น๊ฒ์ด์
์ฒ๋ฆฌ
}
});
return unsubscribe;
}, []);
return (
// ์ฑ ์ปดํฌ๋ํธ
);
}
iOS ์๋ฆผ ์นดํ ๊ณ ๋ฆฌ ์ค์ ํ๊ธฐ
iOS์์๋ ์๋ฆผ ์นดํ ๊ณ ๋ฆฌ๋ฅผ ์ค์ ํด ์ฌ์ฉ์๊ฐ ์๋ฆผ์์ ๋ฐ๋ก ์ก์ ์ ์ทจํ ์ ์๊ฒ ํ ์ ์์ด. ์๋ฅผ ๋ค์ด, ๋ฉ์์ง ์๋ฆผ์์ "๋ต์ฅ" ๋ฒํผ์ ๋๋ฅด๋ฉด ๋ฐ๋ก ๋ต์ฅ ํ๋ฉด์ด ๋จ๋ ์์ด์ง.
// AppDelegate.m์ ์ถ๊ฐ
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
// ์นดํ
๊ณ ๋ฆฌ ์ค์
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
// "์ฑํ
" ์นดํ
๊ณ ๋ฆฌ ์์ฑ
UNNotificationAction *replyAction = [UNNotificationAction actionWithIdentifier:@"REPLY_ACTION"
title:@"๋ต์ฅ"
options:UNNotificationActionOptionForeground];
UNNotificationCategory *chatCategory = [UNNotificationCategory categoryWithIdentifier:@"CHAT_CATEGORY"
actions:@[replyAction]
intentIdentifiers:@[]
options:UNNotificationCategoryOptionNone];
[center setNotificationCategories:[NSSet setWithObjects:chatCategory, nil]];
}
iOS์์ ํธ์ ์๋ฆผ์ ๊ตฌํํ ๋ ๊ฐ์ฅ ์ค์ํ ๊ฒ์ ์ฌ์ฉ์ ๊ฒฝํ์ด์ผ. ๋๋ฌด ๋ง์ ์๋ฆผ์ ๋ณด๋ด๋ฉด ์ฌ์ฉ์๊ฐ ์๋ฆผ์ ๋ ์ ์์ผ๋ ์ ์ ํ ํ์ด๋ฐ์ ์ ์ฉํ ์ ๋ณด๋ฅผ ๋ด์ ์๋ฆผ์ ๋ณด๋ด๋ ๊ฒ ์ค์ํด. ์ฌ๋ฅ๋ท ๊ฐ์ ์๋น์ค์์๋ ์๋ก์ด ๋ฉ์์ง๋ ๊ฑฐ๋ ์ ์์ด ์์ ๋ ์๋ฆผ์ ๋ณด๋ด๋ฉด ์ฌ์ฉ์ ์ฐธ์ฌ๋๋ฅผ ๋์ผ ์ ์์ ๊ฑฐ์ผ! ๐ฑ
5. Android์์ ํธ์ ์๋ฆผ ๊ตฌํํ๊ธฐ ๐ค
Android์์ ํธ์ ์๋ฆผ์ ๊ตฌํํ๋ ๊ฑด iOS๋ณด๋ค ๋น๊ต์ ๊ฐ๋จํด. Google Play ์๋น์ค๊ฐ ๊ธฐ๋ณธ์ ์ผ๋ก ์ค์น๋ ๋๋ถ๋ถ์ Android ๊ธฐ๊ธฐ์์๋ ๋ณ๋์ ์ธ์ฆ์ ์์ด๋ FCM์ ํตํด ํธ์ ์๋ฆผ์ ๋ณด๋ผ ์ ์๊ฑฐ๋ . ๋ง์น ์๋๋ก์ด๋ ๋ง์ค์ฝํธ์ฒ๋ผ ์น์ ํ๊ฒ ๋์์ฃผ๋ ๋๋์ด๋๊น? ๐ค
AndroidManifest.xml ์ค์
Android์์ ํธ์ ์๋ฆผ์ ๋ฐ์ผ๋ ค๋ฉด ๋จผ์ ๋งค๋ํ์คํธ ํ์ผ์ ํ์ํ ๊ถํ์ ์ถ๊ฐํด์ผ ํด:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mypushapp">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:name=".MainApplication"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- FCM ์๋น์ค ์ถ๊ฐ -->
<service
android:name=".MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>
</manifest>
Firebase Messaging Service ๊ตฌํ
๋ค์์ผ๋ก, FCM ๋ฉ์์ง๋ฅผ ์ฒ๋ฆฌํ ์๋น์ค ํด๋์ค๋ฅผ ๋ง๋ค์ด์ผ ํด:
// android/app/src/main/java/com/mypushapp/MyFirebaseMessagingService.java
package com.mypushapp;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import androidx.core.app.NotificationCompat;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// ๋ฐ์ดํฐ ํ์ด๋ก๋๊ฐ ์๋ ๊ฒฝ์ฐ
if (remoteMessage.getData().size() > 0) {
// ์ฌ๊ธฐ์ ๋ฐ์ดํฐ๋ฅผ ์ฒ๋ฆฌ
sendNotification(remoteMessage.getData().get("title"),
remoteMessage.getData().get("body"));
}
// ์๋ฆผ ํ์ด๋ก๋๊ฐ ์๋ ๊ฒฝ์ฐ
if (remoteMessage.getNotification() != null) {
sendNotification(remoteMessage.getNotification().getTitle(),
remoteMessage.getNotification().getBody());
}
}
@Override
public void onNewToken(String token) {
// ์ ํ ํฐ์ด ์์ฑ๋ ๋๋ง๋ค ์๋ฒ์ ํ ํฐ์ ๋ณด๋ด ์ ์ฅ
sendRegistrationToServer(token);
}
private void sendRegistrationToServer(String token) {
// ์ฌ๊ธฐ์ ํ ํฐ์ ์๋ฒ์ ์ ์กํ๋ ๋ก์ง ๊ตฌํ
}
private void sendNotification(String title, String messageBody) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
String channelId = "fcm_default_channel";
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(title)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Android Oreo ์ด์์์๋ ์ฑ๋ ์์ฑ์ด ํ์
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(channelId,
"Channel human readable title",
NotificationManager.IMPORTANCE_DEFAULT);
notificationManager.createNotificationChannel(channel);
}
notificationManager.notify(0, notificationBuilder.build());
}
}
React Native์์ Android ํธ์ ์๋ฆผ ์ฒ๋ฆฌ
์ด์ React Native ์ฝ๋์์ Android ํธ์ ์๋ฆผ์ ์ฒ๋ฆฌํ๋ ๋ฐฉ๋ฒ์ ์์๋ณด์:
import React, { useEffect } from 'react';
import { Platform } from 'react-native';
import messaging from '@react-native-firebase/messaging';
function App() {
// FCM ํ ํฐ ๊ฐ์ ธ์ค๊ธฐ
const getFcmToken = async () => {
const fcmToken = await messaging().getToken();
if (fcmToken) {
console.log('Your Firebase Token is:', fcmToken);
// ์ฌ๊ธฐ์ ํ ํฐ์ ์๋ฒ์ ์ ์ฅํ๋ API ํธ์ถ
} else {
console.log('Failed to get FCM token');
}
};
useEffect(() => {
getFcmToken();
// ํ ํฐ ๊ฐฑ์ ๋ฆฌ์ค๋
const unsubscribe = messaging().onTokenRefresh(token => {
console.log('FCM ํ ํฐ์ด ๊ฐฑ์ ๋์์ต๋๋ค:', token);
// ์ฌ๊ธฐ์ ์ ํ ํฐ์ ์๋ฒ์ ์ ์ฅ
});
// ํฌ๊ทธ๋ผ์ด๋ ๋ฉ์์ง ์ฒ๋ฆฌ
const messageUnsubscribe = messaging().onMessage(async remoteMessage => {
console.log('ํฌ๊ทธ๋ผ์ด๋ ๋ฉ์์ง:', remoteMessage);
// ์ฌ๊ธฐ์ ์ปค์คํ
์๋ฆผ ํ์ ๋ก์ง ๊ตฌํ
});
// ๋ฐฑ๊ทธ๋ผ์ด๋์์ ์ฑ์ด ์ด๋ ธ์ ๋
messaging().onNotificationOpenedApp(remoteMessage => {
console.log('๋ฐฑ๊ทธ๋ผ์ด๋์์ ์๋ฆผ ํด๋ฆญ:', remoteMessage);
// ์ฌ๊ธฐ์ ํน์ ํ๋ฉด์ผ๋ก ๋ค๋น๊ฒ์ด์
});
// ์ฑ์ด ์ข
๋ฃ๋ ์ํ์์ ์๋ฆผ์ผ๋ก ์ด๋ ธ์ ๋
messaging()
.getInitialNotification()
.then(remoteMessage => {
if (remoteMessage) {
console.log('์ข
๋ฃ ์ํ์์ ์๋ฆผ ํด๋ฆญ:', remoteMessage);
// ์ฌ๊ธฐ์ ํน์ ํ๋ฉด์ผ๋ก ๋ค๋น๊ฒ์ด์
}
});
return () => {
unsubscribe();
messageUnsubscribe();
};
}, []);
return (
// ์ฑ ์ปดํฌ๋ํธ
);
}
Android ์๋ฆผ ์ฑ๋ ์ค์ ํ๊ธฐ
Android 8.0(Oreo) ์ด์์์๋ ์๋ฆผ ์ฑ๋์ ์ค์ ํด์ผ ํด. ์ฑ๋์ ํตํด ์ฌ์ฉ์๋ ํน์ ์ ํ์ ์๋ฆผ๋ง ์ ํ์ ์ผ๋ก ๋ฐ์ ์ ์์ด.
// ์๋ฆผ ์ฑ๋ ์์ฑ ํจ์
import { Platform } from 'react-native';
import notifee, { AndroidImportance } from '@notifee/react-native';
async function createNotificationChannels() {
if (Platform.OS === 'android') {
// ์ค์ ์๋ฆผ ์ฑ๋
await notifee.createChannel({
id: 'important',
name: '์ค์ ์๋ฆผ',
description: '์ค์ํ ์
๋ฐ์ดํธ์ ๋ฉ์์ง๋ฅผ ์ํ ์ฑ๋',
importance: AndroidImportance.HIGH,
});
// ์ผ๋ฐ ์๋ฆผ ์ฑ๋
await notifee.createChannel({
id: 'default',
name: '์ผ๋ฐ ์๋ฆผ',
description: '์ผ๋ฐ์ ์ธ ์ ๋ณด ์๋ฆผ์ ์ํ ์ฑ๋',
importance: AndroidImportance.DEFAULT,
});
// ๋ง์ผํ
์๋ฆผ ์ฑ๋
await notifee.createChannel({
id: 'marketing',
name: '๋ง์ผํ
์๋ฆผ',
description: 'ํ๋ก๋ชจ์
๊ณผ ๋ง์ผํ
๋ฉ์์ง๋ฅผ ์ํ ์ฑ๋',
importance: AndroidImportance.LOW,
});
}
}
Android์์ ํธ์ ์๋ฆผ์ ๊ตฌํํ ๋๋ ์ฌ์ฉ์ ๊ฒฝํ๊ณผ ๋ฐฐํฐ๋ฆฌ ์๋ชจ๋ฅผ ๊ท ํ ์๊ฒ ๊ณ ๋ คํ๋ ๊ฒ์ด ์ค์ํด. ํนํ ์ฌ๋ฅ๋ท ๊ฐ์ ํ๋ซํผ์์๋ ๊ฑฐ๋๋ ๋ฉ์์ง ๊ฐ์ ์ค์ ์๋ฆผ๊ณผ ๋ง์ผํ ์๋ฆผ์ ๋ถ๋ฆฌํด์ ์ฌ์ฉ์๊ฐ ์ํ๋ ์๋ฆผ๋ง ๋ฐ์ ์ ์๊ฒ ํ๋ฉด ์ข์ ๊ฑฐ์ผ. ๐
6. react-native-push-notification ๋ผ์ด๋ธ๋ฌ๋ฆฌ ํ์ฉํ๊ธฐ ๐
์ง๊ธ๊น์ง Firebase Messaging์ ์ง์ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ์์๋ดค์ด. ํ์ง๋ง ๋ ์ฝ๊ฒ ํธ์ ์๋ฆผ์ ๊ตฌํํ๊ณ ์ถ๋ค๋ฉด react-native-push-notification ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ํ์ฉํ๋ ๊ฒ๋ ์ข์ ๋ฐฉ๋ฒ์ด์ผ. ์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ FCM ์์ ์ถ์ํ ๋ ์ด์ด๋ฅผ ์ ๊ณตํด์ ๋ ๊ฐ๋จํ API๋ก ํธ์ ์๋ฆผ์ ๊ด๋ฆฌํ ์ ์๊ฒ ํด์ค. ๋ง์น ๋ณต์กํ ์๋ฆฌ ๊ณผ์ ์ ๊ฐํธ์์ผ๋ก ๋ง๋ค์ด์ฃผ๋ ๋๋์ด๋๊น? ๐ฒ
๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค์น ๋ฐ ์ค์
๋จผ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ค์นํด๋ณด์:
npm install --save react-native-push-notification
# ๋๋
yarn add react-native-push-notification
# iOS์ ๊ฒฝ์ฐ ์ถ๊ฐ ์ค์น ํ์
npm install --save @react-native-community/push-notification-ios
# ๋๋
yarn add @react-native-community/push-notification-ios
# ๊ทธ๋ฆฌ๊ณ pod ์ค์น
cd ios && pod install
Android ์ค์
Android์์๋ ๋ช ๊ฐ์ง ์ถ๊ฐ ์ค์ ์ด ํ์ํด:
-
build.gradle ์์
// android/build.gradle buildscript { dependencies { // ... ๊ธฐ์กด ์์กด์ฑ classpath 'com.google.gms:google-services:4.3.10' // Google Services ํ๋ฌ๊ทธ์ธ } } // android/app/build.gradle apply plugin: 'com.android.application' apply plugin: 'com.google.gms.google-services' // Google Services ํ๋ฌ๊ทธ์ธ ์ ์ฉ dependencies { // ... ๊ธฐ์กด ์์กด์ฑ implementation 'com.google.firebase:firebase-messaging:23.0.0' // FCM ์์กด์ฑ ์ถ๊ฐ } -
AndroidManifest.xml ์์
<manifest ...> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <application ...> <!-- ๋ณ๊ฒฝ: launchMode๋ฅผ singleTop์ผ๋ก ์ค์ --> <activity android:name=".MainActivity" android:launchMode="singleTop" ...> </activity> <!-- ์ถ๊ฐ: ๋ฆฌ์๋ฒ ๋ฑ๋ก --> <meta-data android:name="com.dieam.reactnativepushnotification.notification_foreground" android:value="false"/> <meta-data android:name="com.dieam.reactnativepushnotification.notification_color" android:resource="@color/white"/> <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationActions" /> <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" /> <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.QUICKBOOT_POWERON" /> <action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/> </intent-filter> </receiver> <service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService" android:exported="false" > <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service> </application> </manifest>
iOS ์ค์
iOS์์๋ ๋ช ๊ฐ์ง ์ค์ ์ด ํ์ํด:
-
AppDelegate.h ์์
#import <UserNotifications/UNUserNotificationCenter.h> @interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate, UNUserNotificationCenterDelegate> // UNUserNotificationCenterDelegate ์ถ๊ฐ -
AppDelegate.m ์์
#import <UserNotifications/UserNotifications.h> #import <RNCPushNotificationIOS.h> @implementation AppDelegate // ... - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // ... // ํธ์ ์๋ฆผ ์ค์ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; center.delegate = self; return YES; } // ํ์ ๋ฉ์๋ ์ถ๊ฐ - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { [RNCPushNotificationIOS didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; } - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { [RNCPushNotificationIOS didFailToRegisterForRemoteNotificationsWithError:error]; } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { [RNCPushNotificationIOS didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler]; } - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler { [RNCPushNotificationIOS didReceiveNotificationResponse:response]; completionHandler(); } - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler { completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge); } @end
๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ฌ์ฉ ๋ฐฉ๋ฒ
์ด์ React Native ์ฝ๋์์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ด๊ธฐํํ๊ณ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ์์๋ณด์:
import React, { useEffect } from 'react';
import { View, Text, Button } from 'react-native';
import PushNotification from 'react-native-push-notification';
// ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ด๊ธฐํ
const configurePushNotifications = () => {
PushNotification.configure({
// FCM ํ ํฐ ๋ฐ๊ธ ์ ํธ์ถ
onRegister: function (token) {
console.log('TOKEN:', token);
// ์ฌ๊ธฐ์ ํ ํฐ์ ์๋ฒ์ ์ ์ฅ
},
// ์๋ฆผ ์์ ์ ํธ์ถ (ํฌ๊ทธ๋ผ์ด๋ ์ํ)
onNotification: function (notification) {
console.log('NOTIFICATION:', notification);
// ํ์ํ ๊ฒฝ์ฐ ์๋ฆผ ์ฒ๋ฆฌ (์: ํน์ ํ๋ฉด์ผ๋ก ์ด๋)
// iOS์์๋ ์ด ํจ์๋ฅผ ํธ์ถํด์ผ ํจ
notification.finish('backgroundFetchResultNoData');
},
// ๋ฑ๋ก ์ค๋ฅ ๋ฐ์ ์ ํธ์ถ
onRegistrationError: function(err) {
console.error(err.message, err);
},
// Android์์๋ง ์ฌ์ฉ๋๋ ์ต์
permissions: {
alert: true,
badge: true,
sound: true,
},
// iOS์์ ์๋ฆผ์ด ํฌ๊ทธ๋ผ์ด๋์ ํ์๋๋๋ก ์ค์
requestPermissions: true,
// FCM ํ๋ก์ ํธ ๋ฒํธ (Android๋ง ํด๋น)
senderID: 'YOUR_FCM_SENDER_ID',
// ์ฑ์ด ํฌ๊ทธ๋ผ์ด๋์ ์์ ๋๋ ์๋ฆผ ํ์
popInitialNotification: true,
// ์ฑ ์์ ์ ์ด๊ธฐ ์๋ฆผ ํ์ธ
requestPermissions: Platform.OS === 'ios'
});
// Android ์ฑ๋ ์์ฑ
PushNotification.createChannel(
{
channelId: 'default-channel-id',
channelName: '๊ธฐ๋ณธ ์ฑ๋',
channelDescription: '๊ธฐ๋ณธ ์๋ฆผ ์ฑ๋',
soundName: 'default',
importance: 4, // ์ค์๋ (1-5)
vibrate: true,
},
(created) => console.log(`์ฑ๋ ์์ฑ ${created ? '์ฑ๊ณต' : '์คํจ'}`)
);
};
function App() {
useEffect(() => {
configurePushNotifications();
}, []);
// ๋ก์ปฌ ์๋ฆผ ๋ณด๋ด๊ธฐ ์์
const sendLocalNotification = () => {
PushNotification.localNotification({
channelId: 'default-channel-id', // Android์ฉ
title: '๋ก์ปฌ ์๋ฆผ ์ ๋ชฉ',
message: '์ด๊ฒ์ ๋ก์ปฌ ํธ์ ์๋ฆผ์
๋๋ค!',
playSound: true,
soundName: 'default',
importance: 'high', // Android์ฉ
priority: 'high', // Android์ฉ
});
};
// ์์ฝ๋ ๋ก์ปฌ ์๋ฆผ ๋ณด๋ด๊ธฐ ์์
const scheduleNotification = () => {
PushNotification.localNotificationSchedule({
channelId: 'default-channel-id', // Android์ฉ
title: '์์ฝ๋ ์๋ฆผ',
message: '์ด ์๋ฆผ์ 10์ด ํ์ ํ์๋ฉ๋๋ค!',
date: new Date(Date.now() + 10 * 1000), // 10์ด ํ
allowWhileIdle: true, // Android์ฉ: ์ ์ ๋ชจ๋์์๋ ์๋ฆผ ํ์
});
};
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>ํธ์ ์๋ฆผ ํ
์คํธ</Text>
<Button title="๋ก์ปฌ ์๋ฆผ ๋ณด๋ด๊ธฐ" onPress={sendLocalNotification} />
<Button title="10์ด ํ ์๋ฆผ ์์ฝ" onPress={scheduleNotification} />
</View>
);
}
export default App;
๊ณ ๊ธ ๊ธฐ๋ฅ ํ์ฉํ๊ธฐ
react-native-push-notification ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ ๋ค์ํ ๊ณ ๊ธ ๊ธฐ๋ฅ์ ์ ๊ณตํด:
-
์๋ฆผ ๋ฐฐ์ง ๊ด๋ฆฌ
// ๋ฐฐ์ง ์ค์ PushNotification.setApplicationIconBadgeNumber(5); // ๋ฐฐ์ง ๊ฐ์ ธ์ค๊ธฐ PushNotification.getApplicationIconBadgeNumber(number => { console.log('ํ์ฌ ๋ฐฐ์ง ์:', number); }); // ๋ฐฐ์ง ์ด๊ธฐํ PushNotification.setApplicationIconBadgeNumber(0); -
์๋ฆผ ์ทจ์ํ๊ธฐ
// ํน์ ID์ ์๋ฆผ ์ทจ์ PushNotification.cancelLocalNotification('notificationId'); // ๋ชจ๋ ์๋ฆผ ์ทจ์ PushNotification.cancelAllLocalNotifications(); -
์๋ฆผ ๊ทธ๋ฃนํ
// Android์์ ์๋ฆผ ๊ทธ๋ฃนํ PushNotification.localNotification({ channelId: 'default-channel-id', title: '์ ๋ฉ์์ง', message: '์๋ก์ด ๋ฉ์์ง๊ฐ 5๊ฐ ์์ต๋๋ค', groupSummary: true, group: 'messages', }); -
์๋ฆผ ์ก์
๋ฒํผ
// Android์์ ์๋ฆผ์ ์ก์ ๋ฒํผ ์ถ๊ฐ PushNotification.localNotification({ channelId: 'default-channel-id', title: '์ ๋ฉ์์ง', message: '์ฌ๋ฅ๋ท์์ ์ ๋ฉ์์ง๊ฐ ๋์ฐฉํ์ต๋๋ค', actions: ['๋ต์ฅ', '๋์ค์'], });
react-native-push-notification ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ ํนํ ๋ก์ปฌ ์๋ฆผ์ ์์ฃผ ์ฌ์ฉํ๋ ์ฑ์ ์ ์ฉํด. ์๋ฅผ ๋ค์ด, ์ฌ๋ฅ๋ท์์ ์ฌ์ฉ์๊ฐ ์ค์ ํ ๋ง๊ฐ์ผ์ด ๋ค๊ฐ์ค๋ฉด ๋ก์ปฌ ์๋ฆผ์ผ๋ก ์๊ธฐ์์ผ์ฃผ๊ฑฐ๋, ํน์ ์๊ฐ์ ์ฑ ์ฌ์ฉ์ ์๊ธฐ์ํค๋ ๊ธฐ๋ฅ์ ์ฝ๊ฒ ๊ตฌํํ ์ ์์ด. ์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ๋ฉด iOS์ Android ๋ชจ๋์์ ์ผ๊ด๋ ๋ฐฉ์์ผ๋ก ํธ์ ์๋ฆผ์ ๊ด๋ฆฌํ ์ ์์ด์ ๊ฐ๋ฐ ์๊ฐ์ ํฌ๊ฒ ๋จ์ถํ ์ ์์ด! ๐
7. ํธ์ ์๋ฆผ ๋์์ธ๊ณผ ์ฌ์ฉ์ ๊ฒฝํ ์ต์ ํ ๐จ
ํธ์ ์๋ฆผ์ ๊ธฐ์ ์ ์ผ๋ก ๊ตฌํํ๋ ๊ฒ๋ ์ค์ํ์ง๋ง, ์ฌ์ฉ์๊ฐ ์ค์ ๋ก ์๋ฆผ์ ํด๋ฆญํ๊ณ ์ฑ์ผ๋ก ๋์์ค๊ฒ ๋ง๋๋ ๊ฒ์ด ๋ ์ค์ํด. ์๋ฌด๋ฆฌ ๊ธฐ์ ์ ์ผ๋ก ์๋ฒฝํ ํธ์ ์๋ฆผ์ด๋ผ๋ ๋ด์ฉ์ด ๋งค๋ ฅ์ ์ด์ง ์๊ฑฐ๋ ์๊ธฐ๊ฐ ๋ถ์ ์ ํ๋ฉด ์ฌ์ฉ์๋ ๊ทธ๋ฅ ๋ฌด์ํ๊ฑฐ๋ ์ฌ์ง์ด ์๋ฆผ์ ๊บผ๋ฒ๋ฆด ์๋ ์์ด. ๋ง์น ๋ง์๋ ์์์ ์์๊ฒ ํ๋ ์ดํ ํ๋ ๊ฒ์ฒ๋ผ, ํธ์ ์๋ฆผ๋ ๋์์ธ๊ณผ ํ์ด๋ฐ์ด ์ค์ํ์ง! ๐ฝ๏ธ
ํจ๊ณผ์ ์ธ ํธ์ ์๋ฆผ ๋์์ธ ์์น
-
๊ฐ๊ฒฐํ๊ณ ๋ช
ํํ ๋ฉ์์ง
ํธ์ ์๋ฆผ์ ๊ณต๊ฐ์ด ์ ํ์ ์ด๋ฏ๋ก ํต์ฌ ๋ฉ์์ง๋ฅผ ๊ฐ๊ฒฐํ๊ฒ ์ ๋ฌํด์ผ ํด. ๋ถํ์ํ ๋จ์ด๋ ๊ณผ๊ฐํ ์๋ตํ๊ณ ํต์ฌ๋ง ๋ด์๋ด์.
โ ๋์ ์: "์๋ ํ์ธ์, ๊ณ ๊ฐ๋. ์ ํฌ ์ฑ์์ ์๋ก์ด ๊ธฐ๋ฅ์ด ์ ๋ฐ์ดํธ๋์์ผ๋ ํ์ธํด๋ณด์๊ธฐ ๋ฐ๋๋๋ค."
โ ์ข์ ์: "์ ๊ธฐ๋ฅ ์ถ์: ์ค์๊ฐ ์ฑํ ์ง์์ด ์ถ๊ฐ๋์ด์!"
-
๊ฐ์ธํ๋ ์ฝํ
์ธ
์ฌ์ฉ์์ ์ด๋ฆ์ด๋ ๊ด์ฌ์ฌ๋ฅผ ํฌํจํ ๊ฐ์ธํ๋ ๋ฉ์์ง๋ ํด๋ฆญ๋ฅ ์ ํฌ๊ฒ ๋์ผ ์ ์์ด.
โ ๋์ ์: "ํ ์ธ ์ด๋ฒคํธ ์ค์ ๋๋ค."
โ ์ข์ ์: "๋ฏผ์ง๋, ๊ด์ฌ ์์ผ์ จ๋ ๋์์ธ ๊ฐ์๊ฐ 20% ํ ์ธ ์ค์ด์์!"
-
ํ๋ ์ ๋ ๋ฌธ๊ตฌ(CTA) ํฌํจ
์ฌ์ฉ์๊ฐ ์๋ฆผ์ ๋ฐ๊ณ ์ด๋ค ํ๋์ ์ทจํด์ผ ํ ์ง ๋ช ํํ๊ฒ ์๋ดํด์ผ ํด.
โ ๋์ ์: "์ ๋ฉ์์ง๊ฐ ์์ต๋๋ค."
โ ์ข์ ์: "์ ๋ฉ์์ง ๋์ฐฉ: ์ง๊ธ ๋ต์ฅํ๊ธฐ"
-
์ ์ ํ ํ์ด๋ฐ
์ฌ์ฉ์์ ์๊ฐ๋์ ํ๋ ํจํด์ ๊ณ ๋ คํด ์๋ฆผ์ ๋ณด๋ด๋ ๊ฒ์ด ์ค์ํด. ์๋ฒฝ์ ๋ง์ผํ ์๋ฆผ์ ๋ณด๋ด๋ฉด ์ฌ์ฉ์๊ฐ ๋ถ์พํดํ ์ ์์ด.
โ ๋์ ์: ์๋ฒฝ 3์์ ํ๋ก๋ชจ์ ์๋ฆผ ๋ฐ์ก
โ ์ข์ ์: ์ฌ์ฉ์๊ฐ ์ฑ์ ์์ฃผ ์ฌ์ฉํ๋ ์๊ฐ๋(์: ์ ๋ 7-9์)์ ์๋ฆผ ๋ฐ์ก
-
์ด๋ฏธ์ง์ ์ด๋ชจ์ง ํ์ฉ
์๊ฐ์ ์์๋ ์๋ฆผ์ ๋ ๋์ ๋๊ฒ ๋ง๋ค๊ณ ๋ฉ์์ง ์ ๋ฌ๋ ฅ์ ๋์ฌ์ค.
โ ๋์ ์: "์๋ก์ด ํ ์ธ ์ฟ ํฐ์ด ๋ฐ๊ธ๋์์ต๋๋ค."
โ ์ข์ ์: "๐ ํน๋ณ ์ ๋ฌผ์ด ๋์ฐฉํ์ด์! 50% ํ ์ธ ์ฟ ํฐ์ ํ์ธํ์ธ์ โจ"
์ฌ์ฉ์ ๊ฒฝํ ์ต์ ํ ์ ๋ต
-
์๋ฆผ ๋น๋ ์กฐ์
๋๋ฌด ๋ง์ ์๋ฆผ์ ์ฌ์ฉ์๋ฅผ ์ง์ฆ๋๊ฒ ๋ง๋ค ์ ์์ด. ์ค์ํ ์๋ฆผ๋ง ์ ๋ณ์ ์ผ๋ก ๋ณด๋ด๊ณ , ์ฌ์ฉ์๊ฐ ์๋ฆผ ์ ํ๊ณผ ๋น๋๋ฅผ ์ค์ ํ ์ ์๊ฒ ํ์.
-
๋ฅ๋งํฌ ํ์ฉ
์๋ฆผ์ ํด๋ฆญํ์ ๋ ๊ด๋ จ ํ๋ฉด์ผ๋ก ๋ฐ๋ก ์ด๋ํ ์ ์๊ฒ ๋ฅ๋งํฌ๋ฅผ ์ค์ ํ๋ฉด ์ฌ์ฉ์ ๊ฒฝํ์ด ํฌ๊ฒ ํฅ์๋ผ.
// FCM ๋ฉ์์ง์ ๋ฅ๋งํฌ ๋ฐ์ดํฐ ํฌํจ { "to": "์ฌ์ฉ์_FCM_ํ ํฐ", "notification": { "title": "์ ๋ฉ์์ง ๋์ฐฉ", "body": "ํ๊ธธ๋๋์ด ๋ฉ์์ง๋ฅผ ๋ณด๋์ต๋๋ค." }, "data": { "type": "chat", "chatId": "123456", "senderId": "user789" } } // React Native์์ ๋ฅ๋งํฌ ์ฒ๋ฆฌ messaging().onNotificationOpenedApp(remoteMessage => { if (remoteMessage.data) { const { type, chatId, senderId } = remoteMessage.data; if (type === 'chat') { // ์ฑํ ํ๋ฉด์ผ๋ก ์ด๋ navigation.navigate('Chat', { chatId, senderId }); } } }); -
A/B ํ
์คํธ ์ํ
๋ค์ํ ์๋ฆผ ๋ฌธ๊ตฌ์ ๋์์ธ์ ํ ์คํธํด ์ด๋ค ๊ฒ์ด ๊ฐ์ฅ ํจ๊ณผ์ ์ธ์ง ๋ฐ์ดํฐ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๊ฒฐ์ ํ์.
-
์ฌ์ฉ์ ์ธ๊ทธ๋จผํธ๋ณ ์ ๋ต ์๋ฆฝ
ํ์ฑ ์ฌ์ฉ์, ๋นํ์ฑ ์ฌ์ฉ์, ์ ๊ท ์ฌ์ฉ์ ๋ฑ ์ธ๊ทธ๋จผํธ๋ณ๋ก ๋ค๋ฅธ ์๋ฆผ ์ ๋ต์ ์ฌ์ฉํ๋ฉด ํจ๊ณผ์ ์ด์ผ.
-
์๋ฆผ ์ค์ ํ๋ฉด ์ต์ ํ
์ฌ์ฉ์๊ฐ ์ฝ๊ฒ ์๋ฆผ์ ๊ด๋ฆฌํ ์ ์๋ ์ง๊ด์ ์ธ ์ค์ ํ๋ฉด์ ์ ๊ณตํ์.
์๋ฆผ ์ค์ ํ๋ฉด ์์ ์ฝ๋
import React, { useState, useEffect } from 'react';
import { View, Text, Switch, StyleSheet, ScrollView } from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
const NotificationSettings = () => {
const [settings, setSettings] = useState({
chatNotifications: true,
dealUpdates: true,
promotions: false,
systemUpdates: true,
soundEnabled: true,
vibrationEnabled: true,
quietHours: false,
});
// ์ค์ ๋ถ๋ฌ์ค๊ธฐ
useEffect(() => {
const loadSettings = async () => {
try {
const savedSettings = await AsyncStorage.getItem('notificationSettings');
if (savedSettings) {
setSettings(JSON.parse(savedSettings));
}
} catch (error) {
console.error('์ค์ ์ ๋ถ๋ฌ์ค๋ ์ค ์ค๋ฅ ๋ฐ์:', error);
}
};
loadSettings();
}, []);
// ์ค์ ๋ณ๊ฒฝ ์ ์ ์ฅ
const updateSetting = (key, value) => {
const newSettings = { ...settings, [key]: value };
setSettings(newSettings);
// AsyncStorage์ ์ ์ฅ
AsyncStorage.setItem('notificationSettings', JSON.stringify(newSettings))
.catch(error => console.error('์ค์ ์ ์ฅ ์ค ์ค๋ฅ ๋ฐ์:', error));
// ์ฌ๊ธฐ์ ํ์์ ๋ฐ๋ผ ์๋ฒ์ ์ฌ์ฉ์ ์ค์ ์
๋ฐ์ดํธ API ํธ์ถ
};
return (
<ScrollView style={styles.container}>
<Text style={styles.title}>์๋ฆผ ์ค์ </Text>
<View style={styles.section}>
<Text style={styles.sectionTitle}>์๋ฆผ ์ ํ</Text>
<View style={styles.settingItem}>
<Text style={styles.settingLabel}>์ฑํ
๋ฉ์์ง</Text>
<Switch
value={settings.chatNotifications}
onValueChange={(value) => updateSetting('chatNotifications', value)}
trackColor={{ false: '#767577', true: '#81b0ff' }}
thumbColor={settings.chatNotifications ? '#1e88e5' : '#f4f3f4'}
/>
</View>
<View style={styles.settingItem}>
<Text style={styles.settingLabel}>๊ฑฐ๋ ์
๋ฐ์ดํธ</Text>
<Switch
value={settings.dealUpdates}
onValueChange={(value) => updateSetting('dealUpdates', value)}
trackColor={{ false: '#767577', true: '#81b0ff' }}
thumbColor={settings.dealUpdates ? '#1e88e5' : '#f4f3f4'}
/>
</View>
<View style={styles.settingItem}>
<Text style={styles.settingLabel}>ํ๋ก๋ชจ์
๋ฐ ๋ง์ผํ
</Text>
<Switch
value={settings.promotions}
onValueChange={(value) => updateSetting('promotions', value)}
trackColor={{ false: '#767577', true: '#81b0ff' }}
thumbColor={settings.promotions ? '#1e88e5' : '#f4f3f4'}
/>
</View>
<View style={styles.settingItem}>
<Text style={styles.settingLabel}>์์คํ
์
๋ฐ์ดํธ</Text>
<Switch
value={settings.systemUpdates}
onValueChange={(value) => updateSetting('systemUpdates', value)}
trackColor={{ false: '#767577', true: '#81b0ff' }}
thumbColor={settings.systemUpdates ? '#1e88e5' : '#f4f3f4'}
/>
</View>
</View>
<View style={styles.section}>
<Text style={styles.sectionTitle}>์๋ฆผ ๋ฐฉ์</Text>
<View style={styles.settingItem}>
<Text style={styles.settingLabel}>์๋ฆฌ</Text>
<Switch
value={settings.soundEnabled}
onValueChange={(value) => updateSetting('soundEnabled', value)}
trackColor={{ false: '#767577', true: '#81b0ff' }}
thumbColor={settings.soundEnabled ? '#1e88e5' : '#f4f3f4'}
/>
</View>
<View style={styles.settingItem}>
<Text style={styles.settingLabel}>์ง๋</Text>
<Switch
value={settings.vibrationEnabled}
onValueChange={(value) => updateSetting('vibrationEnabled', value)}
trackColor={{ false: '#767577', true: '#81b0ff' }}
thumbColor={settings.vibrationEnabled ? '#1e88e5' : '#f4f3f4'}
/>
</View>
<View style={styles.settingItem}>
<Text style={styles.settingLabel}>๋ฐฉํด ๊ธ์ง ์๊ฐ ์ค์ </Text>
<Switch
value={settings.quietHours}
onValueChange={(value) => updateSetting('quietHours', value)}
trackColor={{ false: '#767577', true: '#81b0ff' }}
thumbColor={settings.quietHours ? '#1e88e5' : '#f4f3f4'}
/>
</View>
</View>
<Text style={styles.footer}>
์๋ฆผ ์ค์ ์ ๋ณ๊ฒฝํ๋ฉด ์๋์ผ๋ก ์ ์ฅ๋ฉ๋๋ค.
</Text>
</ScrollView>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 16,
backgroundColor: '#fff',
},
title: {
fontSize: 24,
fontWeight: 'bold',
marginBottom: 20,
color: '#333',
},
section: {
marginBottom: 24,
backgroundColor: '#f9f9f9',
borderRadius: 8,
padding: 16,
},
sectionTitle: {
fontSize: 18,
fontWeight: '600',
marginBottom: 16,
color: '#333',
},
settingItem: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
paddingVertical: 12,
borderBottomWidth: 1,
borderBottomColor: '#eee',
},
settingLabel: {
fontSize: 16,
color: '#444',
},
footer: {
marginTop: 16,
marginBottom: 32,
textAlign: 'center',
color: '#666',
fontSize: 14,
},
});
export default NotificationSettings;
ํธ์ ์๋ฆผ ๋์์ธ๊ณผ ์ฌ์ฉ์ ๊ฒฝํ์ ์ฑ์ ์ฑ๊ณต์ ์ง์ ์ ์ธ ์ํฅ์ ๋ฏธ์ณ. ํนํ ์ฌ๋ฅ๋ท ๊ฐ์ ์๋น์ค์์๋ ์ฌ์ฉ์ ๊ฐ์ ์ํต์ด ์ค์ํ๊ธฐ ๋๋ฌธ์, ์ ์ ํ ํ์ด๋ฐ์ ๊ฐ์ธํ๋ ์๋ฆผ์ ๋ณด๋ด๋ ๊ฒ์ด ์ฌ์ฉ์ ์ฐธ์ฌ๋์ ๋ง์กฑ๋๋ฅผ ํฌ๊ฒ ๋์ผ ์ ์์ด. ํ์ง๋ง ํญ์ ๊ธฐ์ตํด์ผ ํ ๊ฒ์ "๋ ๋ณด๋ด๋ ๊ฒ์ด ๋ ํจ๊ณผ์ ์ผ ์ ์๋ค"๋ ์ ์ด์ผ. ์ ๋ง ์ค์ํ ์๋ฆผ๋ง ์ ๋ณ์ ์ผ๋ก ๋ณด๋ด์ ์ฌ์ฉ์์ ์ ๋ขฐ๋ฅผ ์ป๋ ๊ฒ์ด ์ฅ๊ธฐ์ ์ผ๋ก ๋ ํฐ ์ฑ๊ณต์ ๊ฐ์ ธ์ฌ ๊ฑฐ์ผ! ๐
8. ํธ์ ์๋ฆผ ํ ์คํธ ๋ฐ ๋๋ฒ๊น ๋ฐฉ๋ฒ ๐
ํธ์ ์๋ฆผ์ ๊ตฌํํ๋ค๋ฉด ์ด์ ์ ๋๋ก ์๋ํ๋์ง ํ ์คํธํ๊ณ ๋ฌธ์ ๊ฐ ์์ผ๋ฉด ๋๋ฒ๊น ํด์ผ ํด. ํธ์ ์๋ฆผ์ ์ฌ๋ฌ ์์คํ (์ฑ, FCM, APNs ๋ฑ)์ ๊ฑฐ์ณ ์ ๋ฌ๋๊ธฐ ๋๋ฌธ์ ๋ฌธ์ ๊ฐ ๋ฐ์ํ ์ ์๋ ์ง์ ์ด ๋ง์. ๋ง์น ๋ฐฐ๋ฌ ์์์ด ์ฃผ๋ฐฉ์์ ์ถ๋ฐํด ๋ฐฐ๋ฌ์์ ๊ฑฐ์ณ ์ง๊น์ง ์ค๋ ๊ณผ์ ์์ ์ฌ๋ฌ ๋ฌธ์ ๊ฐ ์๊ธธ ์ ์๋ ๊ฒ์ฒ๋ผ ๋ง์ด์ผ. ๊ทธ๋ผ ํจ๊ณผ์ ์ธ ํ ์คํธ์ ๋๋ฒ๊น ๋ฐฉ๋ฒ์ ์์๋ณด์! ๐ต๏ธโโ๏ธ
ํธ์ ์๋ฆผ ํ ์คํธ ๋ฐฉ๋ฒ
-
Firebase ์ฝ์ ์ฌ์ฉํ๊ธฐ
๊ฐ์ฅ ๊ฐ๋จํ ๋ฐฉ๋ฒ์ Firebase ์ฝ์์ Cloud Messaging ์น์ ์์ ํ ์คํธ ๋ฉ์์ง๋ฅผ ๋ณด๋ด๋ ๊ฑฐ์ผ.
- Firebase ์ฝ์์ ๋ก๊ทธ์ธํด.
- ํ๋ก์ ํธ๋ฅผ ์ ํํ๊ณ ์ผ์ชฝ ๋ฉ๋ด์์ "Messaging"์ ํด๋ฆญํด.
- "์ฒซ ๋ฒ์งธ ์บ ํ์ธ ๋ง๋ค๊ธฐ" ๋๋ "์ ์๋ฆผ ๋ณด๋ด๊ธฐ"๋ฅผ ํด๋ฆญํด.
- ์๋ฆผ ์ ๋ชฉ, ํ ์คํธ, ์ด๋ฏธ์ง ๋ฑ์ ์ ๋ ฅํด.
- ํ๊ฒํ ์น์ ์์ "์ฑ"์ ์ ํํ๊ณ ํ ์คํธํ ์ฑ์ ์ง์ ํด.
- ํ ์คํธ ๊ธฐ๊ธฐ์ FCM ํ ํฐ์ ์ ๋ ฅํ๊ฑฐ๋ ํ ์คํธ ๊ทธ๋ฃน์ ๋ง๋ค์ด ์ง์ ํด.
- "๊ฒํ " ๋ฒํผ์ ํด๋ฆญํ ํ "๊ฒ์"๋ฅผ ํด๋ฆญํด.
-
Postman์ด๋ cURL ์ฌ์ฉํ๊ธฐ
API ์์ฒญ์ ์ง์ ๋ณด๋ด์ ๋ ์ธ๋ฐํ ํ ์คํธ๋ฅผ ํ ์ ์์ด:
curl -X POST -H "Authorization: key=YOUR_SERVER_KEY" -H "Content-Type: application/json" \ -d '{ "to": "DEVICE_FCM_TOKEN", "notification": { "title": "ํ ์คํธ ์๋ฆผ", "body": "์ด๊ฒ์ ํ ์คํธ ํธ์ ์๋ฆผ์ ๋๋ค!" }, "data": { "type": "test", "id": "123" } }' \ https://fcm.googleapis.com/fcm/send -
๋ก์ปฌ ์๋ฆผ์ผ๋ก ํ
์คํธํ๊ธฐ
์๊ฒฉ ์๋ฒ ์์ด๋ ๋ก์ปฌ ์๋ฆผ์ ์ฌ์ฉํด ์๋ฆผ ํ์ ๋ฐฉ์์ ํ ์คํธํ ์ ์์ด:
// react-native-push-notification ์ฌ์ฉ PushNotification.localNotification({ channelId: 'default-channel-id', // Android์ฉ title: 'ํ ์คํธ ์๋ฆผ', message: '์ด๊ฒ์ ๋ก์ปฌ ํ ์คํธ ์๋ฆผ์ ๋๋ค!', playSound: true, soundName: 'default', }); -
์๋ํ๋ ํ
์คํธ ์คํฌ๋ฆฝํธ ์์ฑํ๊ธฐ
์ฌ๋ฌ ์ ํ์ ์๋ฆผ์ ์๋์ผ๋ก ํ ์คํธํ๋ ์คํฌ๋ฆฝํธ๋ฅผ ๋ง๋ค๋ฉด ํจ์จ์ ์ด์ผ:
// test-notifications.js const axios = require('axios'); const FCM_SERVER_KEY = 'YOUR_SERVER_KEY'; const TEST_DEVICE_TOKEN = 'TEST_DEVICE_FCM_TOKEN'; const testCases = [ { title: '๊ธฐ๋ณธ ์๋ฆผ ํ ์คํธ', body: '๊ธฐ๋ณธ ํ ์คํธ๋ง ์๋ ์๋ฆผ์ ๋๋ค.', data: {} }, { title: '๋ฅ๋งํฌ ํ ์คํธ', body: '์ด ์๋ฆผ์ ํน์ ํ๋ฉด์ผ๋ก ์ด๋ํฉ๋๋ค.', data: { type: 'navigation', screen: 'Profile', id: '12345' } }, { title: '์ด๋ฏธ์ง ์๋ฆผ ํ ์คํธ', body: '์ด๋ฏธ์ง๊ฐ ํฌํจ๋ ์๋ฆผ์ ๋๋ค.', image: 'https://example.com/test-image.jpg', data: {} } ]; async function runTests() { for (const test of testCases) { console.log(`ํ ์คํธ ์คํ: ${test.title}`); try { const response = await axios.post('https://fcm.googleapis.com/fcm/send', { to: TEST_DEVICE_TOKEN, notification: { title: test.title, body: test.body, image: test.image }, data: test.data }, { headers: { 'Authorization': `key=${FCM_SERVER_KEY}`, 'Content-Type': 'application/json' } }); console.log('์๋ต:', response.data); } catch (error) { console.error('์ค๋ฅ:', error.response ? error.response.data : error.message); } // ํ ์คํธ ๊ฐ ๊ฐ๊ฒฉ ๋๊ธฐ await new Promise(resolve => setTimeout(resolve, 5000)); } } runTests();
ํธ์ ์๋ฆผ ๋๋ฒ๊น ๋จ๊ณ
-
FCM ํ ํฐ ํ์ธ
๊ฐ์ฅ ๋จผ์ ํ์ธํ ๊ฒ์ FCM ํ ํฐ์ด ์ ๋๋ก ์์ฑ๋๊ณ ์๋ฒ์ ์ ์ฅ๋์๋์ง์ผ:
// ํ ํฐ ๋ก๊น messaging() .getToken() .then(token => { console.log('FCM ํ ํฐ:', token); // ์ฌ๊ธฐ์ ํ ํฐ์ด ์ ๋๋ก ์์ฑ๋์๋์ง ํ์ธ }); -
์๋ฆผ ๊ถํ ํ์ธ
์ฌ์ฉ์๊ฐ ์๋ฆผ ๊ถํ์ ํ์ฉํ๋์ง ํ์ธํด:
// iOS์์ ๊ถํ ์ํ ํ์ธ import { Platform } from 'react-native'; import messaging from '@react-native-firebase/messaging'; async function checkNotificationPermission() { if (Platform.OS === 'ios') { const authStatus = await messaging().hasPermission(); console.log('์๋ฆผ ๊ถํ ์ํ:', authStatus); if (authStatus === messaging.AuthorizationStatus.NOT_DETERMINED) { console.log('์ฌ์ฉ์๊ฐ ์์ง ๊ถํ์ ๊ฒฐ์ ํ์ง ์์์ต๋๋ค.'); } else if (authStatus === messaging.AuthorizationStatus.DENIED) { console.log('์ฌ์ฉ์๊ฐ ์๋ฆผ ๊ถํ์ ๊ฑฐ๋ถํ์ต๋๋ค.'); } else { console.log('์ฌ์ฉ์๊ฐ ์๋ฆผ ๊ถํ์ ํ์ฉํ์ต๋๋ค.'); } } } -
Firebase ์ฝ์์์ ์ ์ก ์ํ ํ์ธ
Firebase ์ฝ์์ Cloud Messaging > ๋์๋ณด๋์์ ๋ฉ์์ง ์ ์ก ์ํ์ ์ค๋ฅ๋ฅผ ํ์ธํ ์ ์์ด.
-
๋คํธ์ํฌ ์์ฒญ ๋ชจ๋ํฐ๋ง
Charles Proxy๋ Wireshark ๊ฐ์ ๋๊ตฌ๋ก ๋คํธ์ํฌ ์์ฒญ์ ๋ชจ๋ํฐ๋งํด FCM ์๋ฒ์์ ํต์ ๋ฌธ์ ๋ฅผ ํ์ธํ ์ ์์ด.
-
ํ๋ซํผ๋ณ ๋ก๊ทธ ํ์ธ
iOS์ Android์์ ๊ฐ๊ฐ ๋ก๊ทธ๋ฅผ ํ์ธํ๋ ๋ฐฉ๋ฒ:
- - iOS: Xcode์ ์ฝ์ ๋ก๊ทธ์์ "notification"์ด๋ "apns" ํค์๋๋ก ๊ฒ์
- - Android: Logcat์์ "FCM" ๋๋ "FirebaseMessaging" ํ๊ทธ๋ก ํํฐ๋ง
-
๋จ๊ณ๋ณ ํ
์คํธ
๋ฌธ์ ๋ฅผ ๋ถ๋ฆฌํ๊ธฐ ์ํด ๋จ๊ณ๋ณ๋ก ํ ์คํธํด:
- ๋ก์ปฌ ์๋ฆผ์ด ์๋ํ๋์ง ํ์ธ (์ฑ ๋ด๋ถ์์ ์์ฑ)
- Firebase ์ฝ์์์ ์ง์ ํ ์คํธ ๋ฉ์์ง ์ ์ก
- ์๋ฒ์์ FCM API๋ก ๋ฉ์์ง ์ ์ก
์์ฃผ ๋ฐ์ํ๋ ๋ฌธ์ ์ ํด๊ฒฐ ๋ฐฉ๋ฒ
-
์๋ฆผ์ด ์ ํ ๋์ฐฉํ์ง ์๋ ๊ฒฝ์ฐ
- - FCM ํ ํฐ์ด ์ฌ๋ฐ๋ฅด๊ฒ ์๋ฒ์ ๋ฑ๋ก๋์๋์ง ํ์ธ
- - iOS์์ ํธ์ ์๋ฆผ ์ธ์ฆ์๊ฐ ์ ํจํ์ง ํ์ธ
- - Android์์ google-services.json ํ์ผ์ด ์ฌ๋ฐ๋ฅธ ์์น์ ์๋์ง ํ์ธ
- - ์ฌ์ฉ์๊ฐ ์๋ฆผ ๊ถํ์ ํ์ฉํ๋์ง ํ์ธ
- - ๊ธฐ๊ธฐ๊ฐ ์ธํฐ๋ท์ ์ฐ๊ฒฐ๋์ด ์๋์ง ํ์ธ
-
์๋ฆผ์ ๋์ฐฉํ์ง๋ง ํด๋ฆญํด๋ ์ฑ์ด ์ด๋ฆฌ์ง ์๋ ๊ฒฝ์ฐ
- - Android์์ Intent ํํฐ๊ฐ ์ฌ๋ฐ๋ฅด๊ฒ ์ค์ ๋์๋์ง ํ์ธ
- - ์๋ฆผ ์ฒ๋ฆฌ ์ฝ๋์์ ์ค๋ฅ๊ฐ ์๋์ง ํ์ธ
- - ๋ฅ๋งํฌ ์ฒ๋ฆฌ ๋ก์ง์ด ์ฌ๋ฐ๋ฅธ์ง ํ์ธ
-
iOS์์๋ง ์๋ฆผ์ด ์๋ํ์ง ์๋ ๊ฒฝ์ฐ
- - APNs ์ธ์ฆ์๊ฐ ์ ํจํ์ง ํ์ธ
- - Capabilities์ Push Notifications๊ฐ ํ์ฑํ๋์ด ์๋์ง ํ์ธ
- - ์ฑ์ด ํ๋ก๋์ /๊ฐ๋ฐ ํ๊ฒฝ์ ๋ง๋ ์ธ์ฆ์๋ฅผ ์ฌ์ฉํ๊ณ ์๋์ง ํ์ธ
-
Android์์๋ง ์๋ฆผ์ด ์๋ํ์ง ์๋ ๊ฒฝ์ฐ
- - AndroidManifest.xml์ ํ์ํ ๊ถํ๊ณผ ์๋น์ค๊ฐ ๋ฑ๋ก๋์ด ์๋์ง ํ์ธ
- - ์๋ฆผ ์ฑ๋์ด ์ฌ๋ฐ๋ฅด๊ฒ ์์ฑ๋์๋์ง ํ์ธ (Android 8.0 ์ด์)
- - ๊ธฐ๊ธฐ์ ๋ฐฐํฐ๋ฆฌ ์ต์ ํ ์ค์ ์์ ์ฑ์ด ์ ์ธ๋์ด ์๋์ง ํ์ธ
-
์๋ฆผ ์คํ์ผ์ด๋ ์๋ฆฌ๊ฐ ์์๊ณผ ๋ค๋ฅธ ๊ฒฝ์ฐ
- - Android์์ ์๋ฆผ ์ฑ๋ ์ค์ ํ์ธ
- - ์๋ฆผ ํ์ด๋ก๋์ ์คํ์ผ ๊ด๋ จ ์์ฑ์ด ์ฌ๋ฐ๋ฅด๊ฒ ์ค์ ๋์๋์ง ํ์ธ
- - ๊ธฐ๊ธฐ์ ์๋ฆฌ/์ง๋ ์ค์ ํ์ธ
์ ์ฉํ ๋๋ฒ๊น ๋๊ตฌ
-
Firebase ๋๋ฒ๊ทธ ๋ทฐ
Firebase ์ฝ์์ Cloud Messaging > ๋์๋ณด๋์์ ๋ฉ์์ง ์ ์ก ์ํ์ ์ค๋ฅ๋ฅผ ํ์ธํ ์ ์์ด.
-
FCM ํ
์คํธ ํด๋ผ์ด์ธํธ
Google์์ ์ ๊ณตํ๋ FCM ํ ์คํธ ํด๋ผ์ด์ธํธ๋ฅผ ์ฌ์ฉํด ์๋ฆผ ์์ ์ ํ ์คํธํ ์ ์์ด.
-
Flipper
React Native ๋๋ฒ๊น ๋๊ตฌ์ธ Flipper๋ฅผ ์ฌ์ฉํ๋ฉด ๋คํธ์ํฌ ์์ฒญ๊ณผ ์ฑ ๋ก๊ทธ๋ฅผ ์ฝ๊ฒ ๋ชจ๋ํฐ๋งํ ์ ์์ด.
-
React Native Debugger
React Native Debugger๋ฅผ ์ฌ์ฉํ๋ฉด ์ฑ ์ํ์ ๋คํธ์ํฌ ์์ฒญ์ ํ ๊ณณ์์ ๋๋ฒ๊น ํ ์ ์์ด.
ํธ์ ์๋ฆผ ํ ์คํธ์ ๋๋ฒ๊น ์ ์ธ๋ด์ฌ๊ณผ ์ฒด๊ณ์ ์ธ ์ ๊ทผ์ด ํ์ํด. ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ ๋ ๋นํฉํ์ง ๋ง๊ณ ์์์ ์ค๋ช ํ ๋จ๊ณ๋ฅผ ์ฐจ๊ทผ์ฐจ๊ทผ ๋ฐ๋ผ๊ฐ๋ฉด ๋๋ถ๋ถ์ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์ ์์ ๊ฑฐ์ผ. ์ฌ๋ฅ๋ท ๊ฐ์ ํ๋ซํผ์์๋ ํธ์ ์๋ฆผ์ด ์ฌ์ฉ์ ์ฐธ์ฌ์ ์ค์ํ ์ญํ ์ ํ๊ธฐ ๋๋ฌธ์, ์ฒ ์ ํ ํ ์คํธ๋ฅผ ํตํด ๋ชจ๋ ์ฌ์ฉ์์๊ฒ ์๋ฆผ์ด ์ ๋๋ก ์ ๋ฌ๋๋์ง ํ์ธํ๋ ๊ฒ์ด ์ค์ํด! ๐ง
9. ์ค์ ํ์ฉ ์ฌ๋ก์ ๋ฒ ์คํธ ํ๋ํฐ์ค ๐
์ด์ ํธ์ ์๋ฆผ์ ๊ธฐ์ ์ ์ธ ๊ตฌํ ๋ฐฉ๋ฒ์ ๋ชจ๋ ์์์ผ๋, ์ค์ ๋ก ์ด๋ป๊ฒ ํ์ฉํ๋ฉด ์ข์์ง ์ดํด๋ณด์! ํธ์ ์๋ฆผ์ ๋จ์ํ ์ฌ์ฉ์์๊ฒ ์ ๋ณด๋ฅผ ์ ๋ฌํ๋ ๊ฒ์ ๋์ด, ์ฑ์ ์ฌ์ฉ์ ๊ฒฝํ์ ํฅ์์ํค๊ณ ๋น์ฆ๋์ค ๋ชฉํ๋ฅผ ๋ฌ์ฑํ๋ ๊ฐ๋ ฅํ ๋๊ตฌ๊ฐ ๋ ์ ์์ด. ๋ง์น ์๋ฆฌ์ฌ๊ฐ ๋ค์ํ ์ฌ๋ฃ๋ก ๋ง์๋ ์๋ฆฌ๋ฅผ ๋ง๋๋ ๊ฒ์ฒ๋ผ, ํธ์ ์๋ฆผ๋ ๋ค์ํ ๋ฐฉ์์ผ๋ก ํ์ฉํ ์ ์์ง! ๐จโ๐ณ
๋ค์ํ ํ์ฉ ์ฌ๋ก
-
์ค์๊ฐ ๋ฉ์์ง
์ฌ๋ฅ๋ท๊ณผ ๊ฐ์ ํ๋ซํผ์์ ์ฌ์ฉ์ ๊ฐ ๋ฉ์์ง๊ฐ ๋์ฐฉํ์ ๋ ์ฆ์ ์๋ฆผ์ ๋ณด๋ด ์ํต์ ์ด์งํ ์ ์์ด.
// ๋ฉ์์ง ์๋ฆผ ์์ (์๋ฒ ์ฝ๋) async function sendMessageNotification(recipientToken, senderName, messagePreview) { const message = { token: recipientToken, notification: { title: `${senderName}๋์ ์ ๋ฉ์์ง`, body: messagePreview.length > 50 ? messagePreview.substring(0, 47) + '...' : messagePreview }, data: { type: 'chat', senderId: sender.id, timestamp: Date.now().toString() }, android: { priority: 'high', notification: { channel_id: 'chat', click_action: 'OPEN_CHAT_ACTIVITY' } }, apns: { payload: { aps: { category: 'NEW_MESSAGE', sound: 'default' } } } }; try { const response = await admin.messaging().send(message); console.log('๋ฉ์์ง ์๋ฆผ ์ ์ก ์ฑ๊ณต:', response); return response; } catch (error) { console.error('๋ฉ์์ง ์๋ฆผ ์ ์ก ์คํจ:', error); throw error; } } -
๊ฑฐ๋ ๋ฐ ์ฃผ๋ฌธ ์ํ ์
๋ฐ์ดํธ
์ฌ๋ฅ ๊ฑฐ๋๊ฐ ์ฑ์ฌ๋๊ฑฐ๋ ์ํ๊ฐ ๋ณ๊ฒฝ๋ ๋ ์๋ฆผ์ ๋ณด๋ด ์ฌ์ฉ์๊ฐ ์ต์ ์ ๋ณด๋ฅผ ๋์น์ง ์๊ฒ ํ ์ ์์ด.
// ๊ฑฐ๋ ์ํ ์๋ฆผ ์์ (์๋ฒ ์ฝ๋) function sendTransactionStatusNotification(userToken, transactionId, newStatus) { let title, body; switch (newStatus) { case 'accepted': title = '๊ฑฐ๋๊ฐ ์๋ฝ๋์์ต๋๋ค'; body = 'ํ๋งค์๊ฐ ๊ทํ์ ๊ฑฐ๋ ์์ฒญ์ ์๋ฝํ์ต๋๋ค. ์์ธํ ๋ด์ฉ์ ํ์ธํ์ธ์.'; break; case 'completed': title = '๊ฑฐ๋๊ฐ ์๋ฃ๋์์ต๋๋ค'; body = '๊ฑฐ๋๊ฐ ์ฑ๊ณต์ ์ผ๋ก ์๋ฃ๋์์ต๋๋ค. ๋ฆฌ๋ทฐ๋ฅผ ์์ฑํด์ฃผ์ธ์!'; break; case 'cancelled': title = '๊ฑฐ๋๊ฐ ์ทจ์๋์์ต๋๋ค'; body = '๊ฑฐ๋๊ฐ ์ทจ์๋์์ต๋๋ค. ์์ธํ ๋ด์ฉ์ ๊ฑฐ๋ ๋ด์ญ์ ํ์ธํ์ธ์.'; break; default: title = '๊ฑฐ๋ ์ํ ์ ๋ฐ์ดํธ'; body = '๊ฑฐ๋ ์ํ๊ฐ ์ ๋ฐ์ดํธ๋์์ต๋๋ค. ํ์ธํด๋ณด์ธ์.'; } const message = { token: userToken, notification: { title, body }, data: { type: 'transaction', transactionId: transactionId, status: newStatus } }; return admin.messaging().send(message); } -
๊ฐ์ธํ๋ ์ถ์ฒ
์ฌ์ฉ์์ ๊ด์ฌ์ฌ๋ ์ด์ ํ๋์ ๊ธฐ๋ฐ์ผ๋ก ๋ง์ถคํ ์ฌ๋ฅ์ด๋ ์๋น์ค๋ฅผ ์ถ์ฒํ๋ ์๋ฆผ์ ๋ณด๋ผ ์ ์์ด.
// ๋ง์ถคํ ์ถ์ฒ ์๋ฆผ ์์ (์๋ฒ ์ฝ๋) async function sendPersonalizedRecommendation(user) { // ์ฌ์ฉ์์ ๊ด์ฌ์ฌ์ ์ด์ ํ๋ ๊ธฐ๋ฐ์ผ๋ก ์ถ์ฒ ํญ๋ชฉ ์ฐพ๊ธฐ const recommendations = await getRecommendationsForUser(user.id); if (recommendations.length === 0) return; // ๊ฐ์ฅ ๊ด๋ จ์ฑ ๋์ ์ถ์ฒ ์ ํ const topRecommendation = recommendations[0]; const message = { token: user.fcmToken, notification: { title: `${user.firstName}๋์ ์ํ ๋ง์ถค ์ถ์ฒ`, body: `"${topRecommendation.title}" ์ฌ๋ฅ์ด ํ์๋์ ๊ด์ฌ์ฌ์ ์ผ์นํฉ๋๋ค!` }, data: { type: 'recommendation', itemId: topRecommendation.id, category: topRecommendation.category } }; return admin.messaging().send(message); } -
๋ฆฌ๋ง์ธ๋ ๋ฐ ์๋ฆผ
์์ฝ๋ ๋ฏธํ , ๋ง๊ฐ์ผ, ์ด๋ฒคํธ ๋ฑ์ ์๊ธฐ์์ผ์ฃผ๋ ์๋ฆผ์ ๋ณด๋ผ ์ ์์ด.
// ๋ฆฌ๋ง์ธ๋ ์๋ฆผ ์์ (์๋ฒ ์ฝ๋) function scheduleReminderNotification(userToken, eventId, eventTitle, eventTime) { // ์ด๋ฒคํธ 1์๊ฐ ์ ์ ์๋ฆผ ์์ฝ const reminderTime = new Date(eventTime); reminderTime.setHours(reminderTime.getHours() - 1); const message = { token: userToken, notification: { title: '๊ณง ์์ ๋ ์ผ์ ์ด ์์ต๋๋ค', body: `1์๊ฐ ํ "${eventTitle}" ์ผ์ ์ด ์์ต๋๋ค. ์ค๋นํ์ธ์!` }, data: { type: 'reminder', eventId: eventId }, android: { priority: 'high', ttl: 3600 * 1000 // 1์๊ฐ }, apns: { payload: { aps: { sound: 'default' } } } }; // ์์ฝ๋ ์๊ฐ์ ๋ฉ์์ง ์ ์ก return admin.messaging().sendToDevice(userToken, message, { timeToLive: Math.floor((reminderTime.getTime() - Date.now()) / 1000) }); } -
์ฌ์ฉ์ ์ฌ์ฐธ์ฌ ์ ๋
์ค๋ซ๋์ ์ฑ์ ์ฌ์ฉํ์ง ์์ ์ฌ์ฉ์์๊ฒ ์๋ก์ด ๊ธฐ๋ฅ์ด๋ ์ฝํ ์ธ ๋ฅผ ์๊ฐํ๋ ์๋ฆผ์ ๋ณด๋ด ์ฌ์ฐธ์ฌ๋ฅผ ์ ๋ํ ์ ์์ด.
// ์ฌ์ฐธ์ฌ ์๋ฆผ ์์ (์๋ฒ ์ฝ๋) async function sendReengagementNotification(inactiveUsers) { const batch = []; for (const user of inactiveUsers) { // ๋ง์ง๋ง ํ๋ ๊ธฐ๋ฐ์ผ๋ก ๋ง์ถคํ ๋ฉ์์ง ์์ฑ let title, body; const daysSinceLastActivity = getDaysSince(user.lastActiveAt); if (daysSinceLastActivity > 30) { title = '์ค๋๋ง์ด์์!'; body = '์ฌ๋ฅ๋ท์ ์๋ก์ด ๊ธฐ๋ฅ์ด ๋ง์ด ์ถ๊ฐ๋์ด์. ์ง๊ธ ํ์ธํด๋ณด์ธ์!'; } else { title = '๋์์ค์ธ์!'; body = 'ํ์๋์ ์ํ ์๋ก์ด ์ฌ๋ฅ๋ค์ด ๊ธฐ๋ค๋ฆฌ๊ณ ์์ด์.'; } batch.push({ token: user.fcmToken, notification: { title, body }, data: { type: 'reengagement', lastSeen: user.lastActiveAt } }); } // ๋ฐฐ์น๋ก ์๋ฆผ ์ ์ก return admin.messaging().sendAll(batch); }
ํธ์ ์๋ฆผ ๋ฒ ์คํธ ํ๋ํฐ์ค
-
์ ์ ํ ๋น๋ ์ ์งํ๊ธฐ
๋๋ฌด ๋ง์ ์๋ฆผ์ ์ฌ์ฉ์๋ฅผ ์ง์ฆ๋๊ฒ ๋ง๋ค ์ ์์ด. ํ๋ฃจ์ ๋ณด๋ด๋ ์๋ฆผ ์๋ฅผ ์ ํํ๊ณ , ์ ๋ง ์ค์ํ ์ ๋ณด๋ง ์๋ฆผ์ผ๋ก ๋ณด๋ด์.
-
๊ฐ์ธํ๋ ์ฝํ
์ธ ์ ๊ณตํ๊ธฐ
์ฌ์ฉ์์ ์ด๋ฆ, ๊ด์ฌ์ฌ, ํ๋ ํจํด ๋ฑ์ ํ์ฉํด ๊ฐ์ธํ๋ ์๋ฆผ์ ๋ณด๋ด๋ฉด ์ฐธ์ฌ์จ์ด ํฌ๊ฒ ๋์์ ธ.
-
์ ์ ํ ํ์ด๋ฐ ์ ํํ๊ธฐ
์ฌ์ฉ์์ ์๊ฐ๋์ ํ๋ ํจํด์ ๊ณ ๋ คํด ์๋ฆผ์ ๋ณด๋ด๋ ๊ฒ์ด ์ค์ํด. ์๋ฅผ ๋ค์ด, ์์นจ์๋ ๊ฐ๋ฒผ์ด ์ ๋ณด, ์ ๋ ์๋ ์ฌ๊ฐ ๊ด๋ จ ์ฝํ ์ธ ๋ฅผ ์ถ์ฒํ๋ ์์ผ๋ก ๋ง์ด์ผ.
-
์ธ๊ทธ๋จผํธ๋ณ ์ ๋ต ์๋ฆฝํ๊ธฐ
์ฌ์ฉ์๋ฅผ ํ์ฑ ์ฌ์ฉ์, ๋นํ์ฑ ์ฌ์ฉ์, ์ ๊ท ์ฌ์ฉ์ ๋ฑ์ผ๋ก ๋๋์ด ๊ฐ ๊ทธ๋ฃน์ ๋ง๋ ์๋ฆผ ์ ๋ต์ ์๋ฆฝํ์.
-
A/B ํ
์คํธ ์ค์ํ๊ธฐ
๋ค์ํ ์๋ฆผ ๋ฌธ๊ตฌ, ๋์์ธ, ํ์ด๋ฐ์ ํ ์คํธํด ์ด๋ค ๋ฐฉ์์ด ๊ฐ์ฅ ํจ๊ณผ์ ์ธ์ง ๋ฐ์ดํฐ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๊ฒฐ์ ํ์.
-
๋ฅ๋งํฌ ํ์ฉํ๊ธฐ
์๋ฆผ์ ํด๋ฆญํ์ ๋ ๊ด๋ จ ํ๋ฉด์ผ๋ก ๋ฐ๋ก ์ด๋ํ ์ ์๊ฒ ๋ฅ๋งํฌ๋ฅผ ์ค์ ํ๋ฉด ์ฌ์ฉ์ ๊ฒฝํ์ด ํฌ๊ฒ ํฅ์๋ผ.
-
์ฌ์ฉ์ ์ ์ด๊ถ ์ ๊ณตํ๊ธฐ
์ฌ์ฉ์๊ฐ ์๋ฆผ ์ ํ๊ณผ ๋น๋๋ฅผ ์ฝ๊ฒ ๊ด๋ฆฌํ ์ ์๋ ์ค์ ํ๋ฉด์ ์ ๊ณตํ์. ์ด๋ ์๋ฆผ ์ฐจ๋จ์ ๋ฐฉ์งํ๋ ๋ฐ ๋์์ด ๋ผ.
-
์ฑ๊ณผ ์ธก์ ํ๊ธฐ
์๋ฆผ ์คํ์จ, ํด๋ฆญ๋ฅ , ์ ํ์จ ๋ฑ์ ์ธก์ ํด ์๋ฆผ ์ ๋ต์ ํจ๊ณผ๋ฅผ ์ง์์ ์ผ๋ก ํ๊ฐํ๊ณ ๊ฐ์ ํ์.
ํธ์ ์๋ฆผ ์ฑ๊ณผ ์ธก์ ๊ตฌํ
ํธ์ ์๋ฆผ์ ํจ๊ณผ๋ฅผ ์ธก์ ํ๊ธฐ ์ํ ์ฝ๋ ์์:
// React Native์์ ์๋ฆผ ๋ถ์ ๊ตฌํ ์์
import analytics from '@react-native-firebase/analytics';
import messaging from '@react-native-firebase/messaging';
// ์๋ฆผ ์์ ์ ์ด๋ฒคํธ ๊ธฐ๋ก
messaging().onMessage(async remoteMessage => {
// ์๋ฆผ ์์ ์ด๋ฒคํธ ๊ธฐ๋ก
await analytics().logEvent('notification_received', {
notification_id: remoteMessage.messageId,
notification_type: remoteMessage.data?.type || 'unknown',
timestamp: Date.now()
});
// ์๋ฆผ ํ์ ๋ก์ง...
});
// ์๋ฆผ ํด๋ฆญ ์ ์ด๋ฒคํธ ๊ธฐ๋ก
messaging().onNotificationOpenedApp(remoteMessage => {
// ์๋ฆผ ํด๋ฆญ ์ด๋ฒคํธ ๊ธฐ๋ก
analytics().logEvent('notification_opened', {
notification_id: remoteMessage.messageId,
notification_type: remoteMessage.data?.type || 'unknown',
timestamp: Date.now()
});
// ๋ฅ๋งํฌ ์ฒ๋ฆฌ ๋ก์ง...
});
// ํน์ ํ๋ฉด์์ ์ ํ ์๋ฃ ์ ์ด๋ฒคํธ ๊ธฐ๋ก
function logNotificationConversion(notificationId, conversionType) {
analytics().logEvent('notification_conversion', {
notification_id: notificationId,
conversion_type: conversionType,
timestamp: Date.now()
});
}
ํธ์ ์๋ฆผ์ ์ฌ์ฉ์์ ์ฑ์ ์ฐ๊ฒฐํ๋ ๊ฐ๋ ฅํ ๋ค๋ฆฌ ์ญํ ์ ํด. ํนํ ์ฌ๋ฅ๋ท๊ณผ ๊ฐ์ ํ๋ซํผ์์๋ ์ฌ์ฉ์ ๊ฐ์ ์ํต๊ณผ ๊ฑฐ๋๋ฅผ ์ด์งํ๋ ์ค์ํ ๋๊ตฌ๊ฐ ๋ ์ ์์ด. ํ์ง๋ง ํญ์ ๊ธฐ์ตํด์ผ ํ ๊ฒ์ "๋ ๋ณด๋ด๋ ๊ฒ์ด ๋ ํจ๊ณผ์ ์ผ ์ ์๋ค"๋ ์ ์ด์ผ. ์ ๋ง ์ค์ํ๊ณ ๊ด๋ จ์ฑ ๋์ ์๋ฆผ๋ง ์ ๋ณ์ ์ผ๋ก ๋ณด๋ด์ ์ฌ์ฉ์์ ์ ๋ขฐ๋ฅผ ์ป๋ ๊ฒ์ด ์ฅ๊ธฐ์ ์ผ๋ก ๋ ํฐ ์ฑ๊ณต์ ๊ฐ์ ธ์ฌ ๊ฑฐ์ผ! ๐
10. ์์ฃผ ๋ฐ์ํ๋ ๋ฌธ์ ์ ํด๊ฒฐ ๋ฐฉ๋ฒ ๐ง
ํธ์ ์๋ฆผ์ ๊ตฌํํ๋ค ๋ณด๋ฉด ๋ค์ํ ๋ฌธ์ ์ ๋ถ๋ชํ ์ ์์ด. ์ฌ๋ฌ ์์คํ ๊ณผ ํ๋ซํผ์ด ๊ด๋ จ๋์ด ์๊ธฐ ๋๋ฌธ์ ๋ฌธ์ ํด๊ฒฐ์ด ๋ณต์กํ ์ ์์ง๋ง, ๋๋ถ๋ถ์ ๋ฌธ์ ๋ ๋ช ๊ฐ์ง ์ผ๋ฐ์ ์ธ ํจํด์ ์ํด. ๋ง์น ์๋์ฐจ ๊ณ ์ฅ์ ๋๋ถ๋ถ์ด ๋ช ๊ฐ์ง ์ฃผ์ ๋ถํ์์ ๋ฐ์ํ๋ ๊ฒ์ฒ๋ผ ๋ง์ด์ผ. ์ด ์น์ ์์๋ ๊ฐ์ฅ ํํ ๋ฐ์ํ๋ ๋ฌธ์ ์ ๊ทธ ํด๊ฒฐ ๋ฐฉ๋ฒ์ ์์๋ณผ๊ฒ! ๐ ๏ธ
๋ฌธ์ 1: FCM ํ ํฐ์ด ์์ฑ๋์ง ์๊ฑฐ๋ ์ ๋ฐ์ดํธ๋์ง ์๋ ๋ฌธ์
์ฆ์: FCM ํ ํฐ์ ๊ฐ์ ธ์ค๋ ค๊ณ ํ ๋ null์ด ๋ฐํ๋๊ฑฐ๋, ํ ํฐ์ด ์์ฑ๋์์ง๋ง ์๋ฒ์ ์ ๋๋ก ์ ์ฅ๋์ง ์๋ ๋ฌธ์ .
ํด๊ฒฐ ๋ฐฉ๋ฒ:
- Firebase ์ค์ ํ์ผ(google-services.json, GoogleService-Info.plist)์ด ์ฌ๋ฐ๋ฅธ ์์น์ ์๋์ง ํ์ธ
- Firebase ํ๋ก์ ํธ ์ค์ ์ด ์ฌ๋ฐ๋ฅธ์ง ํ์ธ (์ฑ ID, ํจํค์ง ์ด๋ฆ ๋ฑ)
- ๋คํธ์ํฌ ์ฐ๊ฒฐ ์ํ ํ์ธ
- ํ ํฐ ์์ฑ ๋ก์ง์ ์ค๋ฅ๊ฐ ์๋์ง ํ์ธ
// FCM ํ ํฐ ์์ฑ ๋ฐ ์ ์ฅ ๋ก์ง ๊ฐ์
import messaging from '@react-native-firebase/messaging';
import AsyncStorage from '@react-native-async-storage/async-storage';
async function getFCMToken() {
try {
// ์ ์ฅ๋ ํ ํฐ์ด ์๋์ง ํ์ธ
const savedToken = await AsyncStorage.getItem('fcmToken');
// ์ ํ ํฐ ๊ฐ์ ธ์ค๊ธฐ
const fcmToken = await messaging().getToken();
if (!fcmToken) {
throw new Error('FCM ํ ํฐ์ ๊ฐ์ ธ์ฌ ์ ์์ต๋๋ค.');
}
// ํ ํฐ์ด ๋ณ๊ฒฝ๋์๊ฑฐ๋ ์ ์ฅ๋ ํ ํฐ์ด ์๋ ๊ฒฝ์ฐ์๋ง ์๋ฒ์ ์
๋ฐ์ดํธ
if (!savedToken || savedToken !== fcmToken) {
console.log('FCM ํ ํฐ ์
๋ฐ์ดํธ:', fcmToken);
// ํ ํฐ์ ๋ก์ปฌ์ ์ ์ฅ
await AsyncStorage.setItem('fcmToken', fcmToken);
// ์๋ฒ์ ํ ํฐ ์
๋ฐ์ดํธ
const response = await fetch('https://your-api.com/update-token', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
userId: 'current-user-id',
token: fcmToken,
platform: Platform.OS
}),
});
if (!response.ok) {
throw new Error('์๋ฒ์ ํ ํฐ์ ์
๋ฐ์ดํธํ์ง ๋ชปํ์ต๋๋ค.');
}
}
return fcmToken;
} catch (error) {
console.error('FCM ํ ํฐ ์ฒ๋ฆฌ ์ค ์ค๋ฅ:', error);
// ์ค๋ฅ ๋ก๊น
๋๋ ๋ถ์ ์๋น์ค์ ๋ณด๊ณ
return null;
}
}
๋ฌธ์ 2: iOS์์ ํธ์ ์๋ฆผ์ด ์์ ๋์ง ์๋ ๋ฌธ์
์ฆ์: Android์์๋ ์๋ฆผ์ด ์ ์๋ํ์ง๋ง iOS์์๋ ์๋ฆผ์ด ์ ํ ์์ ๋์ง ์๋ ๋ฌธ์ .
ํด๊ฒฐ ๋ฐฉ๋ฒ:
- APNs ์ธ์ฆ์๊ฐ ์ ํจํ์ง ํ์ธ (๋ง๋ฃ๋์์ ์ ์์)
- Xcode์์ Push Notifications Capability๊ฐ ํ์ฑํ๋์ด ์๋์ง ํ์ธ
- ์ฌ์ฉ์๊ฐ ์๋ฆผ ๊ถํ์ ํ์ฉํ๋์ง ํ์ธ
- ๊ฐ๋ฐ/ํ๋ก๋์ ํ๊ฒฝ์ ๋ง๋ APNs ์ค์ ์ ์ฌ์ฉํ๊ณ ์๋์ง ํ์ธ
- AppDelegate.m์ ํ์ํ ์ฝ๋๊ฐ ๋ชจ๋ ๊ตฌํ๋์ด ์๋์ง ํ์ธ
// iOS ์๋ฆผ ๊ถํ ์์ฒญ ๋ฐ ํ์ธ ๋ก์ง
import { Platform, Alert } from 'react-native';
import messaging from '@react-native-firebase/messaging';
import { openSettings } from 'react-native-permissions';
async function checkAndRequestNotificationPermission() {
if (Platform.OS !== 'ios') return true;
try {
const authStatus = await messaging().hasPermission();
if (authStatus === messaging.AuthorizationStatus.NOT_DETERMINED) {
// ๊ถํ ์์ฒญ
const newStatus = await messaging().requestPermission();
return newStatus === messaging.AuthorizationStatus.AUTHORIZED ||
newStatus === messaging.AuthorizationStatus.PROVISIONAL;
}
if (authStatus === messaging.AuthorizationStatus.DENIED) {
// ์ฌ์ฉ์์๊ฒ ์ค์ ์ผ๋ก ์ด๋ํ์ฌ ๊ถํ์ ํ์ฑํํ๋๋ก ์๋ด
Alert.alert(
'์๋ฆผ ๊ถํ ํ์',
'์ฑ์ ์ค์ํ ์๋ฆผ์ ๋ฐ์ผ๋ ค๋ฉด ์๋ฆผ ๊ถํ์ด ํ์ํฉ๋๋ค. ์ค์ ์์ ์๋ฆผ์ ํ์ฑํํด์ฃผ์ธ์.',
[
{ text: '๋์ค์', style: 'cancel' },
{ text: '์ค์ ์ผ๋ก ์ด๋', onPress: () => openSettings() }
]
);
return false;
}
return authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
authStatus === messaging.AuthorizationStatus.PROVISIONAL;
} catch (error) {
console.error('์๋ฆผ ๊ถํ ํ์ธ ์ค ์ค๋ฅ:', error);
return false;
}
}
๋ฌธ์ 3: ์๋ฆผ์ ์์ ๋์ง๋ง ํด๋ฆญํด๋ ์ฑ์ด ์ด๋ฆฌ์ง ์๊ฑฐ๋ ํน์ ํ๋ฉด์ผ๋ก ์ด๋ํ์ง ์๋ ๋ฌธ์
์ฆ์: ํธ์ ์๋ฆผ์ ์ ์์ ์ผ๋ก ์์ ๋์ง๋ง, ์๋ฆผ์ ํด๋ฆญํด๋ ์ฑ์ด ์ด๋ฆฌ์ง ์๊ฑฐ๋ ํน์ ํ๋ฉด์ผ๋ก ์ด๋ํ์ง ์๋ ๋ฌธ์ .
ํด๊ฒฐ ๋ฐฉ๋ฒ:
- Android์์ Intent ํํฐ๊ฐ ์ฌ๋ฐ๋ฅด๊ฒ ์ค์ ๋์๋์ง ํ์ธ
- ์๋ฆผ ํด๋ฆญ ํธ๋ค๋ฌ๊ฐ ์ ๋๋ก ๊ตฌํ๋์๋์ง ํ์ธ
- ๋ฅ๋งํฌ ์ฒ๋ฆฌ ๋ก์ง์ ์ค๋ฅ๊ฐ ์๋์ง ํ์ธ
- ์๋ฆผ ํ์ด๋ก๋์ ํ์ํ ๋ฐ์ดํฐ๊ฐ ํฌํจ๋์ด ์๋์ง ํ์ธ
// ์๋ฆผ ํด๋ฆญ ์ฒ๋ฆฌ ๋ฐ ๋ฅ๋งํฌ ๊ตฌํ ๊ฐ์
import React, { useEffect } from 'react';
import { Platform } from 'react-native';
import messaging from '@react-native-firebase/messaging';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
const Stack = createStackNavigator();
const navigationRef = React.createRef();
// ๋ฅ๋งํฌ ๋ค๋น๊ฒ์ด์
ํจ์
function navigate(name, params) {
if (navigationRef.current) {
navigationRef.current.navigate(name, params);
} else {
// ๋ค๋น๊ฒ์ด์
์ด ์ค๋น๋์ง ์์ ๊ฒฝ์ฐ๋ฅผ ์ํ ๋๊ธฐ ๋ก์ง
setTimeout(() => {
navigate(name, params);
}, 500);
}
}
// ์๋ฆผ ๋ฐ์ดํฐ ์ฒ๋ฆฌ ํจ์
function handleNotificationData(data) {
if (!data) return;
console.log('์๋ฆผ ๋ฐ์ดํฐ ์ฒ๋ฆฌ:', data);
try {
switch (data.type) {
case 'chat':
navigate('ChatScreen', { chatId: data.chatId, userId: data.senderId });
break;
case 'transaction':
navigate('TransactionDetails', { transactionId: data.transactionId });
break;
case 'profile':
navigate('UserProfile', { userId: data.userId });
break;
default:
// ๊ธฐ๋ณธ์ ์ผ๋ก ํ ํ๋ฉด์ผ๋ก ์ด๋
navigate('Home');
}
} catch (error) {
console.error('์๋ฆผ ๋ฐ์ดํฐ ์ฒ๋ฆฌ ์ค ์ค๋ฅ:', error);
}
}
function App() {
useEffect(() => {
// ์ฑ์ด ์ข
๋ฃ๋ ์ํ์์ ์๋ฆผ์ผ๋ก ์ด๋ ธ์ ๋
messaging()
.getInitialNotification()
.then(remoteMessage => {
if (remoteMessage) {
console.log('์ข
๋ฃ ์ํ์์ ์๋ฆผ์ผ๋ก ์ฑ ์คํ:', remoteMessage);
// ์ฝ๊ฐ์ ์ง์ฐ์ ๋์ด ๋ค๋น๊ฒ์ด์
์ด ์ค๋น๋๋๋ก ํจ
setTimeout(() => {
handleNotificationData(remoteMessage.data);
}, 1000);
}
})
.catch(error => {
console.error('์ด๊ธฐ ์๋ฆผ ์ฒ๋ฆฌ ์ค ์ค๋ฅ:', error);
});
// ๋ฐฑ๊ทธ๋ผ์ด๋์์ ์๋ฆผ ํด๋ฆญ์ผ๋ก ์ฑ์ด ์ด๋ ธ์ ๋
const unsubscribe = messaging().onNotificationOpenedApp(remoteMessage => {
console.log('๋ฐฑ๊ทธ๋ผ์ด๋์์ ์๋ฆผ ํด๋ฆญ:', remoteMessage);
handleNotificationData(remoteMessage.data);
});
return unsubscribe;
}, []);
return (
<NavigationContainer ref={navigationRef}>
<Stack.Navigator>
{/* ํ๋ฉด ์ ์ */}
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="ChatScreen" component={ChatScreen} />
<Stack.Screen name="TransactionDetails" component={TransactionDetails} />
<Stack.Screen name="UserProfile" component={UserProfile} />
</Stack.Navigator>
</NavigationContainer>
);
}
๋ฌธ์ 4: ํน์ ๊ธฐ๊ธฐ์์๋ง ์๋ฆผ์ด ์๋ํ์ง ์๋ ๋ฌธ์
์ฆ์: ์ผ๋ถ ๊ธฐ๊ธฐ์์๋ ์๋ฆผ์ด ์ ์์ ์ผ๋ก ์๋ํ์ง๋ง, ํน์ ๊ธฐ๊ธฐ์์๋ง ์๋ฆผ์ด ์์ ๋์ง ์๋ ๋ฌธ์ .
ํด๊ฒฐ ๋ฐฉ๋ฒ:
- ๊ธฐ๊ธฐ๋ณ ๋ฐฐํฐ๋ฆฌ ์ต์ ํ ์ค์ ํ์ธ (ํนํ ์ค๊ตญ ์ ์กฐ์ฌ ๊ธฐ๊ธฐ)
- ๊ธฐ๊ธฐ์ OS ๋ฒ์ ์ ๋ฐ๋ฅธ ํธํ์ฑ ๋ฌธ์ ํ์ธ
- ํด๋น ๊ธฐ๊ธฐ์ FCM ํ ํฐ์ด ์ฌ๋ฐ๋ฅด๊ฒ ๋ฑ๋ก๋์๋์ง ํ์ธ
- ๊ธฐ๊ธฐ๋ณ ํน์ ๊ถํ ์ค์ ํ์ธ (์: MIUI์ ์๋ ์์ ๊ถํ)
// ๊ธฐ๊ธฐ๋ณ ์ต์ ํ ์ค์ ์๋ด ๊ตฌํ
import { Platform, Alert, Linking } from 'react-native';
import DeviceInfo from 'react-native-device-info';
async function checkDeviceOptimizationSettings() {
if (Platform.OS !== 'android') return;
try {
const manufacturer = await DeviceInfo.getManufacturer();
const model = await DeviceInfo.getModel();
// ํน์ ์ ์กฐ์ฌ ๊ธฐ๊ธฐ์ ๋ํ ํน๋ณ ์ฒ๋ฆฌ
if (manufacturer.toLowerCase().includes('xiaomi') ||
manufacturer.toLowerCase().includes('redmi') ||
manufacturer.toLowerCase().includes('poco')) {
Alert.alert(
'์๋ฆผ ์ค์ ํ์ธ',
'์ค์ค๋ฏธ ๊ธฐ๊ธฐ์์๋ ์๋ฆผ์ ๋ฐ๊ธฐ ์ํด ์ถ๊ฐ ์ค์ ์ด ํ์ํ ์ ์์ต๋๋ค. ๋ฐฐํฐ๋ฆฌ ์ค์ ์์ ์ฑ์ ์๋ ์์ ๊ถํ๊ณผ ๋ฐฐํฐ๋ฆฌ ์ ํ์ ํด์ ํด์ฃผ์ธ์.',
[
{ text: '๋์ค์', style: 'cancel' },
{
text: '์ค์ ์ผ๋ก ์ด๋',
onPress: () => Linking.openSettings()
}
]
);
} else if (manufacturer.toLowerCase().includes('huawei') ||
manufacturer.toLowerCase().includes('honor')) {
Alert.alert(
'์๋ฆผ ์ค์ ํ์ธ',
'ํ์จ์ด ๊ธฐ๊ธฐ์์๋ ์๋ฆผ์ ๋ฐ๊ธฐ ์ํด ์ถ๊ฐ ์ค์ ์ด ํ์ํ ์ ์์ต๋๋ค. ๋ฐฐํฐ๋ฆฌ ์ค์ ์์ ์ฑ์ "๋ณดํธ๋ ์ฑ"์ผ๋ก ์ค์ ํ๊ณ , ์ฑ ์์ ๊ด๋ฆฌ์์ ์๋ ์์์ ํ์ฉํด์ฃผ์ธ์.',
[
{ text: '๋์ค์', style: 'cancel' },
{
text: '์ค์ ์ผ๋ก ์ด๋',
onPress: () => Linking.openSettings()
}
]
);
} else if (manufacturer.toLowerCase().includes('oppo') ||
manufacturer.toLowerCase().includes('oneplus') ||
manufacturer.toLowerCase().includes('realme') ||
manufacturer.toLowerCase().includes('vivo')) {
Alert.alert(
'์๋ฆผ ์ค์ ํ์ธ',
'์ด ๊ธฐ๊ธฐ์์๋ ์๋ฆผ์ ๋ฐ๊ธฐ ์ํด ์ถ๊ฐ ์ค์ ์ด ํ์ํ ์ ์์ต๋๋ค. ๋ฐฐํฐ๋ฆฌ ์ค์ ์์ ์ฑ์ ๋ฐฑ๊ทธ๋ผ์ด๋ ์คํ ๊ถํ์ ํ์ฉํด์ฃผ์ธ์.',
[
{ text: '๋์ค์', style: 'cancel' },
{
text: '์ค์ ์ผ๋ก ์ด๋',
onPress: () => Linking.openSettings()
}
]
);
}
// ๋ก๊น
์ ์ํด ๊ธฐ๊ธฐ ์ ๋ณด ๊ธฐ๋ก
console.log('๊ธฐ๊ธฐ ์ ๋ณด:', { manufacturer, model });
} catch (error) {
console.error('๊ธฐ๊ธฐ ์ ๋ณด ํ์ธ ์ค ์ค๋ฅ:', error);
}
}
๋ฌธ์ 5: ์๋ฆผ ์คํ์ผ์ด๋ ์๋ฆฌ๊ฐ ์์๊ณผ ๋ค๋ฅธ ๋ฌธ์
์ฆ์: ์๋ฆผ์ ์์ ๋์ง๋ง ์คํ์ผ, ์๋ฆฌ, ์ง๋ ๋ฑ์ด ์์๊ณผ ๋ค๋ฅด๊ฒ ํ์๋๋ ๋ฌธ์ .
ํด๊ฒฐ ๋ฐฉ๋ฒ:
- Android์์ ์๋ฆผ ์ฑ๋ ์ค์ ํ์ธ
- ์๋ฆผ ํ์ด๋ก๋์ ์คํ์ผ ๊ด๋ จ ์์ฑ์ด ์ฌ๋ฐ๋ฅด๊ฒ ์ค์ ๋์๋์ง ํ์ธ
- ๊ธฐ๊ธฐ์ ์๋ฆฌ/์ง๋ ์ค์ ํ์ธ
- OS ๋ฒ์ ์ ๋ฐ๋ฅธ ์๋ฆผ ์คํ์ผ ์ฐจ์ด ๊ณ ๋ ค
// ์๋ฆผ ์ฑ๋ ์ค์ ๊ฐ์
import { Platform } from 'react-native';
import notifee, { AndroidImportance, AndroidVisibility } from '@notifee/react-native';
async function setupNotificationChannels() {
if (Platform.OS !== 'android') return;
try {
// ์ค์ ์๋ฆผ ์ฑ๋
await notifee.createChannel({
id: 'important',
name: '์ค์ ์๋ฆผ',
description: '์ค์ํ ๋ฉ์์ง์ ์
๋ฐ์ดํธ๋ฅผ ์ํ ์ฑ๋',
importance: AndroidImportance.HIGH,
sound: 'notification_sound', // res/raw/notification_sound.mp3
vibration: true,
vibrationPattern: [300, 500, 300, 500],
lights: true,
lightColor: '#FF0000',
visibility: AndroidVisibility.PUBLIC,
});
// ์ฑํ
์๋ฆผ ์ฑ๋
await notifee.createChannel({
id: 'chat',
name: '์ฑํ
๋ฉ์์ง',
description: '์ฑํ
๋ฉ์์ง๋ฅผ ์ํ ์ฑ๋',
importance: AndroidImportance.HIGH,
sound: 'chat_sound', // res/raw/chat_sound.mp3
vibration: true,
vibrationPattern: [100, 200, 100, 200],
lights: true,
lightColor: '#00FF00',
visibility: AndroidVisibility.PRIVATE,
});
// ์ผ๋ฐ ์๋ฆผ ์ฑ๋
await notifee.createChannel({
id: 'default',
name: '์ผ๋ฐ ์๋ฆผ',
description: '์ผ๋ฐ์ ์ธ ์ ๋ณด ์๋ฆผ์ ์ํ ์ฑ๋',
importance: AndroidImportance.DEFAULT,
sound: 'default',
vibration: true,
visibility: AndroidVisibility.PRIVATE,
});
// ๋ง์ผํ
์๋ฆผ ์ฑ๋
await notifee.createChannel({
id: 'marketing',
name: '๋ง์ผํ
์๋ฆผ',
description: 'ํ๋ก๋ชจ์
๊ณผ ๋ง์ผํ
๋ฉ์์ง๋ฅผ ์ํ ์ฑ๋',
importance: AndroidImportance.LOW,
sound: false,
vibration: false,
visibility: AndroidVisibility.PRIVATE,
});
console.log('์๋ฆผ ์ฑ๋ ์ค์ ์๋ฃ');
} catch (error) {
console.error('์๋ฆผ ์ฑ๋ ์ค์ ์ค ์ค๋ฅ:', error);
}
}
// ์๋ฆผ ํ์ ํจ์
async function displayNotification(channelId, title, body, data = {}) {
try {
// ์ฑ๋ ID์ ๋ฐ๋ผ ๋ค๋ฅธ ์คํ์ผ ์ ์ฉ
let androidConfig = {
channelId,
pressAction: {
id: 'default',
},
};
// ์ฑํ
์๋ฆผ์ธ ๊ฒฝ์ฐ ํน๋ณํ ์คํ์ผ ์ ์ฉ
if (channelId === 'chat') {
androidConfig = {
...androidConfig,
style: {
type: 1, // BigText style
text: body,
},
actions: [
{
title: '๋ต์ฅ',
pressAction: {
id: 'reply',
},
},
{
title: '์ฝ์',
pressAction: {
id: 'mark_as_read',
},
},
],
};
}
await notifee.displayNotification({
title,
body,
data,
android: androidConfig,
ios: {
sound: channelId === 'marketing' ? null : 'default',
categoryId: channelId === 'chat' ? 'chat' : 'default',
},
});
} catch (error) {
console.error('์๋ฆผ ํ์ ์ค ์ค๋ฅ:', error);
}
}
ํธ์ ์๋ฆผ ๊ตฌํ ๊ณผ์ ์์ ๋ฌธ์ ๊ฐ ๋ฐ์ํ๋ ๊ฒ์ ์์ฐ์ค๋ฌ์ด ์ผ์ด์ผ. ์ฌ๋ฌ ์์คํ ๊ณผ ํ๋ซํผ์ด ๊ด๋ จ๋์ด ์๊ธฐ ๋๋ฌธ์ ๋๋ฒ๊น ์ด ๋ณต์กํ ์ ์์ง๋ง, ์์์ ์ค๋ช ํ ์ผ๋ฐ์ ์ธ ๋ฌธ์ ์ ํด๊ฒฐ ๋ฐฉ๋ฒ์ ์ฐธ๊ณ ํ๋ฉด ๋๋ถ๋ถ์ ์ด์๋ฅผ ํด๊ฒฐํ ์ ์์ ๊ฑฐ์ผ. ํนํ ์ฌ๋ฅ๋ท๊ณผ ๊ฐ์ ์๋น์ค์์๋ ํธ์ ์๋ฆผ์ด ์ฌ์ฉ์ ์ฐธ์ฌ์ ์ค์ํ ์ญํ ์ ํ๊ธฐ ๋๋ฌธ์, ๋ชจ๋ ์ฌ์ฉ์๊ฐ ์๋ฆผ์ ์ ๋๋ก ๋ฐ์ ์ ์๋๋ก ์ฒ ์ ํ ํ ์คํธํ๊ณ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ๊ฒ์ด ์ค์ํด! ๐
๊ฒฐ๋ก : ํธ์ ์๋ฆผ์ผ๋ก ์ฑ์ ๊ฐ์น๋ฅผ ๋์ด์ ๐
์ง๊ธ๊น์ง React Native์์ ํธ์ ์๋ฆผ์ ๊ตฌํํ๋ ๋ฐฉ๋ฒ์ ๋ํด ์์ธํ ์์๋ดค์ด. ํธ์ ์๋ฆผ์ ๋จ์ํ ๊ธฐ๋ฅ์ด ์๋๋ผ ์ฌ์ฉ์์ ์ฑ์ ์ฐ๊ฒฐํ๋ ๊ฐ๋ ฅํ ์ํต ์ฑ๋์ด์ผ. ํนํ ์ฌ๋ฅ๋ท๊ณผ ๊ฐ์ ํ๋ซํผ์์๋ ์ฌ์ฉ์ ๊ฐ์ ์ํต๊ณผ ๊ฑฐ๋๋ฅผ ์ด์งํ๋ ํต์ฌ ์์๊ฐ ๋ ์ ์์ง.
ํต์ฌ ์์ฝ
- ํธ์ ์๋ฆผ์ ์ฑ ์ฐธ์ฌ๋์ ์ฌ์ฉ์ ์ ์ง์จ์ ๋์ด๋ ํจ๊ณผ์ ์ธ ๋๊ตฌ
- Firebase Cloud Messaging(FCM)์ ํตํด iOS์ Android ๋ชจ๋ ์ง์ ๊ฐ๋ฅ
- react-native-push-notification ๋๋ @react-native-firebase/messaging ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ก ๊ตฌํ ๊ฐ๋ฅ
- ๊ฐ์ธํ๋ ์ฝํ ์ธ ์ ์ ์ ํ ํ์ด๋ฐ์ด ํธ์ ์๋ฆผ์ ์ฑ๊ณต ์ด์
- ์ฌ์ฉ์์๊ฒ ์๋ฆผ ์ค์ ์ ์ด๊ถ์ ์ ๊ณตํ๋ ๊ฒ์ด ์ค์
- ์ฒด๊ณ์ ์ธ ํ ์คํธ์ ๋๋ฒ๊น ์ผ๋ก ๋ชจ๋ ์ฌ์ฉ์์๊ฒ ์๋ฆผ์ด ์ ๋๋ก ์ ๋ฌ๋๋๋ก ํด์ผ ํจ
ํธ์ ์๋ฆผ์ ๊ตฌํํ ๋๋ ๊ธฐ์ ์ ์ธ ์ธก๋ฉด๋ฟ๋ง ์๋๋ผ ์ฌ์ฉ์ ๊ฒฝํ๊ณผ ๋น์ฆ๋์ค ๋ชฉํ๋ ํจ๊ป ๊ณ ๋ คํด์ผ ํด. ๋๋ฌด ๋ง์ ์๋ฆผ์ ์ฌ์ฉ์๋ฅผ ์ง์ฆ๋๊ฒ ๋ง๋ค ์ ์์ง๋ง, ์ ์ ํ ์๊ฐ์ ๊ฐ์น ์๋ ์ ๋ณด๋ฅผ ์ ๋ฌํ๋ ์๋ฆผ์ ์ฌ์ฉ์ ์ถฉ์ฑ๋๋ฅผ ๋์ด๊ณ ์ฑ์ ์ฑ๊ณต์ ๊ธฐ์ฌํ ์ ์์ด.
์ฌ๋ฅ๋ท์์๋ ์๋ก์ด ๋ฉ์์ง ์๋ฆผ, ๊ฑฐ๋ ์ํ ์ ๋ฐ์ดํธ, ๋ง์ถคํ ์ฌ๋ฅ ์ถ์ฒ ๋ฑ ๋ค์ํ ๋ฐฉ์์ผ๋ก ํธ์ ์๋ฆผ์ ํ์ฉํ ์ ์์ ๊ฑฐ์ผ. ์ด๋ฅผ ํตํด ์ฌ์ฉ์๋ค์ด ํ๋ซํผ์ ๋ ์์ฃผ ๋ฐฉ๋ฌธํ๊ณ , ๋ ๋ง์ ๊ฑฐ๋๊ฐ ์ด๋ฃจ์ด์ง๋๋ก ์ ๋ํ ์ ์์ด.
๋ง์ง๋ง์ผ๋ก, ํธ์ ์๋ฆผ ๊ตฌํ์ ํ ๋ฒ์ ๋๋๋ ์์ ์ด ์๋๋ผ ์ง์์ ์ธ ๊ฐ์ ๊ณผ ์ต์ ํ๊ฐ ํ์ํ ๊ณผ์ ์ด๋ผ๋ ์ ์ ๊ธฐ์ตํ์. ์ฌ์ฉ์ ํผ๋๋ฐฑ์ ์์งํ๊ณ , ์๋ฆผ ์ฑ๊ณผ๋ฅผ ์ธก์ ํ๋ฉฐ, ์๋ก์ด ๊ธฐ๋ฅ๊ณผ ํ๋ซํผ ๋ณํ์ ๋ง์ถฐ ๊ณ์ ๋ฐ์ ์์ผ ๋๊ฐ๋ ๊ฒ์ด ์ค์ํด.
์ด ๊ธ์ด React Native์์ ํธ์ ์๋ฆผ์ ๊ตฌํํ๋ ๋ฐ ๋์์ด ๋์๊ธธ ๋ฐ๋ผ! ๋ ๋ง์ ๊ฐ๋ฐ ์ ๋ณด์ ํ์ ์ฌ๋ฅ๋ท์ ์ง์์ธ์ ์ฒ์์ ์ฐพ์๋ณผ ์ ์์ด. ํจ๊ป ๋ ๋์ ์ฑ์ ๋ง๋ค์ด ๋๊ฐ์! ๐
๊ด๋ จ ํค์๋
๋๊ธ ์์ฑ
์ด ๊ธ์ ๋ํ ์ฌ๋ฌ๋ถ์ ์๊ฐ์ ๋ค๋ ค์ฃผ์ธ์
๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค
๋๊ธ์ ์์ฑํ๋ ค๋ฉด ๋จผ์ ๋ก๊ทธ์ธํด์ฃผ์ธ์.
๋๊ธ 0
์ง์์ธ์ ์ฒ - ์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
- ์ ์๊ถ ๋ฐ ์์ ๊ถ: ๋ณธ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ๋ ์ AI ๊ธฐ์ ๋ก ์์ฑ๋์์ผ๋ฉฐ, ๋ํ๋ฏผ๊ตญ ์ ์๊ถ๋ฒ ๋ฐ ๊ตญ์ ์ ์๊ถ ํ์ฝ์ ์ํด ๋ณดํธ๋ฉ๋๋ค.
- AI ์์ฑ ์ปจํ ์ธ ์ ๋ฒ์ ์ง์: ๋ณธ AI ์์ฑ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ์ง์ ์ฐฝ์๋ฌผ๋ก ์ธ์ ๋๋ฉฐ, ๊ด๋ จ ๋ฒ๊ท์ ๋ฐ๋ผ ์ ์๊ถ ๋ณดํธ๋ฅผ ๋ฐ์ต๋๋ค.
- ์ฌ์ฉ ์ ํ: ์ฌ๋ฅ๋ท์ ๋ช ์์ ์๋ฉด ๋์ ์์ด ๋ณธ ์ปจํ ์ธ ๋ฅผ ๋ณต์ , ์์ , ๋ฐฐํฌ, ๋๋ ์์ ์ ์ผ๋ก ํ์ฉํ๋ ํ์๋ ์๊ฒฉํ ๊ธ์ง๋ฉ๋๋ค.
- ๋ฐ์ดํฐ ์์ง ๊ธ์ง: ๋ณธ ์ปจํ ์ธ ์ ๋ํ ๋ฌด๋จ ์คํฌ๋ํ, ํฌ๋กค๋ง, ๋ฐ ์๋ํ๋ ๋ฐ์ดํฐ ์์ง์ ๋ฒ์ ์ ์ฌ์ ๋์์ด ๋ฉ๋๋ค.
- AI ํ์ต ์ ํ: ์ฌ๋ฅ๋ท์ AI ์์ฑ ์ปจํ ์ธ ๋ฅผ ํ AI ๋ชจ๋ธ ํ์ต์ ๋ฌด๋จ ์ฌ์ฉํ๋ ํ์๋ ๊ธ์ง๋๋ฉฐ, ์ด๋ ์ง์ ์ฌ์ฐ๊ถ ์นจํด๋ก ๊ฐ์ฃผ๋ฉ๋๋ค.
์์ง ๋๊ธ์ด ์์ต๋๋ค.