遇到问题

直接编译Flutter项目到ios15.4版本的iPhone高刷系列的设备上,估计只有60帧不到,这在120Hz的机型上属于远古退化的体验,是无法忍受的,对用户体验来说是毁灭性打击。

解决步骤

  1. /项目/ios/Runner/Info.plist下的作用域下新增<key>CADisableMinimumFrameDurationOnPhone</key><true/>,使其官方的Promotion失效,变成强制刷新率
  2. /项目/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
  }
}
  1. 将flutter升级到最新Master分支
    请先运行flutter channel master
    再运行flutter upgrade升级到最新版本

  2. 重新编译运行
    flutter build ios --release
    flutter install

  3. 官方Github下此问题相关的issue
    点我访问Issue-90675

版权声明:本文为许孙原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/xusun/p/16111361.html