1

I am using the iOS 15 new View(LocationButton {...}), and my app crashed immediately. After I tested for 2 days, reduce code one file by one file, I found the Language Localization make it crashed. Just create 1 project using Xcode 13.1, create a file(LocationView) as below code showed, create a file like InfoPlist or other property list file, and configure the project file for the Localization, add some language package like Spanish/Danish/Japanese/Chinese Traditional/Chinese Simplified, then make the InfoPlist file localized using Chinese simplified, the run app, crashed. But if using other language localized like Chinese Traditional/Japanese/Spanish, it is ok. When app crashed, it will show an alert (as below)

Thread 1: "Invalid parameter not satisfying: width && height".

2021-11-19 15:23:29.247424+0800 MyNewProject2[98414:3116225] *** Assertion failure in CGImageRef _Nonnull UISCreateImageFromDrawing(__strong id _Nonnull, CGFloat, UISDisplayRange)(), UISDrawing.m:19

2021-11-19 15:23:29.259872+0800 MyNewProject2[98414:3116225] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: width && height'

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: width && height' terminating with uncaught exception of type NSException CoreSimulator 776.4 - Device: iPhone 13 Pro Max (FC597160-C5F6-4268-91F5-F38AB31AED4F) - Runtime: iOS 15.0 (19A339) - DeviceType: iPhone 13 Pro Max

Would you please also have a try using below code to test it. Important: device language should use Chinese Simplified to launch, then App InfoPlist.strings localized using Chinese Simplified.

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()
 }
}

enter image description here

Alexico
  • 33
  • 1
  • 4
  • after app crashed, when try other language localization(excluding Chinese simplified), you should first press shift+command+k to clean the build folder, then run app, it will be ok. – Alexico Nov 19 '21 at 07:31
  • 'InfoPlist' for what!? That's not even how you store localized strings. – El Tomato Nov 19 '21 at 07:50
  • "InfoPlist.strings" is created for some device authorization access, and translated text can be placed in this file, and supported different language. Also, you can use another type of file named Property List and edit some data like array or dictionary. – Alexico Nov 19 '21 at 07:57
  • So I have the same problem, I just couldn't solve it after a very long research. Maybe it's a bug in swiftui. Maybe the locationButton is not localized and this is the reason it doesn't work. I don't know really. So I got rid of the LocationButton and used regular requestWhenInUseAuthorization and now all my localization files work! This is my post, be sure to update if you find out something new: https://stackoverflow.com/questions/70998635/why-app-crashes-when-i-use-localization-and-locationbutton-in-swiftui-i-get-thi – Gal May 03 '22 at 14:44

0 Answers0