Objective c 在NSObject类中实现时未调用IOS GCDAsyncSocket didReadData
我在NSObject类中实现GCDAsyncSocket委托,然后在viewController中调用它。 运行它时,我发现调用了'didConnectToHost'和'didWriteDataWithTag',但没有看到调用'didReadData'。这是我的密码: SocketUtils.hObjective c 在NSObject类中实现时未调用IOS GCDAsyncSocket didReadData,objective-c,gcdasyncsocket,Objective C,Gcdasyncsocket,我在NSObject类中实现GCDAsyncSocket委托,然后在viewController中调用它。 运行它时,我发现调用了'didConnectToHost'和'didWriteDataWithTag',但没有看到调用'didReadData'。这是我的密码: SocketUtils.h @interface SocketUtils : NSObject <GCDAsyncSocketDelegate> @property (nonatomic) void (^SocketC
@interface SocketUtils : NSObject <GCDAsyncSocketDelegate>
@property (nonatomic) void (^SocketCallback)(id data);
@property (nonatomic) NSString *message;
@property (nonatomic) UIViewController *vc;
+ (SocketUtils *) createSocket:(NSString *)message inViewController:(UIViewController *)vc;
- (void) connectToSocket;
@end
然后在viewController中,我调用:
socketUtils = [SocketUtils createSocket:@"GET_BOARD_CODE" inViewController:self];
socketUtils.SocketCallback = ^(id data) {
doSth();
};
我预测的第一件事是这个类的毁灭,但我试图保持所有@property=strong,但不起作用
有人能帮忙吗?经过多次搜索,我意识到我忘了在邮件中添加“\r\n”。好的,只需将1行代码更改为:
this.message = [message stringByAppendingString:@"\r\n"];
它的工作正如预期的那样
this.message = [message stringByAppendingString:@"\r\n"];