クライアントとサーバーという2つの異なるMacで動作する2つの異なるアプリがあります。彼らは通信にHTTPを使用します。サーバーには、送信されたデータをカプセル化するplistファイルを公開するHTTPサーバーがあります。
例えば
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>sensorName</key>
<string>external</string>
<key>temperature</key>
<real>8.8</real>
</dict>
</plist>
クライアントはHTTPRequestを使用し、次のようにデータを収集します。
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
DDLogVerbose(@"URL Connection succeeded! Received %ld bytes of data",[testReceivedData length]);
NSString *errorDescription = nil;
NSPropertyListFormat format;
NSDictionary *incomingPlist = [NSPropertyListSerialization propertyListFromData:testReceivedData
mutabilityOption:NSPropertyListImmutable
format:&format
errorDescription:&errorDescription];
if (errorDescription)
{
DDLogError(@"Error converting data from web into plist: %@", errorDescription);
return;
}
DDLogVerbose(@"We got a plist from the server: %@", incomingPlist);
NSString *sensorName;
switch ([self currentCommandType]) {
case MFRemoteCommandTypeSensorIndex:
[self setSensorNames:[incomingPlist objectForKey:@"sensorNames"]];
break;
case MFRemoteCommandTypeTemperature:
sensorName = [incomingPlist objectForKey:@"sensorName"];
if (!sensorName)
{
DDLogError(@"Could not get sensorname from temperature plist: %@", incomingPlist);
break;
}
[self didReceiveTemperatureReading:(NSNumber *)[incomingPlist objectForKey:@"temperature"] ForSensorName:sensorName];
break;
default:
DDLogError(@"We should never get here.");
break;
}
[self clearCurrentRequest];
}
これまでのところ良好です....そしてデータは2つのアプリ間をうまく流れており、世界中ですべてが良好です。
ただし、原因がわからない場合があり、クライアントが温度値を誤って解釈することがあります。つまり、(上記のplistのように)温度NSNumberを8.8として解釈する代わりに、8.800000000000001または9.2を9.19999999999999として解釈します。
なぜそれがこれを行うのか誰かが知っていますか?奇妙なことに、それを行うときのパターンがないように見えます...
助けてくれてありがとう。