diff --git a/src/hooks/useAppBridge.tsx b/src/hooks/useAppBridge.tsx index d796d17..117b527 100644 --- a/src/hooks/useAppBridge.tsx +++ b/src/hooks/useAppBridge.tsx @@ -53,6 +53,12 @@ interface UseAppBridgeReturn { openBiometricRegistrationPopup: () => Promise; // 간편 인증 등록 팝업 닫기 closeBiometricRegistrationPopup: () => Promise; + + // 푸시 알림 권한 확인 + isPushNotificationEnabled: () => Promise; + + // 앱 설정 화면 열기 + openAppSettings: () => Promise; } export const useAppBridge = (): UseAppBridgeReturn => { @@ -214,7 +220,7 @@ export const useAppBridge = (): UseAppBridgeReturn => { console.warn('Web Share API failed:', error); } } - + // 폴백: 클립보드에 복사 const shareText = `${content.title}\n${content.text}${content.url ? `\n${content.url}` : ''}`; if (navigator.clipboard) { @@ -225,10 +231,25 @@ export const useAppBridge = (): UseAppBridgeReturn => { } return; } - + return appBridge.safeCall(() => appBridge.shareContent(content)); }, [isNativeEnvironment]); + const isPushNotificationEnabled = useCallback(async (): Promise => { + if (!isNativeEnvironment) { + return true; + } + const result = await appBridge.safeCall(() => appBridge.isPushNotificationEnabled(), false); + return result || false; + }, [isNativeEnvironment]); + + const openAppSettings = useCallback(async (): Promise => { + if (!isNativeEnvironment) { + return; + } + return appBridge.safeCall(() => appBridge.openAppSettings()); + }, [isNativeEnvironment]); + return { isNativeEnvironment, isAndroid, @@ -249,6 +270,8 @@ export const useAppBridge = (): UseAppBridgeReturn => { requestRefreshToken, registerBiometric, openBiometricRegistrationPopup, - closeBiometricRegistrationPopup + closeBiometricRegistrationPopup, + isPushNotificationEnabled, + openAppSettings }; }; \ No newline at end of file diff --git a/src/pages/setting/setting-page.tsx b/src/pages/setting/setting-page.tsx index 0acdf24..a370e59 100644 --- a/src/pages/setting/setting-page.tsx +++ b/src/pages/setting/setting-page.tsx @@ -6,15 +6,18 @@ import { ServiceLanguageBottomSheet } from '@/entities/alarm/ui/service-language import { APP_LANGUAGE, APP_LOGIN_TYPE } from '@/entities/common/model/constant'; import { AppLanguage, HeaderType, LoginType } from '@/entities/common/model/types'; import { useStore } from '@/shared/model/store'; -import { +import { useSetHeaderTitle, useSetHeaderType, useSetFooterMode } from '@/widgets/sub-layout/use-sub-layout'; import { ChangeEvent, useEffect, useState } from 'react'; +import { useAppBridge } from '@/hooks/useAppBridge'; export const SettingPage = () => { let userInfo = useStore.getState().UserStore.userInfo; + const { isPushNotificationEnabled, openAppSettings } = useAppBridge(); + useSetHeaderTitle('설정'); useSetHeaderType(HeaderType.LeftArrow); useSetFooterMode(false); @@ -27,6 +30,7 @@ export const SettingPage = () => { const {mutateAsync: appAlarmFind} = useAppAlarmFindMutation(); const {mutateAsync: appAlarmConsent} = useAppAlarmConsentMutation(); + const [pushNotificationEnabled, setPushNotificationEnabled] = useState(false); const [alarmSetting, setAlarmSetting] = useState>({ '21': false, '11': false, @@ -40,6 +44,16 @@ export const SettingPage = () => { const onClickPrivacyPolicy = () => { window.open('https://www.nicevan.co.kr/privacy-policy', '_blank'); }; + + const checkPushNotificationStatus = () => { + isPushNotificationEnabled().then((enabled) => { + setPushNotificationEnabled(enabled); + }); + }; + + const onClickPushNotificationToggle = () => { + openAppSettings(); + }; const callAppAlarmFind = () => { if(userInfo.usrid){ @@ -88,6 +102,26 @@ export const SettingPage = () => { useEffect(() => { callAppAlarmFind(); + checkPushNotificationStatus(); + + // 앱이 포어그라운드로 돌아올 때 푸시 알림 권한 상태 재확인 + const handleVisibilityChange = () => { + if (document.visibilityState === 'visible') { + checkPushNotificationStatus(); + } + }; + + const handleFocus = () => { + checkPushNotificationStatus(); + }; + + document.addEventListener('visibilitychange', handleVisibilityChange); + window.addEventListener('focus', handleFocus); + + return () => { + document.removeEventListener('visibilitychange', handleVisibilityChange); + window.removeEventListener('focus', handleFocus); + }; }, []); return ( @@ -96,8 +130,8 @@ export const SettingPage = () => {
알림 수신 설정
-
@@ -109,9 +143,10 @@ export const SettingPage = () => {
서비스 운영 및 장애