I create a local CFMessagePortRef using CFMessagePortCreateLocal and then use CFMachPortGetPort() to try to get the mach port from it like below:
NSString *portIdentifier = [[groupName stringByAppendingString:@"."] stringByAppendingString:sdkId];
NSString *portName = [[portIdentifier stringByAppendingString:@"."] stringByAppendingString:@"mach.port"];
CFMessagePortContext context = {0,(__bridge void *)self,nil,nil,nil};
self.sendPort = CFMessagePortCreateLocal(kCFAllocatorDefault, (__bridge CFStringRef)portName, &callback, &context, false); CFMachPortGetPort(ms->_port);
It works till iOS 15 but crashes on iOS 16. Can anyone help? I have defined below definition of __CFMessagePort:
struct __CFMessagePort {
CFRuntimeBase _base;
CFLock_t _lock;
CFStringRef _name;
CFMachPortRef _port; /* immutable; invalidated */
CFMutableDictionaryRef _replies;
int32_t _convCounter;
int32_t _perPID; /* zero if not per-pid, else pid */
CFMachPortRef _replyPort; /* only used by remote port; immutable once created; invalidated */
CFRunLoopSourceRef _source; /* only used by local port; immutable once created; invalidated */
dispatch_source_t _dispatchSource; /* only used by local port; invalidated */
dispatch_queue_t _dispatchQ; /* only used by local port */
CFMessagePortInvalidationCallBack _icallout;
CFMessagePortCallBack _callout; /* only used by local port; immutable */
CFMessagePortCallBackEx _calloutEx; /* only used by local port; immutable */
CFMessagePortContext _context; /* not part of remote port; immutable; invalidated */
};