我已經爲了這個功能來檢查從UDP連接IOS比較兩個NSString的
- (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag
{
NSString *response = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSString *hello = @"hello";
if(response == hello){
[self debugPrint:[NSString stringWithFormat:@"ok"]];
}
else{
[self debugPrint:[NSString stringWithFormat:@"Read: \n%@",response]];
}
[response release];
}
我發送「你好」,但它不會再回來了「OK」的消息來的數據,它會跳轉到其他{ }
誰能幫助謝謝
thanx您的答案,但你的代碼不能正常工作,我嘗試了NSLOG(響應),並在調試屏幕中收到了你好,但是如果每次都返回false。另外,如果我嘗試類似: NSString * hello = @「hello」; NSString * hello2 = @「hello」; if([hello2 isEqualToString:hello]){} if返回true .. pf im confused! –