When does NSURLConnection's initWithRequest return nil

时光总嘲笑我的痴心妄想 提交于 2019-12-03 22:39:29

I believe this can also be used when it fails to load, not just initialize. (The alloc is done separately - that's where low mem would probably bite you) So (I'm guessing) it could fail because you did not have a network available (3G/Wifi) or it simply failed to connect to the server. In any event, use:

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error

To get the actual failure.

You may be able to simulate this with an absence of a network - or even giving it a bad URL.

I guess the answer is "Never". Seems only way for NSURLConnection to return nil is failing at [super init]. ([super init] returning nil) But as super class of NSURLConnection is NSObject and NSObjects init just returns self (never nil)

PS: That's for IOS SDK 4.0, on emulator, can be different on device.

I would try all of the above except do it during low memory conditions. IE, I think it will happen when an internal malloc fails.

I thing this is caused if the request u specified has wrong or not all essential values

NSURLConnection returns nil if it is not created inside a runLoop.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!