5. Network Activity Log
5
Log all network requests
Simple way to see all events for every
request
HTTP headers and other related
information
Received/sent data for any request in
different formats
Including HTTPS requests
5пятница, 4 октября 13 г.
6. 2013-09-23 12:43:43.136 Start loading
2013-09-23 12:43:43.138 Will send request
2013-09-23 12:43:43.152 Received response
Response: 200
Header fields:{
"Cache-Control" = "no-cache";
Connection = "keep-alive";
"Content-Encoding" = gzip;
"Content-Length" = 351;
"Content-Type" = "text/xml; encoding=utf-8";
Date = "Mon, 23 Sep 2013 08:43:34 GMT";
Server = "nginx/1.2.1";
"X-YaMisc" = "region_id=9999;";
"X-YaReqFinish" = "1379925814.110185";
}
2013-09-23 12:43:43.153 Did receive data (685 bytes).
2013-09-23 12:43:43.153 Did finish loading.
2013-09-23 12:43:43.154 Stop loading
2013-09-23 12:43:44.169 Received response
Response: 200
Header fields:{
Connection = close;
"Content-Length" = 0;
"Content-Type" = "application/octet-stream";
Date = "Mon, 23 Sep 2013 08:43:35 GMT";
Server = nginx;
}
2013-09-23 12:43:44.169 Did finish loading.
2013-09-23 12:43:44.170 Stop loading
2013-09-23 12:43:58.314 Initialized
URL: http://www.yandex.com/?clid=2035378
HTTP Method: GET
HTTP Headers: {
Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
"User-Agent" = "Mozilla/5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Mobile/11A465";
Network Activity Log
6
NSLog(...)
6пятница, 4 октября 13 г.
7. "Content-Encoding" = gzip;
"Content-Type" = "text/css";
Date = "Mon, 23 Sep 2013 08:43:49 GMT";
Expires = "Thu, 31 Dec 2037 23:55:55 GMT";
"Last-Modified" = "Thu, 19 Sep 2013 18:25:56 GMT";
Server = "nginx/1.4.1";
"Transfer-Encoding" = Identity;
}
2013-09-23 12:43:58.476 Did receive data (23122 bytes).
2013-09-23 12:43:58.477 Did finish loading.
2013-09-23 12:43:58.477 Initialized
URL: http://yandex.st/www/1.686/com/pages-desktop/index/_index.js
HTTP Method: GET
HTTP Headers: {
Accept = "*/*";
Referer = "http://www.yandex.com/";
"User-Agent" = "Mozilla/5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Mobile/11A465";
}
HTTP Body:
2013-09-23 12:43:58.477 Start loading
2013-09-23 12:43:58.478 Will send request
2013-09-23 12:43:58.478 Start loading
2013-09-23 12:43:58.478 Will send request
2013-09-23 12:43:58.480 Received response
Response: 200
Header fields:{
"Access-Control-Allow-Origin" = "*";
"Cache-Control" = "max-age=315360000";
Connection = "keep-alive";
"Content-Encoding" = gzip;
"Content-Type" = "application/x-javascript";
Date = "Mon, 23 Sep 2013 08:43:49 GMT";
Expires = "Thu, 31 Dec 2037 23:55:55 GMT";
"Last-Modified" = "Thu, 10 May 2012 20:10:56 GMT";
Server = "nginx/1.4.1";
"Transfer-Encoding" = Identity;
}
2013-09-23 12:43:58.480 Did receive data (1553 bytes).
2013-09-23 12:43:58.481 Did finish loading.
2013-09-23 12:43:58.482 Received response
Response: 200
Header fields:{
"Accept-Ranges" = bytes;
"Access-Control-Allow-Origin" = "*";
"Cache-Cont
Network Activity Log
6
NSLog(...)
6пятница, 4 октября 13 г.
8. Network Activity Log
3rd party instruments
Wireshark
Charles
Fiddler
mitmproxy
– They are all good, but we want a look from inside the application.
7
7пятница, 4 октября 13 г.
9. Test Networking
8
Test application state after making
network requests:
– with various responses.
Test application state if a network request
fails due to numerous reasons:
– different HTTP status codes,
– timeout,
– etc.
8пятница, 4 октября 13 г.
11. Hybrid Applications
10
UIWebView as the main interface.
Ship static resources within the application
bundle.
Smart caching.
10пятница, 4 октября 13 г.
13. Extend iOS Networking
11
UIWebView support for new media formats
– WebP
– WebM
Application-wide support for new
protocols
– SPDY
11пятница, 4 октября 13 г.
17. @interface MyProtocol : NSURLProtocol
@end
[NSURLProtocol registerClass:[MyProtocol class]];
NSURLProtocol
15
Registration of the new protocol:
15пятница, 4 октября 13 г.
30. Network Activity Log
21
Log all network requests
Simple way to see all events for every
request
HTTP headers and other related
information
Received/sent data for any request in
different formats
Including HTTPS requests
21пятница, 4 октября 13 г.
41. Network Activity Log
28
URLProtocol Logger
Sample Code
github.com/dodonov/YACURLProtocolLogger
bit.ly/yac_nsurlprotocol
28пятница, 4 октября 13 г.
42. Test Networking
29
Test application state after making
network requests:
– with various responses.
Test application state if a network request
fails due to numerous reasons:
– different HTTP status codes,
– timeout,
– etc.
29пятница, 4 октября 13 г.
43. Test Networking
30
Special Test ProtocolNSURLConnection
iOS URLProtocols
NSURLConnection
Delegate
30пятница, 4 октября 13 г.
44. Test Networking
30
Special Test ProtocolNSURLConnection
iOS URLProtocols
NSURLConnection
Delegate
30пятница, 4 октября 13 г.
45. Test Networking
30
Special Test ProtocolNSURLConnection
iOS URLProtocols
NSURLConnection
Delegate
30пятница, 4 октября 13 г.
46. Test Networking
31
Sample test
- (void)testImageLoader
{
[NSURLProtocol registerClass:[ILCannedURLProtocol class]];
[ILCannedURLProtocol setCannedStatusCode:500];
[ILCannedURLProtocol setSupportedBaseURL:[NSURL URLWithString:@"yandex.ru"]];
ImageLoader *loader = [[ImageLoader alloc] init];
[loader load];
NSAssert([loader hasBadResponse], @"Loader should have bad response");
[NSURLProtocol unregisterClass:[ILCannedURLProtocol class]];
}
31пятница, 4 октября 13 г.
47. Test Networking
31
Sample test
- (void)testImageLoader
{
[NSURLProtocol registerClass:[ILCannedURLProtocol class]];
[ILCannedURLProtocol setCannedStatusCode:500];
[ILCannedURLProtocol setSupportedBaseURL:[NSURL URLWithString:@"yandex.ru"]];
ImageLoader *loader = [[ImageLoader alloc] init];
[loader load];
NSAssert([loader hasBadResponse], @"Loader should have bad response");
[NSURLProtocol unregisterClass:[ILCannedURLProtocol class]];
}
31пятница, 4 октября 13 г.
48. Test Networking
31
Sample test
- (void)testImageLoader
{
[NSURLProtocol registerClass:[ILCannedURLProtocol class]];
[ILCannedURLProtocol setCannedStatusCode:500];
[ILCannedURLProtocol setSupportedBaseURL:[NSURL URLWithString:@"yandex.ru"]];
ImageLoader *loader = [[ImageLoader alloc] init];
[loader load];
NSAssert([loader hasBadResponse], @"Loader should have bad response");
[NSURLProtocol unregisterClass:[ILCannedURLProtocol class]];
}
31пятница, 4 октября 13 г.
49. Test Networking
31
Sample test
- (void)testImageLoader
{
[NSURLProtocol registerClass:[ILCannedURLProtocol class]];
[ILCannedURLProtocol setCannedStatusCode:500];
[ILCannedURLProtocol setSupportedBaseURL:[NSURL URLWithString:@"yandex.ru"]];
ImageLoader *loader = [[ImageLoader alloc] init];
[loader load];
NSAssert([loader hasBadResponse], @"Loader should have bad response");
[NSURLProtocol unregisterClass:[ILCannedURLProtocol class]];
}
31пятница, 4 октября 13 г.
50. Test Networking
31
Sample test
- (void)testImageLoader
{
[NSURLProtocol registerClass:[ILCannedURLProtocol class]];
[ILCannedURLProtocol setCannedStatusCode:500];
[ILCannedURLProtocol setSupportedBaseURL:[NSURL URLWithString:@"yandex.ru"]];
ImageLoader *loader = [[ImageLoader alloc] init];
[loader load];
NSAssert([loader hasBadResponse], @"Loader should have bad response");
[NSURLProtocol unregisterClass:[ILCannedURLProtocol class]];
}
31пятница, 4 октября 13 г.
51. Test Networking
31
Sample test
- (void)testImageLoader
{
[NSURLProtocol registerClass:[ILCannedURLProtocol class]];
[ILCannedURLProtocol setCannedStatusCode:500];
[ILCannedURLProtocol setSupportedBaseURL:[NSURL URLWithString:@"yandex.ru"]];
ImageLoader *loader = [[ImageLoader alloc] init];
[loader load];
NSAssert([loader hasBadResponse], @"Loader should have bad response");
[NSURLProtocol unregisterClass:[ILCannedURLProtocol class]];
}
31пятница, 4 октября 13 г.
52. Test Networking
31
Sample test
- (void)testImageLoader
{
[NSURLProtocol registerClass:[ILCannedURLProtocol class]];
[ILCannedURLProtocol setCannedStatusCode:500];
[ILCannedURLProtocol setSupportedBaseURL:[NSURL URLWithString:@"yandex.ru"]];
ImageLoader *loader = [[ImageLoader alloc] init];
[loader load];
NSAssert([loader hasBadResponse], @"Loader should have bad response");
[NSURLProtocol unregisterClass:[ILCannedURLProtocol class]];
}
31пятница, 4 октября 13 г.
53. Test Networking
31
Sample test
- (void)testImageLoader
{
[NSURLProtocol registerClass:[ILCannedURLProtocol class]];
[ILCannedURLProtocol setCannedStatusCode:500];
[ILCannedURLProtocol setSupportedBaseURL:[NSURL URLWithString:@"yandex.ru"]];
ImageLoader *loader = [[ImageLoader alloc] init];
[loader load];
NSAssert([loader hasBadResponse], @"Loader should have bad response");
[NSURLProtocol unregisterClass:[ILCannedURLProtocol class]];
}
31пятница, 4 октября 13 г.
54. Test Networking
32
Testing via NSURLProtocol
github.com/InfiniteLoopDK/ILTesting
bit.ly/yac_nsurlprotocol
github.com/AliSoftware/OHHTTPStubs
32пятница, 4 октября 13 г.
55. Hybrid Applications
33
UIWebView as the main interface.
Ship static resources within the application
bundle.
Smart caching.
33пятница, 4 октября 13 г.
67. Extend iOS Networking
40
UIWebView support for new media formats
– WebP
– WebM
Application-wide support for new
protocols
– SPDY
40пятница, 4 октября 13 г.