Push 알림 설치

hwakyungChoi·2021년 9월 22일
0

설치

클라이언트 측에서 푸시 알림을 준비하기 위해 필요한 두 가지 주요 사항은 다음과 같습니다.

  • 푸시 알림을 보낼 수 있는 사용자의 권한
  • 사용자의 ExpoPushToken(푸시 알림이 메일인 경우 ExpoPushToken은 사용자의 주소)

expo-notifications 라이브러리를 사용하면 이 두 가지를 모두 쉽게 얻을 수 있습니다.
사용 권한의 경우 requestPermissionsAsync을 ExpoPushToken의 경우, getExpoPushTokenAsync을 사용하시면 됩니다.

참고: 관리되는 워크플로우에서 getExpoPushTokenAsync에 추가적인 옵션을 전달할필요가 없습니다.

기본 워크플로우에서는 ExperienceId를 전달해야 합니다. 자세한 내용은 설명서를 참조하십시오.
다음 방법을 사용하면 이 모든 작업을 처리할 수 있으므로 복사/붙여넣기 작업을 할 수 있습니다.

registerForPushNotificationsAsync = async () => {
  if (Constants.isDevice) {
    const { status: existingStatus } = await Notifications.getPermissionsAsync();
    let finalStatus = existingStatus;
    if (existingStatus !== 'granted') {
      const { status } = await Notifications.requestPermissionsAsync();
      finalStatus = status;
    }
    if (finalStatus !== 'granted') {
      alert('Failed to get push token for push notification!');
      return;
    }
    const token = (await Notifications.getExpoPushTokenAsync()).data;
    console.log(token);
    this.setState({ expoPushToken: token });
  } else {
    alert('Must use physical device for Push Notifications');
  }

  if (Platform.OS === 'android') {
    Notifications.setNotificationChannelAsync('default', {
      name: 'default',
      importance: Notifications.AndroidImportance.MAX,
      vibrationPattern: [0, 250, 250, 250],
      lightColor: '#FF231F7C',
    });
  }
  };

자격 증명(credential)

기본 워크플로우를 사용하거나 expo build:ios 또는 expo build:android와 함께 독립 실행형 앱을 만드는 경우 필요한 push credentials도 구성해야 합니다.

안드로이드의 경우, 관리형 워크플로우 사용자 및 bare 워크플로우 사용자 모두 FCM 설정 가이드를 따라야 하며, 약 5분 정도만 소요됩니다.

iOS의 경우, 클래식 Classic 빌드 서비스는 expo build:ios를 실행할 때 푸시 알림 자격 증명을 자동으로 처리합니다. 그러나 EAS 빌드 또는 기본 워크플로우를 사용할 경우 Expo credentials:manager 명령을 사용하여 푸시 알림 자격 증명을 Expo의 서버에 업로드해야 합니다. 자세한 지침은 여기에서 확인할 수 있습니다.

참고: 자격 증명을 생성하려면 유료 Apple Developer 계정이 필요합니다.

0개의 댓글