Mobilens English

流程 · 新用户引导

通知权限

这个流程的所有画面

询问之前

回答

何时出现
怎么离开
下一步
行为规则

    用法

    import * as Notifications from 'expo-notifications';
    import { Linking } from 'react-native';
    import { NotificationPermission, type PermissionApi } from '@/components/mobilens/NotificationPermission';
    
    // expo-notifications: "denied" with canAskAgain false means only Settings can turn it on.
    const toStatus = (p: Notifications.NotificationPermissionsStatus) =>
      p.granted ? 'granted' : p.status === 'undetermined' ? 'undetermined' : p.canAskAgain ? 'denied' : 'blocked';
    
    const permissions: PermissionApi = {
      get: async () => toStatus(await Notifications.getPermissionsAsync()),
      request: async () => toStatus(await Notifications.requestPermissionsAsync()),
      openSettings: () => Linking.openSettings(),
    };
    
    export function NotificationsStep({ next }: { next: (enabled: boolean) => void }) {
      return <NotificationPermission permissions={permissions} appName="Northwind" onDone={next} />;
    }
    

    API

    参数类型默认值说明
    permissions PermissionApi – get, request and openSettings, connected to the platform (see Usage).
    onDone (enabled: boolean) => void – Called when the user moves on, with whether notifications are on.
    appName string – The app's name, used in the copy.
    title? string – Heading on the explanation screen before requesting permission.
    primaryLabel? string 'Turn on notifications' Label for the button that opens the system permission prompt.
    labels? Partial<NotificationPermissionLabels> – The words the screen shows. Pass a partial set to change only some of them.
    initialStep? PermissionStep – Where to start. Defaults to checking the current status; pass a step in tests.
    onStepChange? (step: PermissionStep) => void – Called with every step the screen enters, for analytics or logging.

    这个流程用到的控件