Skip to content

Commit

Permalink
Merge pull request #7 from gloddy-dev/feature/5-firebase-push
Browse files Browse the repository at this point in the history
Feature/5 : firebase push 알림 구현
  • Loading branch information
guesung authored Oct 27, 2023
2 parents 449625e + 59dd623 commit 1a295e4
Show file tree
Hide file tree
Showing 15 changed files with 540 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "interactive"
"java.configuration.updateBuildConfiguration": "automatic"
}
32 changes: 32 additions & 0 deletions App.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import AsyncStorage from '@react-native-async-storage/async-storage';
import React, {useEffect, useRef, useState} from 'react';
import {
Alert,
Animated,
AppRegistry,
BackHandler,
Dimensions,
Image,
Expand All @@ -28,6 +30,19 @@ import Text1SVG from './image/text1.svg';
import Text1enSVG from './image/text1en.svg';
import Text2SVG from './image/text2.svg';
import Text2enSVG from './image/text2en.svg';
import messaging from '@react-native-firebase/messaging';

// Firebase 알림
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);
}
}

const deviceWidth = Dimensions.get('window').width;

Expand All @@ -46,6 +61,22 @@ export default function App() {
const [webloading, setwebloading] = useState(true);
const [showindex, setshowindex] = useState(true);

// 앱이 Foreground 인 상태에서 푸쉬알림 받는 코드 작성
useEffect(() => {
const unsubscribe = messaging().onMessage(async remoteMessage => {
Alert.alert('A new FCM message arrived!', JSON.stringify(remoteMessage));
});

return unsubscribe;
}, []);

// 앱이 Background 이거나 꺼진 상태에서 푸쉬알림 받는 코드 작성
messaging().setBackgroundMessageHandler(async remoteMessage => {
console.log('Message handled in the background!', remoteMessage);
});

AppRegistry.registerComponent('app', () => App);

const onShouldStartLoadWithRequest = event => {
if (!event.url.includes(SOURCE_URL)) {
Linking.openURL(event.url);
Expand Down Expand Up @@ -129,6 +160,7 @@ export default function App() {
await request(PERMISSIONS.IOS.CAMERA);
await request(PERMISSIONS.IOS.MICROPHONE);
await request(PERMISSIONS.IOS.PHOTO_LIBRARY);
await requestUserPermission();
};
requestPhotoLibraryPermission();
}
Expand Down
5 changes: 4 additions & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
apply plugin: "com.android.application"
apply plugin: 'com.google.gms.google-services' // <- 추가
apply plugin: "com.facebook.react"

/**
* This is the configuration block to customize your React Native Android app.
* By default you don't need to apply any configuration, just uncomment the lines you need.
* By default you don't need tox apply any configuration, just uncomment the lines you need.
*/
react {
/* Folders */
Expand Down Expand Up @@ -120,6 +121,8 @@ dependencies {
exclude group:'com.squareup.okhttp3', module:'okhttp'
}

// Add the SDK for Firebase Cloud Messaging
implementation 'com.google.firebase:firebase-messaging:18.5.0'
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}")
if (hermesEnabled.toBoolean()) {
implementation("com.facebook.react:hermes-android")
Expand Down
40 changes: 40 additions & 0 deletions android/app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"project_info": {
"project_number": "743260252436",
"firebase_url": "https://guesung-exerciseinformation-default-rtdb.firebaseio.com",
"project_id": "guesung-exerciseinformation",
"storage_bucket": "guesung-exerciseinformation.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:743260252436:android:ccaa2482e4a8041d7b7a01",
"android_client_info": {
"package_name": "com.goodcode.gloddy"
}
},
"oauth_client": [
{
"client_id": "743260252436-eufmd05v8gu3he9qtjmlmjea6gmeilie.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyAo42iXV-rzCvT5YXvwQHCcqkwwdBqM6G4"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "743260252436-eufmd05v8gu3he9qtjmlmjea6gmeilie.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}
3 changes: 2 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.goodcode.gloddy">


<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION"/>
Expand Down
2 changes: 2 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ buildscript {

// We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
ndkVersion = "23.1.7779620"

}
repositories {
google()
Expand All @@ -17,5 +18,6 @@ buildscript {
dependencies {
classpath("com.android.tools.build:gradle")
classpath("com.facebook.react:react-native-gradle-plugin")
classpath('com.google.gms:google-services:4.4.0')
}
}
32 changes: 32 additions & 0 deletions ios/GoogleService-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>API_KEY</key>
<string>AIzaSyCyxtqPKS6eoyRvsSm7VNI2GHCi2ERyR4U</string>
<key>GCM_SENDER_ID</key>
<string>743260252436</string>
<key>PLIST_VERSION</key>
<string>1</string>
<key>BUNDLE_ID</key>
<string>com.goodcode.gloddy</string>
<key>PROJECT_ID</key>
<string>guesung-exerciseinformation</string>
<key>STORAGE_BUCKET</key>
<string>guesung-exerciseinformation.appspot.com</string>
<key>IS_ADS_ENABLED</key>
<false></false>
<key>IS_ANALYTICS_ENABLED</key>
<false></false>
<key>IS_APPINVITE_ENABLED</key>
<true></true>
<key>IS_GCM_ENABLED</key>
<true></true>
<key>IS_SIGNIN_ENABLED</key>
<true></true>
<key>GOOGLE_APP_ID</key>
<string>1:743260252436:ios:e52ff7c145d907397b7a01</string>
<key>DATABASE_URL</key>
<string>https://guesung-exerciseinformation-default-rtdb.firebaseio.com</string>
</dict>
</plist>
4 changes: 3 additions & 1 deletion ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : Flip
linkage = ENV['USE_FRAMEWORKS']
if linkage != nil
Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
use_frameworks! :linkage => linkage.to_sym
use_frameworks! :linkage => true
end

target 'gloddy' do
Expand All @@ -31,6 +31,8 @@ target 'gloddy' do
pod 'Permission-Camera', :path => "#{permissions_path}/Camera"
pod 'Permission-PhotoLibrary', :path => "#{permissions_path}/PhotoLibrary"
pod 'Permission-Microphone', :path => "#{permissions_path}/Microphone"
pod 'GoogleUtilities', :modular_headers => true
pod 'FirebaseCore', :modular_headers => true

# Flags change depending on the env values.
flags = get_default_flags()
Expand Down
Loading

0 comments on commit 1a295e4

Please sign in to comment.