When does NSURLConnection's initWithRequest return nil

后端 未结 5 1366
遥遥无期
遥遥无期 2021-02-18 23:51

Does anyone know in which situations initializing a NSURLConnection returns nil instead of the created connection. The documentation says it\'s possible but fails t

5条回答
  •  甜味超标
    2021-02-19 00:36

    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.

提交回复
热议问题