Both the extension and the receiving application are in the same app group.
I can't find the issue. It doesn't seem to be a problem with entitlements. Maybe an issue with the string formatting/conversion? Maybe I am not allowed to send distributed center notifications from the camera extension?
I am sending the notification calling:
func notifyChangeInUsage() {
os_log("Notifying the virtual camera change in usage", log: cdsLog, type: .info) // this is logged
DistributedNotificationCenter.default().postNotificationName(NSNotification.Name("VirtualCamUsageChanged"), object: nil, userInfo: nil, deliverImmediately: true)
}
And receiving it in the other end, subscribing with
std::string notification = "VirtualCamUsageChanged"
[mObserverClassInstance subscribe:@(notification.c_str())];
where subscribe
is the following method, which is tested to be working.
- (void)subscribe:(NSString *)notification {
[[NSDistributedNotificationCenter defaultCenter]
addObserver:self
selector:@selector(callCallback:)
name:notification
object:nil
suspensionBehavior:NSNotificationSuspensionBehaviorDeliverImmediately];
}
I use CMIOObjectAddPropertyListener
for this kind of communication (of state changes from the extension to an app).
That said, I'm surprised at this line
[mObserverClassInstance subscribe:@(notification.c_str())];
because I thought @ could only be used with string literals, so you could write
[mObserverClassInstance subscribe:@"VirtualCamUsageChanged"];
I've never seen @ used with a run-time expression.