51 lines
1.4 KiB
JavaScript
51 lines
1.4 KiB
JavaScript
const { withInfoPlist, withEntitlementsPlist } = require('@expo/config-plugins')
|
||
|
||
/**
|
||
* iOS 内存和渲染优化配置
|
||
* 针对大量图片/视频场景优化性能
|
||
*/
|
||
const withIOSMemoryOptimization = (config) => {
|
||
// 1. 配置 Info.plist
|
||
config = withInfoPlist(config, (config) => {
|
||
const infoPlist = config.modResults
|
||
|
||
// 启用 Metal 渲染(硬件加速)
|
||
infoPlist.UIRequiresPersistentWiFi = false
|
||
|
||
// 优化视图渲染
|
||
infoPlist.UIViewControllerBasedStatusBarAppearance = true
|
||
|
||
// 允许后台任务(用于图片预加载)
|
||
if (!infoPlist.UIBackgroundModes) {
|
||
infoPlist.UIBackgroundModes = []
|
||
}
|
||
if (!infoPlist.UIBackgroundModes.includes('fetch')) {
|
||
infoPlist.UIBackgroundModes.push('fetch')
|
||
}
|
||
|
||
// 优化 WKWebView 内存使用
|
||
infoPlist.WKWebViewOnly = true
|
||
|
||
// 允许文件访问(用于缓存)
|
||
infoPlist.NSAllowsArbitraryLoads = false
|
||
|
||
console.log('✅ withIOSMemoryOptimization: Info.plist 已优化')
|
||
return config
|
||
})
|
||
|
||
// 2. 配置 Entitlements(如果需要)
|
||
config = withEntitlementsPlist(config, (config) => {
|
||
const entitlements = config.modResults
|
||
|
||
// 启用数据保护(优化磁盘缓存)
|
||
entitlements['com.apple.developer.default-data-protection'] = 'NSFileProtectionComplete'
|
||
|
||
console.log('✅ withIOSMemoryOptimization: Entitlements 已优化')
|
||
return config
|
||
})
|
||
|
||
return config
|
||
}
|
||
|
||
module.exports = withIOSMemoryOptimization
|