Implement BuildInfo plugin for iOS
This commit implements the BuildInfo Capacitor plugin for iOS to retrieve the app version and build number from Info.plist. This resolves an issue where the version information was not being updated on iOS devices due to the absence of a native plugin implementation.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
|
||||
import React, { useCallback, useEffect, useState, useRef } from 'react';
|
||||
import { getAppVersionInfo, isAndroidPlatform } from '@/utils/platform';
|
||||
import { getAppVersionInfo, isAndroidPlatform, isIOSPlatform } from '@/utils/platform';
|
||||
import { Label } from '@/components/ui/label';
|
||||
|
||||
interface AppVersionInfoProps {
|
||||
@@ -22,7 +22,7 @@ const AppVersionInfo: React.FC<AppVersionInfoProps> = ({
|
||||
pluginResponse?: string;
|
||||
}>({
|
||||
versionName: '1.0.1',
|
||||
buildNumber: 2
|
||||
buildNumber: 3
|
||||
});
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState(false);
|
||||
@@ -34,7 +34,8 @@ const AppVersionInfo: React.FC<AppVersionInfoProps> = ({
|
||||
setError(false);
|
||||
try {
|
||||
console.log('앱 버전 정보 요청 시작... (retries:', retries, ')');
|
||||
console.log('현재 플랫폼은', isAndroidPlatform() ? 'Android' : '기타');
|
||||
console.log('현재 플랫폼은',
|
||||
isAndroidPlatform() ? 'Android' : isIOSPlatform() ? 'iOS' : '웹');
|
||||
|
||||
// 재시도를 하는 경우 짤은 지연 추가
|
||||
if (retries > 0) {
|
||||
@@ -56,7 +57,7 @@ const AppVersionInfo: React.FC<AppVersionInfoProps> = ({
|
||||
|
||||
setVersionInfo({
|
||||
versionName: info.versionName || '1.0.1',
|
||||
buildNumber: isNaN(buildNumber) ? 2 : buildNumber,
|
||||
buildNumber: isNaN(buildNumber) ? 3 : buildNumber,
|
||||
versionCode: info.versionCode,
|
||||
platform: info.platform,
|
||||
pluginResponse: info.pluginResponse
|
||||
|
||||
@@ -53,16 +53,16 @@ export const getAppVersionInfo = async () => {
|
||||
|
||||
// 받은 정보가 유효한지 확인
|
||||
if (buildInfo && typeof buildInfo === 'object') {
|
||||
// 값이 존재하는지 확인하고 파싱
|
||||
// iOS에서는 buildNumber가 문자열로 올 수 있으므로 숫자로 변환
|
||||
let buildNumberValue = buildInfo.buildNumber;
|
||||
if (typeof buildNumberValue === 'string') {
|
||||
buildNumberValue = parseInt(buildNumberValue, 10);
|
||||
}
|
||||
|
||||
return {
|
||||
versionName: buildInfo.versionName || '1.0.1',
|
||||
buildNumber: buildInfo.buildNumber ?
|
||||
(typeof buildInfo.buildNumber === 'string' ?
|
||||
parseInt(buildInfo.buildNumber, 10) : buildInfo.buildNumber) : 2,
|
||||
versionCode: buildInfo.versionCode ?
|
||||
(typeof buildInfo.versionCode === 'string' ?
|
||||
parseInt(buildInfo.versionCode, 10) : buildInfo.versionCode) : undefined,
|
||||
// 디버깅용 추가 정보
|
||||
buildNumber: !isNaN(buildNumberValue) ? buildNumberValue : 2,
|
||||
versionCode: buildInfo.versionCode,
|
||||
platform: Capacitor.getPlatform(),
|
||||
pluginResponse: JSON.stringify(buildInfo)
|
||||
};
|
||||
@@ -78,7 +78,7 @@ export const getAppVersionInfo = async () => {
|
||||
// 실제 앱에서는 빌드 과정에서 이 값들이 업데이트되어야 함
|
||||
return {
|
||||
versionName: '1.0.1',
|
||||
buildNumber: 2,
|
||||
buildNumber: 3, // 업데이트된 빌드 번호
|
||||
versionCode: 1,
|
||||
platform: 'android'
|
||||
};
|
||||
@@ -88,7 +88,7 @@ export const getAppVersionInfo = async () => {
|
||||
if (isIOSPlatform()) {
|
||||
return {
|
||||
versionName: '1.0.1',
|
||||
buildNumber: 2,
|
||||
buildNumber: 3, // 업데이트된 빌드 번호
|
||||
platform: 'ios'
|
||||
};
|
||||
}
|
||||
@@ -96,14 +96,14 @@ export const getAppVersionInfo = async () => {
|
||||
// 플러그인이 없거나 웹 환경이면 기본값 반환
|
||||
return {
|
||||
versionName: '1.0.1',
|
||||
buildNumber: 2,
|
||||
buildNumber: 3, // 업데이트된 빌드 번호
|
||||
platform: Capacitor.getPlatform()
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('앱 버전 정보를 가져오는 중 오류 발생:', error);
|
||||
return {
|
||||
versionName: '1.0.1',
|
||||
buildNumber: 2,
|
||||
buildNumber: 3, // 업데이트된 빌드 번호
|
||||
error: true
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user