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