NSMachPort
- (void)handlePortMessage:(NSPortMessage *)message{
NSLog(@"11");
}
-------
Preson * p = [Preson new];
_p = p;
_port = [NSMachPort port];
_port.delegate = self;
[[NSRunLoop currentRunLoop] addPort:self.port forMode:( NSRunLoopCommonModes)];
[NSThread detachNewThreadSelector:@selector(tts:) toTarget:p withObject:_port];
- (void)tts:(NSPort *)port{
_vcPort = port;
_myPort = [NSMachPort new];
// [[NSRunLoop currentRunLoop] addPort:_myPort forMode:( NSDefaultRunLoopMode)];
[[NSRunLoop currentRunLoop] run];
_myPort.delegate = self;
[self sendPortMessage];
}
- (void)sendPortMessage{
NSDate *data1 = [@"111" dataUsingEncoding:NSUTF8StringEncoding];
NSDate *data2 = [@"1112222" dataUsingEncoding:NSUTF8StringEncoding];
NSMutableDictionary *array = [NSMutableArray arrayWithObjects:data2,self.myPort, nil];
BOOL isRes = [self.vcPort sendBeforeDate:[NSDate date]
msgid:1111102
components:array
from:self.myPort
reserved:0];
NSLog(@"%d",isRes);
}
- (void)handlePortMessage:(NSPortMessage *)message{
NSLog(@"11");
}
网友评论