遇到問題
直接編譯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
