0

我正在使用 iOS 15 新视图(LocationButton {...}),我的应用程序立即崩溃。测试了2天,逐个文件减少代码,我发现语言本地化让它崩溃了。只需使用 Xcode 13.1 创建 1 个项目,如下代码所示创建一个文件(LocationView),创建一个像 InfoPlist 或其他属性列表文件这样的文件,并为本地化配置项目文件,添加一些语言包,如西班牙语/丹麦语/日语/繁体中文/简体中文,然后使用简体中文本地化InfoPlist文件,运行应用程序,崩溃。但如果使用其他本地化语言,如繁体中文/日文/西班牙文,就可以了。当应用程序崩溃时,它会显示一个警报(如下)

线程 1:“无效参数不满足:宽度 && 高度”。

2021-11-19 15:23:29.247424+0800 MyNewProject2[98414:3116225] *** CGImageRef _Nonnull UISCreateImageFromDrawing(__strong id _Nonnull, CGFloat, UISDisplayRange)(), UISDrawing.m:19 中的断言失败

2021-11-19 15:23:29.259872+0800 MyNewProject2[98414:3116225] *** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无效参数不满足:宽度和高度”

*** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无效参数不满足:宽度 && 高度”以 NSException CoreSimulator 776.4 类型的未捕获异常终止 - 设备:iPhone 13 Pro Max (FC597160-C5F6-4268-91F5- F38AB31AED4F) - 运行时:iOS 15.0 (19A339) - 设备类型:iPhone 13 Pro Max

您是否也可以尝试使用以下代码对其进行测试。重要提示:设备语言应该使用简体中文启动,然后App InfoPlist.strings使用简体中文本地化。

import SwiftUI
import CoreLocationUI
import CoreLocation
import MapKit

struct LocationView: View {
    @StateObject var locationWorker = LocationWorker()
    var body: some View {
        NavigationView {
            LocationButton(.currentLocation) {
                locationWorker.startUpdatingLocation()
            }
            .foregroundColor(Color.white)
            .cornerRadius(27)
            .frame(width: 210, height: 54)
            .padding(.bottom, 30)
            .navigationTitle("Search Location")
        }
        .navigationViewStyle(.stack)
    }
}

class LocationWorker: NSObject, ObservableObject, CLLocationManagerDelegate {
    private let locationManager = CLLocationManager()
    @Published var locationStatus: CLAuthorizationStatus?
    @Published var lastLocation: CLLocation?
    override init() {
        super.init()
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
    }

func startUpdatingLocation() {
    locationManager.startUpdatingLocation()
}

func stopUpdatingLocation() {
    locationManager.stopUpdatingLocation()
}

var statusString: String {
    guard let status = locationStatus else {
        return "unknown"
    }
    
    switch status {
    case .notDetermined: return "notDetermined"
    case .authorizedWhenInUse: return "authorizedWhenInUse"
    case .authorizedAlways: return "authorizedAlways"
    case .restricted: return "restricted"
    case .denied: return "denied"
    default: return "unknown"
    }
}

func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
    locationStatus = status
    print(#function, statusString)
}

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    guard let location = locations.last else { return }
    print(#function, location)
    stopUpdatingLocation()
 }
}

在此处输入图像描述

4

0 回答 0