반응형
TL;DR (3줄 요약)
@notifee/react-native
+@expo/config-plugins
+expo-build-properties
설치android-manifest.plugin.js
생성 →app.json
에 플러그인 등록npx expo prebuild --clean
후 재빌드
개발 환경
expo: 53.0.11
빌드 타입: Dev Client
1️⃣ 필수 패키지 설치
npm install @notifee/react-native
npx expo install expo-build-properties
npm install @expo/config-plugins
2️⃣ Maven 경로 추가 (app.json
)
{
"plugins": [
[
"expo-build-properties",
{
"android": {
"extraMavenRepos": [
"../../node_modules/@notifee/react-native/android/libs"
]
}
}
]
]
}
3️⃣ Foreground Service용 Manifest 플러그인
3-1 android-manifest.plugin.js
const { withAndroidManifest, AndroidConfig } = require("@expo/config-plugins");
module.exports = function withForegroundService(config) {
return withAndroidManifest(config, async (config) => {
const manifest = config.modResults;
// tools 네임스페이스 보장
if (!manifest.manifest.$["xmlns:tools"]) {
manifest.manifest.$["xmlns:tools"] = "http://schemas.android.com/tools";
}
// Foreground Service 등록
const app = AndroidConfig.Manifest.getMainApplicationOrThrow(manifest);
app.service = app.service || [];
app.service.push({
$: {
"android:name": "app.notifee.core.ForegroundService",
"android:foregroundServiceType": "microphone",
"tools:replace": "android:foregroundServiceType"
}
});
return config;
});
};
3-2 플러그인 등록
app.json
{
"expo": {
"plugins": ["./android-manifest.plugin.js"]
}
}
4️⃣ Foreground Service 등록 코드 (App.tsx
)
import notifee from "@notifee/react-native";
notifee.registerForegroundService(() => new Promise(() => {
console.log("Foreground service started");
}));
5️⃣ 녹음 시작 로직 예시
import * as Audio from "expo-av";
import notifee from "@notifee/react-native";
const startRecording = async () => {
const { granted } = await Audio.requestPermissionsAsync();
if (!granted) return;
await Audio.setAudioModeAsync({
allowsRecordingIOS: true,
playsInSilentModeIOS: true,
staysActiveInBackground: true
});
const { recording } = await Audio.Recording.createAsync(
Audio.RecordingOptionsPresets.HIGH_QUALITY
);
const channelId = await notifee.createChannel({
id: "recording",
name: "Recording"
});
notifee.displayNotification({
title: "백그라운드 녹음 중",
body: "마이크 ON",
android: { channelId, asForegroundService: true }
});
};
6️⃣ 빌드 & 테스트
npx expo prebuild --clean # 네이티브 파일 재생성
npx expo run:android # Dev Client 빌드 · 설치
- 홈 버튼 눌러도
adb logcat | grep "Foreground service started"
로그가 계속 찍히면 성공 - 1-분 이상 녹음 유지되는지 확인 → OK!
반응형