我正在使用NSOutputStream將數據從客戶端(IOS設備)輸出到服務器(PC設備)。 我可以成功發送數據到服務器,我只是想使用NSOutputStream添加當前時間。使用NSOutputStream將當前時間輸出到服務器
如何使用NSOutputStream發送當前時間?
這裏是我的代碼
- (IBAction)button1:(id)sender {
NSString *response = @" Today's Sunny \n ";
NSData *data = [[NSData alloc] initWithData:[response dataUsingEncoding:NSASCIIStringEncoding]];
[outputStream write:[data bytes] maxLength:[data length]];
NSDate *currentTime = [NSDate date];
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"hh:mm:ss"];
_timer.text = [formatter stringFromDate:currentTime];
//_timer is A label just for testing
///I'm trying to use outputStream to output currentTime like this
/// [outputStream write:[currentTime bytes] maxLength:[CurrentTime length]];
}
謝謝您的幫助。老實說,我仍然不明白如何使用您的代碼來輸出currentTime類似於我做的迴應 –
調用''[formatter stringFromDate:currentTime]''調用返回一個NSString實例,然後您可以調用UTF8String等等 –