开发者

NSURLConnection help

Also I know that anything that I create using alloc I have to release it, but when I try to release 'request' object using [request开发者_开发百科 release]; it throws the following error:

Program received signal:  “EXC_BAD_ACCESS”.
kill
error while killing target (killing anyway): warning: error on line 2179 of "/SourceCache/gdb/gdb-1510/src/gdb/macosx/macosx-nat-inferior.c" in function "macosx_kill_inferior_safe": (os/kern) failure (0x5x)


You are creating the request using requestWithURL:cachePolicy:timeoutInterval:. Since that method name doesn't begin with "alloc" or "new" or contain "copy", according to the Memory Management Rules you don't own it and so should not be releasing it (unless you call retain on it explicitly, of course).

As for efficiency, the code seems fine. Note though that if the user can trigger a second load before the first completes that you will have problems; the solution to that is to either prevent such a thing or to save the NSURLConnection object created in load into an ivar and then have the pseudo-delegate methods check that against the passed connection before doing anything else. It's also a good idea to set the ivar to nil when you release the object it formerly contained, as then you cannot accidentally use the released object. And I note the variable name for your "authentication failed" alert is alertsuccess, that's misleading ;)


Try this in your load function:

    NSMutableURLRequest *request;

request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:pageUrl]];

NSURLResponse *response;
NSError *error = [[NSError alloc] init];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];`

NSString *responseString = [NSString stringWithCString:[data bytes] length:[data length]]; `

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