EXC_BREAKPOINT crash in iOS Extension when debug with some breakpoint - ios

When I debug the code in iOS Extension. I face some crash with EXC_BREAKPOINT
What did I do?
Run my APP with Xcode 11.5.
Start debugging for extension: Debug -> Attach to Process by PID or name -> Input my Extension name and click Attach Button
Setup some breakpoint in Extension code (Mine is UNNotificationServiceExtension)
Minimize the APP.
Push the notification.
Trigger the breakpoint which I set.
Continue to debug. Then I see this crash.
My question is how to debug extension in my case?

It may be a bug from Xcode. I fix it by setting breakpoint at the SECOND time push notification.
So the steps are:
Run my APP with Xcode 11.5.
Start debugging for extension: Debug -> Attach to Process by PID or name -> Input my Extension name and click Attach Button
Minimize the APP.
Make sure there is no breakpoint in extension code.
Push the notification.
Setup some breakpoint in Extension code (Mine is UNNotificationServiceExtension)
Push the notification.
Trigger the breakpoint which I set.
Continue to debug. It works fine.

Related

Can't attach debugger to UNNotificationServiceExtension

I'm not being able to use the debugger in a UNNotificationServiceExtension.
Here's what I do when attempting to attach the debugger to the UNNotificationServiceExtension:
Run app
Set the breakpoint in the "Testing" UNNotificationServiceExtension
Select Debug > Attach to Process by PID or Name > Select the "Testing" UNNotificationServiceExtension
XCode indicates that the "Testing is waiting to attach"
I then send a push notification and my iPhone displays the notification, but the debugger doesn't hit the breakpoint. Instead, XCode shows a "Thread1: signal SIGKILL".
Does anyone know how to get the debugger to work in a UNNotificationServiceExtension?
Don't hit run on Xcode when the debugger is attached to the service extension.
Connect the debugger to the Containing app and run the app. Then attach the debugger to the service extension.
I don't know why you can't run it when the debugger is connected to the service extension. I'm guessing it has something to do with NSExtensionPointIdentifier set to com.apple.usernotifications.service and once the OS sees that things go to hell because only the OS should launch the service extension.

How to debug iOS 9 extensions

Is there a way I can debug my networkextension (NEPacketTunnelProvider)? .
I use NSLog but not use for extension (only for container app). I found system log in window -> devices, but only have crash logs.
so I can only debug by breakpoint(debug -> attach) . but it's really really annoying me for a long time. Can I view log (NSLog) in somewhere?
You can..
First Start Your container App.
Switch to Your Extension App in xCode.
Go To Debug and choose attach to process..
Put the breakpoints to debug than

Swift keyboard extension SIGQUIT, Execution was interrupted, reason: EXC_BREAKPOINT

