XuqmGroup-RNSDK/src/update/updateSDK.ts
2026-04-21 22:07:29 +08:00

54 行
1.4 KiB
TypeScript

import { Platform, Linking } from 'react-native'
import { apiRequest } from '../core/http'
import { getConfig } from '../core/config'
export interface AppUpdateInfo {
needsUpdate: boolean
versionName?: string
versionCode?: number
downloadUrl?: string
changeLog?: string
forceUpdate?: boolean
appStoreUrl?: string
marketUrl?: string
}
export interface RnUpdateInfo {
needsUpdate: boolean
latestVersion: string
downloadUrl: string
md5: string
minCommonVersion: string
note: string
}
export const UpdateSDK = {
async checkAppUpdate(currentVersionCode: number): Promise<AppUpdateInfo> {
const config = getConfig()
return apiRequest<AppUpdateInfo>('/api/v1/updates/app/check', {
params: {
appId: config.appId,
platform: Platform.OS === 'android' ? 'ANDROID' : 'IOS',
currentVersionCode: String(currentVersionCode),
},
})
},
async openAppStore(appStoreUrl?: string, marketUrl?: string): Promise<void> {
const url = Platform.OS === 'ios' ? appStoreUrl : marketUrl
if (url) await Linking.openURL(url)
},
async checkRnUpdate(moduleId: string, currentVersion: string): Promise<RnUpdateInfo> {
const config = getConfig()
return apiRequest<RnUpdateInfo>('/api/v1/rn/update/check', {
params: {
appId: config.appId,
moduleId,
platform: Platform.OS === 'android' ? 'ANDROID' : 'IOS',
currentVersion,
},
})
},
}