Downside
I am creating an app that has each a CarPlay and telephone interface. My CarPlay app makes use of MPNowPlayingInfoCenter defaultCenter by a NowPlaying Template. Nonetheless, I’ve one other module which makes use of the default middle within the telephone app scene (not the CarPlay scene).
When disconnecting from CarPlay, the singleton shared occasion of [MPNowPlayingInfoCenter defaultCenter]
will get deallocated together with my NowPlayingTemplate, regardless of the telephone app nonetheless requiring it. This causes points with my audio playback state.
This downside solely happens on a bodily CarPlay gadget – within the CarPlay gadget simulator, my code works positive with a proxy class implementation.
What I’ve tried
Implementing a proxy class (works in simulator however not on bodily gadget)
Varied types of methodology swizzling
I can not modify the third-party library code that calls [MPNowPlayingInfoCenter defaultCenter]
within the telephone app
Atmosphere
iOS model: 18.1.1
CarPlay framework model: iOS 18 CarPlay framework
Xcode model: Model 16.2 (16C5032a)
Questions
How can I stop MPNowPlayingInfoCenter defaultCenter from being deallocated when disconnecting from CarPlay whereas guaranteeing it stays obtainable for the telephone app? Is there a really helpful strategy for sharing the now enjoying information between CarPlay and telephone interfaces?
Code Instance
@interface CarPlayCoordinator : NSObject
@property (nonatomic, sturdy) CPNowPlayingTemplate *nowPlayingTemplate;
- (void)setupNowPlayingTemplate;
@finish
@implementation CarPlayCoordinator
- (void)setupNowPlayingTemplate {
self.nowPlayingTemplate = [CPNowPlayingTemplate sharedTemplate];
// Configure template after which..
// MPNowPlayingInfoCenter is used within the template's lifecycle
}
@finish
Any help with this subject can be significantly appreciated.