これは私の ViewController.h の一部です:
@interface ViewController : UIViewController <UITextFieldDelegate> {
NSString *idUser;
NSMutableData *responseData;
NSMutableData *responseDataPersonal;
}
そして、これは私の.mです:
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
if (URLtype == 1)
responseData = [[NSMutableData alloc] init];
else if (URLtype = 3)
responseDataPersonal = [[NSMutableData alloc] init];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
if (URLtype == 1)
[responseData appendData:data];
else if (URLtype == 2)
[responseDataPersonal appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
...
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
if(URLtype == 1)
{
URLtype = 2;
// responseData contains this line of text: "true;1234567"
NSString *txt = [[[NSString alloc] initWithData:responseData encoding: NSASCIIStringEncoding] autorelease];
// idUser is set to 1234567
NSArray *txtString = [txt componentsSeparatedByString: @";"];
idUser = [txtString objectAtIndex: 1];
// This NSLog PERFECTLY logs 1234567
NSLog(@"%@",idUser);
NSString *post = @"task=something";
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:@"http://www.site.com/script.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
}
else if (URLtype == 2)
{
NSLog(@"%@ blabla", idUser);
}
}
コードの最後にある NSLog を機能させたいのですが、その行で EXC_BAD_ACCESS がクラッシュし続けます。その NSLog 行を次のように変更すると、非常に奇妙なことが原因であることが間違いありません。
NSString *idUser2 = [NSString stringWithFormat:@"%@", idUser];
NSLog(@"%@ BLA", idUser2);
..いつかクラッシュするか、毎回異なるメッセージをログに記録します! ここではいくつかの例を示します。
<__NSMallocBlock__: 0x777df70> BLA
また
HTTP connection to www.site.com:80 BLA
また
HTTPHeaderDict 0x856d870 [0x856d878]> { <CFBasicHash 0x855a2a0 [0x1b3b4d8]>{type = immutable dict, count = 5,
entries =>
1 : Content-Length = <CFString 0x85723d0 [0x1b3b4d8]>{contents = "36"}
3 : Accept-Encoding = <CFString 0x25b48f8 [0x1b3b4d8]>{contents = "gzip, deflate"}
4 : Content-Type = <CFString 0x3e420 [0x1b3b4d8]>{contents = "application/x-www-form-urlencoded"}
5 : Accept-Language = <CFString 0x8572a00 [0x1b3b4d8]>{contents = "en-us"}
6 : Accept = <CFString 0x25b4308 [0x1b3b4d8]>{contents = "*/*"}
}
} BLA
最近、それはクラッシュすることを好みます..でNSString *idUser2 line.
私は何を間違っていますか?:/ 前もって感謝します