When I try to build and run my keyboard extension, it sometimes just crashes with a Thread 1: signal SIGQUIT.
I am not able to reproduce the error. Sometimes I can build and run my app but most of the time the keyboard just quits. This happens on an actual device. In the simulator it does not open my keyboard and says Waiting to Attach.
The console does not output any errors at first. However, if I change the dropdown to View UI Hierachy in the Debug navigator I get the following description:
Details: No plist data for fetching view hierarchy: error evaluating expression “(id)[(Class)objc_getClass("DBGViewDebuggerSupport_iOS") fetchViewHierarchyWithOptions:(id)[(Class)objc_getClass("NSDictionary") dictionaryWithObjects:(id)[(id)[(id)[(Class)objc_getClass("NSArray") arrayWithObject:(id)[(Class)objc_getClass("NSNumber") numberWithBool:1]] arrayByAddingObject:(id)[(id)[(Class)objc_getClass("NSArray") arrayWithObject:#"_UIVisualEffectBackdropView"] arrayByAddingObject:#"_UIBackdropEffectView"]] arrayByAddingObject:(id)[(Class)objc_getClass("NSNumber") numberWithBool:0]] forKeys:(id)[(id)[(id)[(Class)objc_getClass("NSArray") arrayWithObject:#"DBGViewDebuggerUseLayersAsSnapshots"] arrayByAddingObject:#"DBGViewDebuggerEffectViewsToSnapshotAsImage"] arrayByAddingObject:#"DBGViewDebuggerAlwaysEncodeLayers"]]]”: error: Execution was interrupted, reason: EXC_BREAKPOINT (code=1, subcode=0x18daddc34).
The process has been returned to the state before expression evaluation.
Method: -[DBGAbstractViewDescriber handleFetchedViewInfo:fetchError:resultHandler:]
Please file a bug at http://bugreport.apple.com with this warning message and any useful information you can provide.
I also took a screenshot of the processes.
Am I doing something wrong and how could I prevent that my keyboard extension quits all the time when running it? Is it actually a bug as it says in the description?
DISCLAIMER
It seems like something in xCode 8.2.1 is broken and the debugger is not correctly attaching to the correct process or the hosting process is not properly loading the new code.
This is a not a permanent solution but a temporary workaround.
WORKAROUND
I have been able to work around this issue by following the steps below.
Kill any process that is using your keyboard (important!)
Launch the application using the debugger so the latest code is deployed to the device
Navigate to Settings > General > Keyboards > etc.
Remove your custom keyboard
Re-add your custom keyboard
Debug the application once again
The reason this works is because removing the keyboard kills the process that is hosting the extension allowing Xcode to attach to the new binary.
As I understand this is a bug in Xcode 8.2.1. because before update my custom keyboard was working very well.
this is a temporary solution.
Run your code like always!
Bring up your keyboard until the error (SIGQUIT) appear!
Goto xcode > debug > detach
Goto again Xcode > debug > Attach to Process: attach the keyboard (it should be first process)
now, your breakpoints will work. but there are no log output unfortunately! I hope it temporary solve your problem

HockeySDK Warning - How to test crash reporting?

I got this warning when running my application with HockeyApp integration:
[HockeySDK] WARNING: Detecting crashes is NOT enabled due to running the app with a debugger attached.
Crash reports are not sent and no alert is displayed when opening the app again.
Any one have any idea how to resolve this issue?
This has very simple reasons:
If you are running the app with Xcode attached, your app is connected to lldb, Xcode's debugger. When lldb is attached, it will of course do its job as a debugger and catch any exception or crash that occurs. This means that the crash can never reach the HockeyApp SDK or any other crash reporting SDK while lldb is attached at the same time.
The solution is also pretty simple. If you just want to make sure the SDK is integrated properly and will catch crashes, do the following:
Do a quick "Build & Run" to install the current version of the app on the simulator or device.
Click the "Stop" button in Xcode to stop the debugging session.
Manually start the app on the device or simulator by tapping or clicking the app icon.
Cause a crash.
Restart the app. Now the HockeySDK should process the crash report and show a dialog to approve crash log sending.
One thing to keep in mind: Make sure to not make the app crash immediately after app start as this would not give the SDK enough time to process and send the crash report before crashing again.
Hockey app sdk by default does not send report when a debugger is attached. There is nothing wrong with this.
It will send report when a archive build that release to ur tester cause a crash. I personally think this should and remain as this because you are trying to track crashes from your tester not when you are developing.

Debug Notification Extensions

I'm building a set of Notification Extensions (Service/Content).
I'm unable to connect to Xcode debugger or even log out to the device log or console.
Is there any way to see any kind of output?
Change the target to run the extension
then select run and choose your app from the 'Choose an app to run:' window.
I have tried as per brendan's Answer but is not working for me at all!
I am getting below error in console
Program ended with exit code: 0
Then after searching on google i have checked this answer. however this also not worked for me for while!
Then i have tried same steps again as given in answer, After stopping my current running app. then follow same steps.For clarity i am writing this steps as below:
After running the app that contains the extension,
1) Set your breakpoint in the extension
2) Select Debug / Attach to Process by PID or name
3) Enter the name of the extension target
4) Trigger the push notification
Before step 2 make sure to stop your current running app.
This worked for me to stop at breakpoints in the extension and see the extension log:
Choose the notification extension scheme, not the main app scheme
Run the app and select the main app from the list Choose an app to run
Stop the app in Xcode and terminate it manually on the device; not terminating it manually results in Message from debugger: Terminated due to signal 9 after step 6.
[Update: Terminating the app manually on the device doesn't seem to be necessary, try either way if it doesn't work.]
Select Menu Debug > Attach to Process by PID or Name
Enter the correct extension name, not the main app name
Send the push notification
Notification service extension (NSE) is not actually a part of your app but an extension that said it has a different process id (PID) from your app. You can have XCode listen to every process on your phone by going to the “Debug” tab, scroll down to “Attach to Process” and look to see if your NSE is listed under “Likely Targets”. If it's not there than try to sand another push notification to your device and attach to it when it appears.
Now in debug navigator you can see the NES process and you can successfully debug it.
In my case all methods above had some mistakes. Main point, that you need to send push one time, then connect through debugger, then send push to debug. So, full list:
Launch app (not extension).
Stop app from XCode.
Send one push.
Connect via "Attach to Process by PID or Name..." to your extension process.
Send another push.
If you have tried all the above solutions and still scratching your head and wondering why break point point is not being called. Then try checking the deployment target of your extension it should be less or equal to your device OS.
For me, the deployment target was higher than the device OS.
In my case (Xcode 11.1) debug starts after this steps:
run notification extension target with main app
switch app to background
lock the phone !
send push to device
I followed solutions mentioned here but nothing helped. I found out that problem is when payload of notification does not contain flag to enable content to be mutated. Notification without this flag are not handled by NotificationExtension at all. After I added "mutable-content": 1 to the payload and followed answers here I was able to alter content of push notification and to debug code in NotificationExtension.
{
"aps": {
"mutable-content": 1,
"alert": {
"title": "Push Title",
"body": "Push payload body"
}
},
"data": "what ever you need to be in userInfo"
}
Not sure if this will be helpful, but we have multiple builds of the same app (alpha, beta, etc). Kept getting a "don't have permissions to attach" error when trying to debug. Opening up the processes list, I noticed that there were 2 processes named notification-extension so xcode must have been defaulting to the one of the other build. By manually selecting the right one, or deleting the other builds from my phone things started working again.
The only way that worked for me was to see logs. I use xcode 10.1. The logs were available from Window -> Devices and Simulators -> Choose your device -> click on 'Open Console'.
This way i could see logs from extensions as well.

Resources