-
Notifications
You must be signed in to change notification settings - Fork 48
/
705.srt
4202 lines (3089 loc) · 92 KB
/
705.srt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:00:00.506 --> 00:00:10.676 A:middle
[ Silence ]
00:00:11.176 --> 00:00:11.806 A:middle
>> Good morning.
00:00:11.936 --> 00:00:17.056 A:middle
I'm Steve and I'm going to
talk today about what's new
00:00:17.056 --> 00:00:18.166 A:middle
in Foundation Networking.
00:00:19.706 --> 00:00:24.086 A:middle
So, Foundation Networking
gives you new API this year:
00:00:24.516 --> 00:00:25.476 A:middle
NSURLSession.
00:00:25.886 --> 00:00:27.376 A:middle
You might have heard this talked
00:00:27.376 --> 00:00:31.516 A:middle
about yesterday during the
multitasking APIs talk.
00:00:32.676 --> 00:00:35.586 A:middle
NSURLSession is a replacement
for NSURLConnection.
00:00:35.816 --> 00:00:38.206 A:middle
The big benefit it's going
00:00:38.206 --> 00:00:40.716 A:middle
to give you right off
the bat is out-of-process
00:00:40.766 --> 00:00:41.766 A:middle
background transfers.
00:00:41.766 --> 00:00:46.676 A:middle
It's a way of providing your
applications with the ability
00:00:46.676 --> 00:00:48.256 A:middle
to get work done when
you're not running.
00:00:48.946 --> 00:00:52.376 A:middle
It's available on iOS 7
but also in OS X Mavericks.
00:00:53.006 --> 00:00:56.206 A:middle
I'm mostly going to talk
about some enhancements
00:00:56.206 --> 00:00:57.746 A:middle
to the Foundation frameworks
00:00:57.746 --> 00:01:01.146 A:middle
around some specific
technologies, NSNetServices,
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:00:57.746 --> 00:01:01.146 A:middle
around some specific
technologies, NSNetServices,
00:01:01.146 --> 00:01:04.086 A:middle
single sign-on an iCloud
credential syncing.
00:01:05.275 --> 00:01:07.666 A:middle
So off the bat we
have, you know,
00:01:07.666 --> 00:01:12.756 A:middle
sort of a generic chart diagram
of where your application sits.
00:01:12.756 --> 00:01:17.146 A:middle
Your app sits on top of maybe
WebKit, MapKit, UIKit on iOS.
00:01:18.286 --> 00:01:20.166 A:middle
This also sits on top of
the Foundation Framework
00:01:20.306 --> 00:01:22.946 A:middle
which contains the
Cocoa container classes.
00:01:23.276 --> 00:01:25.906 A:middle
There are classes
for scheduling,
00:01:26.056 --> 00:01:28.756 A:middle
for file transfer
and networking.
00:01:29.866 --> 00:01:32.436 A:middle
Foundation sits on top of
CoreFoundation and CFNetwork.
00:01:32.506 --> 00:01:34.336 A:middle
Now, the reason there
is a separation there is
00:01:34.336 --> 00:01:36.376 A:middle
because a long time
ago, we have the support
00:01:36.376 --> 00:01:37.306 A:middle
in API called Carbon.
00:01:38.046 --> 00:01:41.206 A:middle
Nowadays, almost all the work
you guys do is going to be based
00:01:41.206 --> 00:01:42.196 A:middle
on the Foundation layer.
00:01:42.666 --> 00:01:45.356 A:middle
But the CoreFoundation/CFNetwork
layer is still there.
00:01:46.106 --> 00:01:50.246 A:middle
Lastly, networking on our
platform is built on top
00:01:50.246 --> 00:01:52.716 A:middle
of BSD sockets with
enhancements in the kernel
00:01:52.716 --> 00:01:55.476 A:middle
for our specific mobile needs.
00:01:58.396 --> 00:02:01.116 A:middle
In these different frameworks
at these different layers,
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:01:58.396 --> 00:02:01.116 A:middle
In these different frameworks
at these different layers,
00:02:01.116 --> 00:02:03.816 A:middle
there are different
APIs you can use.
00:02:03.816 --> 00:02:05.746 A:middle
BSD Networking uses BSD Sockets
00:02:05.746 --> 00:02:07.376 A:middle
and this is obviously
well known.
00:02:07.726 --> 00:02:11.826 A:middle
But on top of BSD
Sockets, the CoreFoundation
00:02:11.826 --> 00:02:15.106 A:middle
and CFNetwork layer gives
you access to a stream API
00:02:15.236 --> 00:02:17.606 A:middle
in CFStream which allows you
00:02:17.606 --> 00:02:21.036 A:middle
to access files streams
or sockets streams.
00:02:22.006 --> 00:02:26.346 A:middle
CFNetServices which allows you
to publish and subscribe to
00:02:26.346 --> 00:02:29.526 A:middle
or browse for Bonjour services.
00:02:31.036 --> 00:02:34.776 A:middle
And CFHTTPReadStream
which gives you a way
00:02:34.776 --> 00:02:38.976 A:middle
of issuing an HTTP request
and receiving the body
00:02:38.976 --> 00:02:41.936 A:middle
of the response as
the stream data.
00:02:43.556 --> 00:02:47.956 A:middle
Foundation though gives you some
nice Cocoa APIs on top of this.
00:02:48.416 --> 00:02:51.516 A:middle
NSStream is a direct
replacement for CFStream.
00:02:51.646 --> 00:02:53.666 A:middle
There's no need to use CFStream
if you're using NSStream.
00:02:54.186 --> 00:02:57.716 A:middle
NSNetServices just wraps
CFNetServices but it does
00:02:57.716 --> 00:03:02.276 A:middle
so in a delegate-based
Objective-C ARC compatible way.
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:02:57.716 --> 00:03:02.276 A:middle
so in a delegate-based
Objective-C ARC compatible way.
00:03:03.586 --> 00:03:06.906 A:middle
But NSURLConnection is more
than just a single class.
00:03:06.906 --> 00:03:10.616 A:middle
NSURLConnection is a suite of
classes, a bunch of classes,
00:03:10.616 --> 00:03:12.136 A:middle
it's also the name of a class
00:03:12.136 --> 00:03:15.416 A:middle
which is a little
confusing, but it's true.
00:03:15.906 --> 00:03:17.436 A:middle
Now, today we're
going to talk about--
00:03:17.436 --> 00:03:21.196 A:middle
we're going to talk about
NSNetServices a little later,
00:03:21.196 --> 00:03:23.676 A:middle
but mostly I'm going to
talk about NSURLSession
00:03:23.676 --> 00:03:26.326 A:middle
and then NSURLConnection, how
they relate, why you're going
00:03:26.326 --> 00:03:31.016 A:middle
to use one over the other, and
why you're not going to use one.
00:03:32.036 --> 00:03:33.456 A:middle
So going back in time
00:03:33.726 --> 00:03:37.806 A:middle
for NSURLConnection it
describes both a technology
00:03:37.916 --> 00:03:40.706 A:middle
that is the suite of
classes that are necessary
00:03:40.706 --> 00:03:44.826 A:middle
for doing HTTP loading,
and it's a specific class
00:03:45.316 --> 00:03:48.996 A:middle
in that there is an instance of
a class called NSURLConnection.
00:03:50.816 --> 00:03:53.706 A:middle
These classes were originally
written for Safari back
00:03:53.706 --> 00:03:55.526 A:middle
at the dawn of the millennium.
00:03:56.256 --> 00:03:58.946 A:middle
And they were first
made available in 2003
00:03:58.946 --> 00:04:02.276 A:middle
which I think the same year we
introduced the Power Mac G5 back
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:03:58.946 --> 00:04:02.276 A:middle
which I think the same year we
introduced the Power Mac G5 back
00:04:02.316 --> 00:04:05.336 A:middle
when the bits all
went the right way.
00:04:05.336 --> 00:04:06.096 A:middle
[ laughter, applause ]
00:04:06.096 --> 00:04:08.846 A:middle
It provides URL resolution--
thank you.
00:04:08.846 --> 00:04:11.976 A:middle
It provides URL resolution
and loading.
00:04:11.976 --> 00:04:14.306 A:middle
What that means is when
you have an arbitrary URL
00:04:14.306 --> 00:04:17.836 A:middle
like a file URL, NSURLConnection
is going to be used to load data
00:04:17.836 --> 00:04:22.646 A:middle
out of a file URL or out of a
data URL, or you can connect
00:04:22.646 --> 00:04:24.646 A:middle
to an FTP site, but mostly HTTP
00:04:24.646 --> 00:04:26.796 A:middle
and HTTPS is what people
end up using it for.
00:04:27.056 --> 00:04:30.036 A:middle
If you had your own protocol
that you wanted to register,
00:04:30.036 --> 00:04:32.846 A:middle
you could register that
in your process using the
00:04:32.846 --> 00:04:34.426 A:middle
NSURLProtocol class.
00:04:35.266 --> 00:04:39.856 A:middle
So NSURLConnection as an API
encompasses all the loading
00:04:39.856 --> 00:04:42.806 A:middle
machinery for the
Foundation layer.
00:04:44.036 --> 00:04:46.806 A:middle
Configuration of an
NSURLConnection occurs
00:04:46.846 --> 00:04:49.306 A:middle
by tweaking the NSURLRequest
object.
00:04:50.056 --> 00:04:52.676 A:middle
There are a couple of properties
you can set on an NSURLRequest,
00:04:52.676 --> 00:04:55.606 A:middle
some headers maybe you can set,
00:04:55.606 --> 00:04:57.646 A:middle
and some policy decisions
you can set.
00:04:58.176 --> 00:05:01.146 A:middle
But by and large,
NSURLConnection works by looking
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:04:58.176 --> 00:05:01.146 A:middle
But by and large,
NSURLConnection works by looking
00:05:01.146 --> 00:05:02.866 A:middle
at the global state
of your process
00:05:02.866 --> 00:05:04.236 A:middle
and global configuration
options.
00:05:04.756 --> 00:05:09.746 A:middle
NSURLConnection also gives you
access to proxies automatically,
00:05:09.746 --> 00:05:13.196 A:middle
and it challenges
you for credentials
00:05:13.296 --> 00:05:16.156 A:middle
when an HTTP request is
challenged by a server.
00:05:17.676 --> 00:05:21.456 A:middle
So what this looks like is you
create an NSURLRequest object,
00:05:21.616 --> 00:05:22.466 A:middle
you create it with the URL.
00:05:23.226 --> 00:05:24.446 A:middle
You configure it how you want
00:05:24.446 --> 00:05:27.656 A:middle
and then you create an
NSURLConnection object.
00:05:28.486 --> 00:05:32.446 A:middle
This object represents the
sort of the transient of state
00:05:32.446 --> 00:05:34.316 A:middle
of the request as
it's being made.
00:05:35.226 --> 00:05:37.276 A:middle
You create the connection
with a delegate
00:05:37.556 --> 00:05:40.446 A:middle
which receives information about
the load as it's occurring.
00:05:41.966 --> 00:05:43.906 A:middle
NSURLConnection then
looks in the global state.
00:05:44.176 --> 00:05:47.276 A:middle
It captures the cookie
store, cache, credentials
00:05:47.906 --> 00:05:51.196 A:middle
and any protocols that are
loaded in your process.
00:05:51.806 --> 00:05:56.186 A:middle
And it produces an NSURLResponse
Meta-Data object, and zero
00:05:56.186 --> 00:05:59.526 A:middle
or more NSData objects
which represent the payload
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:06:00.346 --> 00:06:03.816 A:middle
of what you're getting.
00:06:03.976 --> 00:06:07.286 A:middle
So in your process, you have
some networking needs, right?
00:06:07.286 --> 00:06:08.746 A:middle
And you're just going to keep
doing this over and over.
00:06:08.746 --> 00:06:09.546 A:middle
You're going to create
a request,
00:06:09.546 --> 00:06:11.726 A:middle
you create a connection,
bind it to your delegate,
00:06:12.526 --> 00:06:15.726 A:middle
and the framework is going to
bind to the global storage over
00:06:15.726 --> 00:06:18.516 A:middle
and over and over to produce
these response objects.
00:06:18.516 --> 00:06:21.156 A:middle
So a problem is if
another framework
00:06:21.156 --> 00:06:23.836 A:middle
in your application also needs
to use this global state,
00:06:24.126 --> 00:06:27.086 A:middle
it ends up using and overriding
the same global state.
00:06:27.086 --> 00:06:28.906 A:middle
You can't both have your
own protocol handler
00:06:28.906 --> 00:06:32.546 A:middle
as you can't both have your
own global cache objects.
00:06:33.186 --> 00:06:39.476 A:middle
So the first thing NSURLSession
does is it continues the process
00:06:39.476 --> 00:06:41.376 A:middle
of having confusion over
whether it's the name
00:06:41.376 --> 00:06:42.846 A:middle
of a class or a technology.
00:06:43.416 --> 00:06:44.326 A:middle
It's consistent.
00:06:45.116 --> 00:06:48.016 A:middle
[laughter] I know
that's important.
00:06:49.126 --> 00:06:51.826 A:middle
So it replaces NSURLConnection
as a technology,
00:06:52.186 --> 00:06:53.806 A:middle
but it preserves
almost all of it.
00:06:54.066 --> 00:06:58.596 A:middle
So NSURLConnection as a class
goes away and to be replaced
00:06:58.596 --> 00:06:59.996 A:middle
by an NSURLSession class,
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:07:01.076 --> 00:07:04.626 A:middle
and NSURLSession has some
additional classes associated
00:07:04.626 --> 00:07:06.466 A:middle
with it.
00:07:06.466 --> 00:07:08.886 A:middle
NSURLSession is the
configurable container
00:07:08.886 --> 00:07:10.586 A:middle
for putting network
requests in to.
00:07:11.236 --> 00:07:13.816 A:middle
It gives you better
HTTP options based
00:07:13.816 --> 00:07:15.136 A:middle
on feedback we've
gotten over the year.
00:07:15.196 --> 00:07:16.296 A:middle
So I want to be able to this.
00:07:16.296 --> 00:07:18.366 A:middle
Well, you couldn't
before, now you can.
00:07:19.686 --> 00:07:21.656 A:middle
It gives you access
to the storage objects
00:07:21.716 --> 00:07:23.086 A:middle
on a per session basis.
00:07:23.506 --> 00:07:25.386 A:middle
So you can have private
storage objects.
00:07:26.866 --> 00:07:28.426 A:middle
It improves authentication
handling
00:07:28.426 --> 00:07:32.056 A:middle
by having an explicit
authentication challenge
00:07:32.056 --> 00:07:34.826 A:middle
mechanism for connection-based
requests.
00:07:35.146 --> 00:07:39.796 A:middle
In NSURLConnection, when
a request was challenged
00:07:39.866 --> 00:07:43.216 A:middle
by a server to authenticate
against a pipe,
00:07:43.216 --> 00:07:47.336 A:middle
for instance an NTLM server,
the challenge would come back
00:07:47.466 --> 00:07:49.416 A:middle
for an arbitrary request.
00:07:49.416 --> 00:07:50.446 A:middle
You wouldn't know necessarily
00:07:50.446 --> 00:07:52.626 A:middle
which request would
get that challenge.
00:07:53.206 --> 00:07:55.226 A:middle
Now, challenges for
connection-based
00:07:55.226 --> 00:07:57.486 A:middle
of are sent directly to
the session delegate.
00:07:57.916 --> 00:08:02.546 A:middle
And I have this rich delegate
model which is kind of--
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:07:57.916 --> 00:08:02.546 A:middle
And I have this rich delegate
model which is kind of--
00:08:03.306 --> 00:08:04.586 A:middle
weird way of saying this,
00:08:05.646 --> 00:08:07.726 A:middle
but NSURLConnection had some
asynchronous convenience
00:08:07.726 --> 00:08:09.756 A:middle
routines, but the
problem with that is
00:08:09.756 --> 00:08:12.066 A:middle
that they wouldn't
use any delegates.
00:08:12.146 --> 00:08:14.796 A:middle
So either the asynchronous
routine would work
00:08:14.796 --> 00:08:17.226 A:middle
or it would fail, now you
can have a hybrid approach
00:08:17.226 --> 00:08:18.966 A:middle
where there is an asynchronous
convenience routine,
00:08:19.496 --> 00:08:23.186 A:middle
but it can also use your
delegate to do auth.
00:08:24.696 --> 00:08:27.946 A:middle
Session gives you uploads and
downloads to the filesystem,
00:08:27.946 --> 00:08:30.686 A:middle
that's sort of the preferred
way to do uploads and downloads.
00:08:32.596 --> 00:08:34.726 A:middle
There's sort of a
policy shift in Session
00:08:34.726 --> 00:08:38.986 A:middle
in that the configuration
goes in via Session instead
00:08:38.986 --> 00:08:44.155 A:middle
of NSURLRequest and we try and
separate the body of a request,
00:08:44.155 --> 00:08:46.136 A:middle
that is if you're doing
a post of an image,
00:08:46.546 --> 00:08:48.536 A:middle
from the request
envelope itself,
00:08:48.536 --> 00:08:51.186 A:middle
it's sort of like you don't
want to have a post star,
00:08:51.226 --> 00:08:52.026 A:middle
you want to have an envelope.
00:08:53.566 --> 00:08:56.526 A:middle
We've always had the separation
of that response meta data
00:08:57.386 --> 00:08:59.326 A:middle
from the actual payload itself.
00:08:59.326 --> 00:09:02.696 A:middle
So just trying to make this
API consistent between request,
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:08:59.326 --> 00:09:02.696 A:middle
So just trying to make this
API consistent between request,
00:09:02.696 --> 00:09:04.046 A:middle
response, payload, payload.
00:09:06.046 --> 00:09:07.586 A:middle
And NSURLSession
gives you access
00:09:07.586 --> 00:09:09.316 A:middle
to out-of-process
uploads and downloads.
00:09:10.436 --> 00:09:12.216 A:middle
The nice thing about
that is it's just a
00:09:12.216 --> 00:09:13.376 A:middle
configuration option.
00:09:13.376 --> 00:09:16.526 A:middle
When you create a session, you
specify, "Well, I want request
00:09:16.526 --> 00:09:18.846 A:middle
that go into the session,
could be done on a background."
00:09:19.386 --> 00:09:22.676 A:middle
What it allows us
to do though is
00:09:22.676 --> 00:09:25.306 A:middle
when your process is no longer
running, it's been suspended,
00:09:26.546 --> 00:09:30.296 A:middle
we can continue your download in
the background taking advantage
00:09:30.296 --> 00:09:33.636 A:middle
of everything we've learned
about the user's network use
00:09:33.636 --> 00:09:35.326 A:middle
and their battery life.
00:09:36.606 --> 00:09:42.226 A:middle
Using UIKit on iOS 7, we
key in, we take advantage
00:09:42.226 --> 00:09:44.006 A:middle
of the new multitasking APIs
00:09:44.566 --> 00:09:49.656 A:middle
so that your application can
have updated its interface
00:09:49.656 --> 00:09:52.076 A:middle
and provide a better
experience for the user.
00:09:52.076 --> 00:09:53.646 A:middle
You're going to download
your content
00:09:53.646 --> 00:09:56.946 A:middle
and have it available in the UI.
00:09:56.946 --> 00:09:59.516 A:middle
So this looks like,
well, it's a big object,
00:09:59.516 --> 00:10:01.436 A:middle
a big square object
called NSURLSession.
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:09:59.516 --> 00:10:01.436 A:middle
a big square object
called NSURLSession.
00:10:02.026 --> 00:10:04.176 A:middle
And you create a session
with a configuration object.
00:10:04.176 --> 00:10:07.956 A:middle
This is where you're going
to specify any HTTP options
00:10:08.076 --> 00:10:10.366 A:middle
and the various storage objects.
00:10:10.506 --> 00:10:12.566 A:middle
And you create a
session with a delegate.
00:10:13.316 --> 00:10:16.946 A:middle
Delegate gets called on a
sort of per request basis.
00:10:17.506 --> 00:10:19.996 A:middle
When you throw a request into a
session, you get a response out
00:10:19.996 --> 00:10:24.186 A:middle
and you keep using the
same session over and over.
00:10:24.386 --> 00:10:29.486 A:middle
So as Session is an
API, there are a bunch
00:10:29.486 --> 00:10:31.346 A:middle
of additional classes
you need to know about,
00:10:33.046 --> 00:10:35.146 A:middle
not nearly a bunch
but some more.
00:10:35.476 --> 00:10:38.396 A:middle
OK, so the first one is
the configuration object.
00:10:38.396 --> 00:10:40.486 A:middle
This is basically a
properties dictionary
00:10:41.086 --> 00:10:47.286 A:middle
of how you want the session
to behave, the task object
00:10:47.436 --> 00:10:50.046 A:middle
which really is the
replacement for connection.
00:10:50.366 --> 00:10:53.776 A:middle
So you can think about
Session is this larger ball,
00:10:53.776 --> 00:10:59.166 A:middle
and Connection goes away and
these taske objects get created
00:10:59.166 --> 00:11:00.326 A:middle
on a per request basis.
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:10:59.166 --> 00:11:00.326 A:middle
on a per request basis.
00:11:01.746 --> 00:11:03.886 A:middle
There is a delegate
protocol, the delegate object,
00:11:04.066 --> 00:11:05.956 A:middle
that you're going to
create to bind your session,
00:11:05.956 --> 00:11:07.556 A:middle
and then the session
object itself
00:11:07.636 --> 00:11:09.856 A:middle
which is a factory
for creating tasks.
00:11:10.726 --> 00:11:13.326 A:middle
You always create
one task per request.
00:11:14.716 --> 00:11:18.846 A:middle
So this is a classic
NSURLConnection example.
00:11:18.846 --> 00:11:21.736 A:middle
You create a delegate
object and a URL.
00:11:21.736 --> 00:11:25.466 A:middle
I keep using
setAllowsCellularAccess during
00:11:25.466 --> 00:11:27.386 A:middle
this talk as an example
of a property
00:11:27.386 --> 00:11:28.996 A:middle
that you might tweak
on a request.
00:11:29.066 --> 00:11:32.196 A:middle
So in this case, you
create an NSURLRequest
00:11:32.196 --> 00:11:34.036 A:middle
and then you modify
the request to say,
00:11:34.036 --> 00:11:36.006 A:middle
"I don't want this request
to go over cellular."
00:11:37.156 --> 00:11:40.026 A:middle
You create an NSURLConnection
object using the class method
00:11:40.026 --> 00:11:42.606 A:middle
connectionWithRequest, you
bind it to your delegate.
00:11:42.606 --> 00:11:45.726 A:middle
Your delegate then gets called
with didReceiveResponse,
00:11:45.776 --> 00:11:48.556 A:middle
didReceiveData, didFinishLoading
referencing this
00:11:48.596 --> 00:11:49.326 A:middle
connection object.
00:11:51.026 --> 00:11:54.816 A:middle
Now in NSURLSession, it's
pretty much the same,
00:11:54.816 --> 00:11:57.636 A:middle
but there is more configuration
upfront but less work later on.
00:11:58.346 --> 00:12:00.356 A:middle
You create a delegate conforming
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:11:58.346 --> 00:12:00.356 A:middle
You create a delegate conforming
00:12:00.576 --> 00:12:02.086 A:middle
to the session delegate
protocol.
00:12:02.456 --> 00:12:05.396 A:middle
You create a configuration
object.
00:12:05.886 --> 00:12:08.226 A:middle
There is a bunch
of class methods
00:12:08.226 --> 00:12:10.016 A:middle
for creating configuration
objects based
00:12:10.526 --> 00:12:12.416 A:middle
on what you're going to
try and do with them.
00:12:12.416 --> 00:12:14.806 A:middle
In this case the
defaultSessionConfiguration
00:12:14.806 --> 00:12:18.306 A:middle
object actually gives
you the same sort
00:12:18.306 --> 00:12:21.036 A:middle
of configuration options that
NSURLConnection would see.
00:12:21.126 --> 00:12:24.576 A:middle
So if you had created this task
with an NSURLConnection instead,
00:12:24.576 --> 00:12:26.486 A:middle
you would have sort
of the same behaviors.