0
我通過Bonjour發送一些數據:NSData合併在一起?
NSString *songString = [NSString stringWithFormat:@"sn:%@", [bHelp song]];
NSString *artistString = [NSString stringWithFormat:@"an:%@", [bHelp artist]];
NSData *imageData = [self PNGRepresentationOfImage:[bHelp getArtwork]];
NSData *songData = [songString dataUsingEncoding:NSUTF8StringEncoding];
NSData *artistData = [artistString dataUsingEncoding:NSUTF8StringEncoding];
[self.server sendData:songData error:nil];
[self.server sendData:artistData error:nil];
[self.server sendData:imageData error:nil];
然後接受它:
NSString *message = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
UIImage *image = [[UIImage alloc] initWithData:data];
if (message != nil) {
NSLog(message);
if ([message hasPrefix:@"sn:"]) {
_songName = [message stringByReplacingOccurrencesOfString:@"sn:" withString:@""];
} else if ([message hasPrefix:@"an:"]) {
_artistName = [message stringByReplacingOccurrencesOfString:@"an:" withString:@""];
}
return;
}
if (image != nil) {
self.albumImage = image;
return;
}
但songData
,artistData
和imageData
都收到一個。一個例子是:sn:BURN IT DOWNan:Linkin Park
如果我先發送imageData
,它永遠不會識別songData
和artistData
。如果我最後送imageData
,songData
和artistData
被搗成泥一起imageData
決不會被識別。
爲什麼有一個方法調用所有數據與多個調用與每個發送的數據包? @rmaddy – vqdave 2013-02-09 20:29:41