I sent out a functioning test build of my app on to test flight. To remove some errors I did the following:
Turned off device orientation left and right
ticked requires full screen
and finally, replaced the valid app icons.
However, I noticed my label and background was missing from this test build so I opened it up in the simulator and received this error:
Thread 1: EXC_BAD_INSTRUCTION(code=EXC_1386_INVOP,subcode=0x0)
about the line:
let distanceSpan:CLLocationDegrees = 2000
MapView.setRegion(MKCoordinateRegionMakeWithDistance(CLLocationCoordinate2DMake(-39.0556253, 174.0752278), distanceSpan,distanceSpan), animated: true)
I have no idea what has caused this also in the output I got:
fatal error: unexpectedly found nil while unwrapping an Optional value
but I don't see where the optional value is? I have attached my code here
Any help is much appreciated.
Thanks
Related
Using Xcode 12.4 Simulator 14.4
For the alert displayed below, I have the following function in my XCUITests that I use to pull the static text displayed on the System Alert:
_ = addUIInterruptionMonitor(withDescription: "", handler: { (alert) -> Bool in
var data = alert.staticTexts.allElementsBoundByIndex.map {$0.label}
...
})
This worked when using Xcode 11.3 Sims 13.3; however, I just upgraded Xcode and now it crashes on when running the map function and gives the following error:
error: Execution was interrupted, reason: internal ObjC exception breakpoint(-8)..The process has been returned to the state before expression evaluation.
If I put a breakpoint, I can see the following:
po alert.staticTexts.allElementsBoundByIndex.count -> returns 3
po alert.staticTexts.allElementsBoundByIndex[0].label -> returns "Allow “X” to use your location?"
po alert.staticTexts.allElementsBoundByIndex[1].label -> returns "Your location is used to find and display nearby X facilities."
po alert.staticTexts.allElementsBoundByIndex[2] -> returns StaticText, {{32.0, 12.0}, {72.5, 16.0}}, label: 'Precise: On'
However, when I run the following (or runs during my test), it fails but as you can see from above, it does have a static text element at that position:
po alert.staticTexts.allElementsBoundByIndex[2].label -> No matches found for Element at index 2 from input {(
StaticText)} error: Execution was interrupted, reason: internal ObjC exception breakpoint(-8)
If I remain in the console and rerun the same call again, it then works though:
po alert.staticTexts.allElementsBoundByIndex[2].label -> "Precise: On"
Does anyone know what causes this error or a solution for how I can handle it in my test?
As this alert is "outside" your application and everything works when you debug/pause execution, I have to think this is something to do with synchronization.
Do you have anything waiting for the alert to fully display? I don't usually trust the UIInterruptionHandler to do more than auto-dismiss an alert not under test.
I'm using a page object model and typically wait for new pages in the initializer using something like _ = XCUIApplication().alerts.firstMatch.waitForExistence(timeout: 2.0)
That doesn't explain why your example of calling it twice in the console works, but timing is where I'd be looking. I feel that's the only time I ever see errors like this.
It could also be related to the map not being static or loading slowly and therefore changing the accessibility after XCUITest thinks it has finished loading and proceeds. Throwing in a nice long Thread.sleep would be the easiest way to debug that.
I know this kind of question is kind of asked a lot but it's a bit different that i could not find elsewhere .
Age old "Fatal error: Unexpectedly found nil while unwrapping an Optional value" we face everyday but usually it states to the point or line in the code where it is trying to unwrap an optional value and it is nil .
But in my case it is redirecting me to AppDelegate class due to which i don't know where it is exactly crashing .
Now my point is that is there any way to figure out which variable was being unwrapped that caused the crash.
The Debugger window does not state anything as well . Just the same Unwrapping optional- nil - failed statement
Following are the debugger commands that i used and their output after that :
Blue - App name
Red - Framework that we are using inside the app
di
thread backtrace
Suppose that I set up the breakpoint at some point of my code. I run the compiler, and app stop exactly there where i set up the breakpoint. Now I need to print object in console using, for instance:
po messageIdentifier
But instead of correct object i get a lot of errors:
error: Error in auto-import:
failed to get module 'Module-Name' from AST context:
...
A fatal parse error has occurred.
LLDB may become unstable; please restart your debug session as soon as possible.
but when i try to tap po messageIdentifier second time, the I get correct answer:
"44540ef4-7343-4cd6-89a2-a4ea97048d6f"
Why do I have to do this twice?
My project code in here:
SMS_DEMO
It runs successfully in Xcode but display (lldb) in console output, and error message
"thread 1:EXC_BREAKPOINT(code=EXC_I386_BPT,subcode=0x0",
Please kindly see below screen for details.
Could you please kindly help to see what I should do to solve this problem?
Thank you!
I looked closely to image that you post. I suggest you to check the getCo.... method from ContactData class. Inside it look for places where you cast a value. One of them is the source of this error.
EDIT: More Info
Here is the portion of your image that you should look. It show stack trace of thread 1 which is main thread. The number 0 line is where the crash happens. Looking the method name you can easily guess this is casting from one type to other. For example let bar = baz as Bar. Because of this cast failed your program crashed. Now the line 1 is your code. If you click that line you can see the line where the casting happens in editor.
Sometimes I get this error on the device.
I've seen past question on this saying the error will occur if simulation location is enabled in the scheme. However I'm getting this on hardware not the simulator.
Other answer say to check there is Wifi/3G. Which there is.
Other answer say to reset the location services and the network services. However this would imply some terminal fault with the device, but after getting this error I might try again later and it would work.
From Apple Docs,
typedef enum {
kCLErrorLocationUnknown = 0,
kCLErrorDenied,
kCLErrorNetwork,
kCLErrorHeadingFailure,
kCLErrorRegionMonitoringDenied,
kCLErrorRegionMonitoringFailure,
kCLErrorRegionMonitoringSetupDelayed,
kCLErrorRegionMonitoringResponseDelayed,
kCLErrorGeocodeFoundNoResult,
kCLErrorGeocodeFoundPartialResult,
kCLErrorGeocodeCanceled,
kCLErrorDeferredFailed,
kCLErrorDeferredNotUpdatingLocation,
kCLErrorDeferredAccuracyTooLow,
kCLErrorDeferredDistanceFiltered,
kCLErrorDeferredCanceled,
} CLError;
kCLErrorDomain error comes unexpectedly, reason may be different. You are getting the error 0; i.e kCLErrorLocationUnknown the location manager was unable to obtain a location value right now.