Flutter ios高刷不生效解决方案(iPhone高刷系列)
遇到问题
直接编译Flutter项目到ios15.4版本的iPhone高刷系列的设备上,估计只有60帧不到,这在120Hz的机型上属于远古退化的体验,是无法忍受的,对用户体验来说是毁灭性打击。
解决步骤
- 在
/项目/ios/Runner/Info.plist
下的作用域下新增<key>CADisableMinimumFrameDurationOnPhone</key><true/>
,使其官方的Promotion失效,变成强制刷新率 - 在
/项目/ios/Runner/AppDelegate.swift
下application作用域新增:
if #available(iOS 15.0, *) {
let displayLink = CADisplayLink(target: self, selector: #selector(step))
displayLink.preferredFrameRateRange = CAFrameRateRange(minimum:120, maximum:120, preferred:120)
displayLink.add(to: .current, forMode: .default)
}
使之变成:
import UIKit
import Flutter
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
if #available(iOS 15.0, *) {
let displayLink = CADisplayLink(target: self, selector: #selector(step))
displayLink.preferredFrameRateRange = CAFrameRateRange(minimum:120, maximum:120, preferred:120)
displayLink.add(to: .current, forMode: .default)
}
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
@objc func step(displaylink: CADisplayLink) {
// Will be called once a frame has been built while matching desired frame rate
}
}
-
将flutter升级到最新Master分支
请先运行flutter channel master
再运行flutter upgrade
升级到最新版本 -
重新编译运行
flutter build ios --release
flutter install
-
官方Github下此问题相关的issue
点我访问Issue-90675