Why do I get a SIGTRAP Exception when opening CarPlay App in real car



I have been working on implementing CarPlay into my audio app. It works as intended when I am using the Xcode Simulator but when testing in a real car, the app crashes immediately upon trying to open the app from the car display.

The app uses the com.apple.developer.playable-content entitlement and Media Player framework, which I think is still backwards compatible with iOS 14 despite there being a new CarPlay audio framework for iOS 14.

Other than the crashing when trying to open the app in CarPlay. The app when used without a car connected functions perfectly fine.

I have attached the crashlogs below.




What could be causing the app to crash in a real car but work fine in the simulator? Here is part of my AppDelegate where I call a function to setup carplay:

Code Block
import UIKit
import AVFoundation
import AVKit
import GoogleInteractiveMediaAds
import MediaPlayer
import GoogleMobileAds
import UserNotifications
import WebKit
import SafariServices
import Hero
import Firebase
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
[...]
// CarPlay
var playableContentManager: MPPlayableContentManager?
let carplayPlaylist = CarPlayPlaylist()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
[...]
setupCarPlay()
return true
}

and two files containing the CarPlay logic

AppDelegate+CarPlay.swift




CarPlayPlaylist.swift



To install a CarPlay app to your car, you have to ask Apple for a special CarPlay app Entitlement.
Did you already do that?
@robnotyou

Yes. In my app's entitlements I have added com.apple.developer.playable-content (MediaPlayer framework).

On the app's provisioning profile, I just noticed today that the entitlements has both: CarPlay audio app (CarPlay + Media Player frameworks)iOS (Dist). Which contains the new CarPlay audio framework entitlement as well as the Media Player entitlement.

I'm not sure if this is causing an issue, but I am going to try to test the app with only the MediaPlayer framework entitlement checked in the provisioning profile

I also received a crash event in FireBase Crashlytics:
Here is the stack trace of the crashed thread. There is some additional information here that the Apple crashlogs didn't have.

Code Block
Crashed: BSXPCCnx:19083:com.apple.CarPlayTemplateUIHostApp.anonymous (BSCnx:client:com.apple.frontboard.workspace-service)
0 FrontBoardServices 0x1a39e13cc -[FBSSceneParameters initWithSpecification:] + 228
1 FrontBoardServices 0x1a39e1dd8 -[FBSSceneParameters initWithXPCDictionary:] + 128
2 BaseBoard 0x198275af4 _BSXPCDecodeObject + 1892
3 BaseBoard 0x1982739c0 _BSXPCDecodeObjectForKey + 268
4 BoardServices 0x1ad695f30 +[BSXPCServiceConnectionProxy decodeArguments:outArgs:fromMessage:forConnection:] + 1608
5 BoardServices 0x1ad693ab0 -[BSXPCServiceConnectionProxy invokeMessage:onTarget:] + 276
6 BoardServices 0x1ad69a994 __63-[BSXPCServiceConnectionEventHandler connection:handleMessage:]_block_invoke + 536
7 BoardServices 0x1ad6b0284 BSXPCServiceConnectionExecuteCallOut + 316
8 BoardServices 0x1ad69a708 -[BSXPCServiceConnectionEventHandler connection:handleMessage:] + 172
9 BoardServices 0x1ad6af668 -[BSXPCServiceConnection _connection_handleMessage:fromPeer:withHandoff:] + 572
10 libdispatch.dylib 0x19385424c _dispatch_call_block_and_release + 32
11 libdispatch.dylib 0x193855db0 _dispatch_client_callout + 20
12 libdispatch.dylib 0x19385d10c _dispatch_lane_serial_drain + 580
13 libdispatch.dylib 0x19385dc90 _dispatch_lane_invoke + 460
14 libdispatch.dylib 0x19385cfd8 _dispatch_lane_serial_drain + 272
15 libdispatch.dylib 0x19385dc90 _dispatch_lane_invoke + 460
16 libdispatch.dylib 0x193867d78 _dispatch_workloop_worker_thread + 708
17 libsystem_pthread.dylib 0x1df711814 _pthread_wqthread + 276
18 libsystem_pthread.dylib 0x1df71876c start_wqthread + 8


Yes. In my app's entitlements I have added com.apple.developer.playable-content (MediaPlayer framework).

No. This is not enough!
You have to literally contact Apple, and ask them for a special CarPlay app Entitlement.

From the CarPlay App Programming Guide

To request a CarPlay app entitlement, go to http://developer.apple.com/carplay and provide information about your app, including the CarPlay app category.
You must also agree to the CarPlay Entitlement Addendum.
Apple will review your request.
If your app meets the criteria for a CarPlay app, Apple will create a CarPlay app entitlement and notify you.




Accepted Answer
@robnotyou

Yes, I'm aware. I should have made it more clear. I have contacted Apple and as I said in my app's provisioning profile I have two CarPlay audio entitlements that have been added by Apple.
I selected the wrong solution, it should be this comment:

Good news. I was able to find out something interesting. Earlier I mentioned that my entitlements file contained com.apple.developer.playable-content meanwhile my provisioning profile entitlement was selected on CarPlay audio app (CarPlay + Media Player frameworks)iOS (Dist).

When changing the CarPlay entitlement file in the app to com.apple.developer.carplay-audio (incorrect entitlement). I was able to reproduce the crash inside of the Xcode simulator. After changing it back to com.apple.developer.playable-content, the app in the simulator still crashed despite cleaning the build folder and deleting derived data and building again. However, it is possible to fix this by deleting the app from the simulator, then building and clean installing it all over again.

This led me to the follow solution:
  1. Change the provisioning profile entitlement to CarPlay audio app (Media Player only)iOS (Dist) and build the app

  2. Delete the app from the device before installing it again

  3. In the CarPlay display, go to Settings (of CarPlay) > General > Reset to clear the CarPlay dashboard

Which fixed the crashes

Why do I get a SIGTRAP Exception when opening CarPlay App in real car
 
 
Q