From 83d713c38c4364307831c324259bf744743d5535 Mon Sep 17 00:00:00 2001 From: Junhui Chen Date: Wed, 23 Jul 2025 20:59:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E6=9D=83=E9=99=90=E7=94=B3=E8=AF=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/(tabs)/_layout.tsx | 7 ++++--- components/auth/index.tsx | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/(tabs)/_layout.tsx b/app/(tabs)/_layout.tsx index 28ecb79..aaed35a 100644 --- a/app/(tabs)/_layout.tsx +++ b/app/(tabs)/_layout.tsx @@ -1,5 +1,6 @@ import { HapticTab } from '@/components/HapticTab'; import { TabBarIcon } from '@/components/navigation/TabBarIcon'; +import { requestNotificationPermission } from '@/components/owner/utils'; import TabBarBackground from '@/components/ui/TabBarBackground'; import { Colors } from '@/constants/Colors'; import { useColorScheme } from '@/hooks/useColorScheme'; @@ -27,9 +28,9 @@ export default function TabLayout() { const [token, setToken] = useState(''); const sendNotification = async (item: PollingData) => { // 请求通知权限 - const { status } = await Notifications.requestPermissionsAsync(); - if (status !== 'granted') { - alert('请先允许通知权限'); + const granted = await requestNotificationPermission(); + if (!granted) { + console.log('用户拒绝了通知权限'); return; } diff --git a/components/auth/index.tsx b/components/auth/index.tsx index 26df4ec..6c70630 100644 --- a/components/auth/index.tsx +++ b/components/auth/index.tsx @@ -3,6 +3,7 @@ import * as Device from 'expo-device'; import * as Notifications from 'expo-notifications'; import { useEffect, useState } from 'react'; import { Button, Platform, Text, View } from 'react-native'; +import { requestNotificationPermission } from '../owner/utils'; Notifications.setNotificationHandler({ handleNotification: async () => ({ @@ -108,13 +109,13 @@ async function registerForPushNotificationsAsync() { // 4. 如果尚未授予权限,则请求权限 if (existingStatus !== 'granted') { - const { status } = await Notifications.requestPermissionsAsync(); - finalStatus = status; + const granted = await requestNotificationPermission(); + finalStatus = granted ? Notifications.PermissionStatus.GRANTED : Notifications.PermissionStatus.DENIED; } // 5. 如果权限被拒绝,显示警告并返回 if (finalStatus !== 'granted') { - alert('Failed to get push token for push notification!'); + console.log('用户拒绝了通知权限'); return; }