J'ai donc ce morceau de code:Re codant pour une NSString renvoie null
if ([receivedPage hasPrefix:[NSString stringWithUTF8String:"\xC3\xAF\xC2\xBB\xC2\xBF"]]) // UTF-8 BOM 'EF BB BF' as UTF-16 chars
{
//DebugLog(@"converting calls list to UTF8");
receivedPage = [[[NSString alloc] initWithData:[receivedPage dataUsingEncoding:NSISOLatin1StringEncoding] encoding:NSUTF8StringEncoding] autorelease];
}
Cependant, parfois, quand le cas est vrai que le receivedPage devient nulle. pourquoi cela arriverait-il?
La page reçue est la valeur renvoyée de cette fonction:
NSURLResponse * response;
NSData * result = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:error];
if ([result length] > 0)
return [[[NSString alloc] initWithBytes: (const void*)[result bytes] length:[result length] encoding: encoding] autorelease];
else
{
if (error && *error)
DebugLog(@"URL request got error: %@",*error);
return nil;
}
L'encodage est ici NSISOLatin1StringEncoding (ne sais pas pourquoi, je suis quelqu'un débogage du code d'autre).
Une idée pourquoi cela se produirait?