Compare commits
609 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
53837dc070 | |
|
|
c012fc9bb2 | |
|
|
67329ac512 | |
|
|
de149aedaa | |
|
|
fc0de57066 | |
|
|
473054879c | |
|
|
5d42a2ac5e | |
|
|
1e412927cc | |
|
|
eab4279140 | |
|
|
1bf62d475a | |
|
|
d8dc6a25aa | |
|
|
335a437b2e | |
|
|
cb7a3db23c | |
|
|
6545a3aba1 | |
|
|
9137b65d3b | |
|
|
09a9e74eae | |
|
|
5580c78282 | |
|
|
af7b587936 | |
|
|
86fc47bf7b | |
|
|
e6e5c5156b | |
|
|
cc510a6a4e | |
|
|
0dc2c41112 | |
|
|
f8a7b6bac7 | |
|
|
8e300c92a4 | |
|
|
44eac986bb | |
|
|
afaf306222 | |
|
|
5ac4e308c7 | |
|
|
f1a471e93f | |
|
|
11840d1313 | |
|
|
1f165b48ee | |
|
|
edb4bc3554 | |
|
|
990f85bce2 | |
|
|
b40124c95d | |
|
|
371533549c | |
|
|
d4d11ef0b0 | |
|
|
d6d9a5c233 | |
|
|
1fba8d99f3 | |
|
|
5cc5abae03 | |
|
|
19041b44c2 | |
|
|
d2b648e8ff | |
|
|
29c9c5d68a | |
|
|
4709774dc2 | |
|
|
0979d5b5f7 | |
|
|
11521aa040 | |
|
|
83240bd781 | |
|
|
32787175ac | |
|
|
0da78a4ce6 | |
|
|
09556f2d21 | |
|
|
ed7df926ea | |
|
|
16e1862afc | |
|
|
1ef791bad9 | |
|
|
32ca18b523 | |
|
|
1189f74c00 | |
|
|
469d8bbfd8 | |
|
|
2489074417 | |
|
|
b39fab3180 | |
|
|
974141f5a2 | |
|
|
e7fa11058b | |
|
|
8fe7ed5ca7 | |
|
|
cbb50e986e | |
|
|
68ae502797 | |
|
|
6e1b2aa8f0 | |
|
|
9c4fcfa844 | |
|
|
e41af47e2f | |
|
|
070cbc63ee | |
|
|
3b039d5910 | |
|
|
64f621081c | |
|
|
b426975b9f | |
|
|
fca618fb61 | |
|
|
9ecf488aff | |
|
|
a8fca6584f | |
|
|
47115e2593 | |
|
|
6a623cd58f | |
|
|
a45b222e70 | |
|
|
aa3598f3e0 | |
|
|
8aca4ca1b3 | |
|
|
cac21e106d | |
|
|
ee49d49d35 | |
|
|
6c650f910e | |
|
|
e709a04e89 | |
|
|
ee50027b88 | |
|
|
740cd7f090 | |
|
|
95468315fc | |
|
|
40ad58571b | |
|
|
30e9e0b516 | |
|
|
11c7efb6e1 | |
|
|
a090531604 | |
|
|
f9abff8988 | |
|
|
92e38160d6 | |
|
|
8dcc5b5ae7 | |
|
|
2b57abd44a | |
|
|
6b5f3236a8 | |
|
|
c8c00810dd | |
|
|
04a0431ae9 | |
|
|
ac98896099 | |
|
|
6406d8e526 | |
|
|
5b05d6c3cc | |
|
|
53ef2dc3c3 | |
|
|
0e4dbe1f24 | |
|
|
32923fa2e8 | |
|
|
dcb7985c5c | |
|
|
3b9c09142a | |
|
|
07fe1f0dfe | |
|
|
4068b93386 | |
|
|
0ecd13667d | |
|
|
7ba8208f17 | |
|
|
bf899e222f | |
|
|
c1f6aecd8b | |
|
|
782c682187 | |
|
|
233b6c2607 | |
|
|
65fbc3b85a | |
|
|
eec1b67497 | |
|
|
a16d007622 | |
|
|
577fefa26e | |
|
|
7a48ca6dad | |
|
|
20c77af44c | |
|
|
5f0594f043 | |
|
|
2d748f1e2f | |
|
|
944fd77965 | |
|
|
3af1a30ebb | |
|
|
996fea9e5b | |
|
|
6a28dc7ae9 | |
|
|
7e6bd60176 | |
|
|
b185621812 | |
|
|
05ce156764 | |
|
|
4786e98605 | |
|
|
60cab8b74c | |
|
|
14842f65f7 | |
|
|
4d1abffb32 | |
|
|
46c59183aa | |
|
|
6814af4ade | |
|
|
5a5c65d799 | |
|
|
d00d368cdb | |
|
|
49f6e532b5 | |
|
|
5f6287e535 | |
|
|
c011d1a88b | |
|
|
6edface2c3 | |
|
|
0df58e4995 | |
|
|
fb62c3fde1 | |
|
|
a45c722fc8 | |
|
|
25b4c178d9 | |
|
|
be560a4090 | |
|
|
df751e737b | |
|
|
a9ea132874 | |
|
|
c68d585e49 | |
|
|
4cfb12c01c | |
|
|
dcde40fc01 | |
|
|
ae11cf7e43 | |
|
|
0373b97f71 | |
|
|
5c7dc8c2e5 | |
|
|
ba335fc7d5 | |
|
|
33c13e79ca | |
|
|
f611d5e52b | |
|
|
4d6693c813 | |
|
|
ef578240b3 | |
|
|
d107a80189 | |
|
|
b111d6246a | |
|
|
511ce9992e | |
|
|
48d4adc210 | |
|
|
7e160e34a2 | |
|
|
466e4011d0 | |
|
|
08e9962b5e | |
|
|
7692bd2610 | |
|
|
2ee4bfe24b | |
|
|
8021ddd313 | |
|
|
db4f3fc9b6 | |
|
|
4499441661 | |
|
|
e622b290c9 | |
|
|
0e761f4aa7 | |
|
|
43115af147 | |
|
|
01a5cfb86b | |
|
|
ef1a1c3c47 | |
|
|
5d2963ac73 | |
|
|
26698f9da0 | |
|
|
48d10c1773 | |
|
|
1f65ca773f | |
|
|
dfc57ac94c | |
|
|
8f3b5e9330 | |
|
|
be0791233c | |
|
|
8f309e194e | |
|
|
d7bc2c0036 | |
|
|
737140d4cb | |
|
|
91b4251115 | |
|
|
393d4f1601 | |
|
|
78be42ee3b | |
|
|
4756d5dcbe | |
|
|
a51688168d | |
|
|
98989d9524 | |
|
|
f72f4c183d | |
|
|
9f719ca2f9 | |
|
|
79eb6e77c5 | |
|
|
66ddb23593 | |
|
|
9ae8f97425 | |
|
|
38a6edb02a | |
|
|
7e50d78c80 | |
|
|
704c630567 | |
|
|
4dd5a6681a | |
|
|
6690de8ccf | |
|
|
9c00f5cd7b | |
|
|
a897811eb5 | |
|
|
a66a790eb2 | |
|
|
17a4803661 | |
|
|
70dfe15144 | |
|
|
f2252b3499 | |
|
|
9620fffa64 | |
|
|
4f97897a41 | |
|
|
cd0c57f43e | |
|
|
c0c5e0d714 | |
|
|
2b68869927 | |
|
|
d56c4f3d22 | |
|
|
eac0b816f8 | |
|
|
85dde52173 | |
|
|
88ee3c6774 | |
|
|
6e947240a0 | |
|
|
7f99c01804 | |
|
|
72ed897c53 | |
|
|
843148139b | |
|
|
fb2063086d | |
|
|
beabb1842b | |
|
|
0ef0e07f77 | |
|
|
27e3038ec3 | |
|
|
210c13d124 | |
|
|
021607a845 | |
|
|
d41bfaf8c8 | |
|
|
6c29c8b009 | |
|
|
b3ad18ea56 | |
|
|
fd34a9a0fa | |
|
|
36f5b1e4e9 | |
|
|
76ed37636f | |
|
|
9ee89474ed | |
|
|
962bcb0323 | |
|
|
9b8aa8a12d | |
|
|
904f552e01 | |
|
|
56e2c6283c | |
|
|
f83abb578a | |
|
|
9cc8269dcd | |
|
|
62e2320f2d | |
|
|
17c3cf3aa0 | |
|
|
0f157d4332 | |
|
|
f8c7b9014c | |
|
|
ffa3962992 | |
|
|
4445bb2e47 | |
|
|
6468a92f32 | |
|
|
dadb740c47 | |
|
|
ce73619640 | |
|
|
0e047941e9 | |
|
|
761b00553b | |
|
|
feca1e8d0d | |
|
|
c59160e6da | |
|
|
e97fea7233 | |
|
|
4ceb6665b2 | |
|
|
21656fad68 | |
|
|
cded20c736 | |
|
|
0db489b32e | |
|
|
0ae0e34642 | |
|
|
6b137fb8ba | |
|
|
22750a18b2 | |
|
|
f7a2321107 | |
|
|
d90d115893 | |
|
|
327c444322 | |
|
|
cd977d70a4 | |
|
|
3d3471e490 | |
|
|
dad2a9254b | |
|
|
b271cbb371 | |
|
|
9af7460f2b | |
|
|
6698910fe1 | |
|
|
2cfa5ccb88 | |
|
|
afd1931c52 | |
|
|
0aa9b61bcc | |
|
|
542fc29808 | |
|
|
87384290a4 | |
|
|
0b50b57c13 | |
|
|
55f4beade5 | |
|
|
ef9a2798a7 | |
|
|
01931d1d89 | |
|
|
914ed45a44 | |
|
|
b596c9c120 | |
|
|
7f39e5e60e | |
|
|
936f47c005 | |
|
|
d9d9ceedf4 | |
|
|
759f0b9a3e | |
|
|
09b6ee941a | |
|
|
3d94e34415 | |
|
|
dfd2e2a2f1 | |
|
|
1a3ccc2e8d | |
|
|
125515d7f1 | |
|
|
a4c213ecbd | |
|
|
b0ff8516ab | |
|
|
c3c55784cb | |
|
|
52b2b70abf | |
|
|
62a8ee1ab6 | |
|
|
75944258f0 | |
|
|
83ad6fa977 | |
|
|
d2da4d0df4 | |
|
|
98082a6791 | |
|
|
2233b5e77d | |
|
|
ee3c351abd | |
|
|
66a6873b2c | |
|
|
54a772ebb9 | |
|
|
5f4d7f44b4 | |
|
|
5284ac6623 | |
|
|
43af50c555 | |
|
|
013ccba57b | |
|
|
3c82278727 | |
|
|
11125c4379 | |
|
|
249adae4f0 | |
|
|
3671cdde0f | |
|
|
6dfec7ccd9 | |
|
|
15cda1b561 | |
|
|
ec6b6e7267 | |
|
|
16eea9f104 | |
|
|
8bf39a9263 | |
|
|
a31b9d46a1 | |
|
|
f1041856d0 | |
|
|
044abf402d | |
|
|
55c7c6c8e1 | |
|
|
a8c4fa48b7 | |
|
|
b2909fb2da | |
|
|
3587b8d1e0 | |
|
|
2eef774eae | |
|
|
bf6be426f3 | |
|
|
934c9cc96d | |
|
|
7815923c48 | |
|
|
101ee70d94 | |
|
|
3bb13ef34a | |
|
|
b9d9456e21 | |
|
|
959e8db914 | |
|
|
e95224bf5f | |
|
|
f96302b427 | |
|
|
f6d7d60b98 | |
|
|
222e6bca0d | |
|
|
28109c4c70 | |
|
|
7d93374067 | |
|
|
c8df858f75 | |
|
|
681a7c4222 | |
|
|
9faee5356c | |
|
|
b88a552fba | |
|
|
cd4b925448 | |
|
|
db252d3654 | |
|
|
f080e38fb8 | |
|
|
6e4fbafa55 | |
|
|
0b47342b2f | |
|
|
39db378082 | |
|
|
894a1b1810 | |
|
|
99590ed6ec | |
|
|
2e708d3518 | |
|
|
30e034d60d | |
|
|
72a4e7b830 | |
|
|
30f672661c | |
|
|
a6f11b3ad7 | |
|
|
23874cdca4 | |
|
|
6d01e80409 | |
|
|
9b18145e56 | |
|
|
3a7adbbacf | |
|
|
8d668b4121 | |
|
|
50c4d1d2eb | |
|
|
c7330db3a6 | |
|
|
e5faad0026 | |
|
|
e0b3de4357 | |
|
|
c1fae30d63 | |
|
|
60b043755f | |
|
|
7855f89185 | |
|
|
fe4b3a088a | |
|
|
5615cf12de | |
|
|
af3e4f87e4 | |
|
|
eb91fdd3b8 | |
|
|
a8a69ab9b6 | |
|
|
136daba9df | |
|
|
e116aa5ce0 | |
|
|
ea663b9602 | |
|
|
4c18545dbc | |
|
|
03a751430d | |
|
|
81b5e72a9c | |
|
|
21b230f28f | |
|
|
76b552e21e | |
|
|
c38409b813 | |
|
|
673fca9113 | |
|
|
939f68d27e | |
|
|
7108b4f404 | |
|
|
654a9c98ea | |
|
|
233ef65f98 | |
|
|
99b7a090f8 | |
|
|
a8f5627052 | |
|
|
dfceb49d2b | |
|
|
e4b9ef512b | |
|
|
455188355f | |
|
|
9dcd68d5ee | |
|
|
e4104942ee | |
|
|
f6fdaeb6ae | |
|
|
364f5c4d7a | |
|
|
b81b7f9b4a | |
|
|
6c409cd8a0 | |
|
|
c76aba6c00 | |
|
|
2973aedd09 | |
|
|
0772019e4d | |
|
|
22782052a1 | |
|
|
6759e5982e | |
|
|
d6a7e1a8c3 | |
|
|
f5d0ddc270 | |
|
|
689586f73a | |
|
|
e6c0f56d1f | |
|
|
a0bc09df7d | |
|
|
5fd21e5ce1 | |
|
|
5b1451e11c | |
|
|
b29850b61b | |
|
|
7abff886ae | |
|
|
1ac6b92d9d | |
|
|
b9389350cb | |
|
|
67ed774c0c | |
|
|
825207d1d0 | |
|
|
77be243598 | |
|
|
074ce1f4cf | |
|
|
f5bd783b5e | |
|
|
3284e157ff | |
|
|
fe48ee54f3 | |
|
|
5b59677437 | |
|
|
12ee2d114b | |
|
|
f63a45add6 | |
|
|
a46f6149e5 | |
|
|
257da39e4d | |
|
|
caf3299c27 | |
|
|
3b32f1dd9d | |
|
|
f43dd896fa | |
|
|
542d930f10 | |
|
|
5f239c07b8 | |
|
|
241dafdd57 | |
|
|
a83f440269 | |
|
|
097b502eae | |
|
|
4566b67f98 | |
|
|
db614bc53e | |
|
|
5b3c54ba16 | |
|
|
2c5ee720ba | |
|
|
2ca5eab0e5 | |
|
|
7edeef9f1a | |
|
|
fca411224b | |
|
|
dab65ae8f5 | |
|
|
7764e47a36 | |
|
|
b1203d4a9e | |
|
|
acac18d6a2 | |
|
|
1c5060369e | |
|
|
36d5069b66 | |
|
|
29302f49b3 | |
|
|
6c79daad00 | |
|
|
6f02d77add | |
|
|
c335e1f597 | |
|
|
78a50d3929 | |
|
|
9a45faac3f | |
|
|
7ca81d0e36 | |
|
|
f7ee9d3375 | |
|
|
12715da31b | |
|
|
8fe72023dc | |
|
|
83843a493a | |
|
|
c9a24e294a | |
|
|
bdef7651f0 | |
|
|
88e6ca3e49 | |
|
|
1f202ed7a3 | |
|
|
c285074321 | |
|
|
db86161132 | |
|
|
065db6db0c | |
|
|
ec5369db13 | |
|
|
b49243d147 | |
|
|
710908ed91 | |
|
|
556665d8a7 | |
|
|
87aed00733 | |
|
|
63f5c9706e | |
|
|
1c463ad46b | |
|
|
dd682c92b5 | |
|
|
4b26a89ac4 | |
|
|
65163ea1ac | |
|
|
71de51d658 | |
|
|
efb0b359bf | |
|
|
938c2e0f3f | |
|
|
a883c63e9c | |
|
|
8b315a3585 | |
|
|
4e4ecd6d02 | |
|
|
b9bb5558e4 | |
|
|
1293582047 | |
|
|
f2546c7333 | |
|
|
986794012d | |
|
|
25d20ead49 | |
|
|
5f3e9272c8 | |
|
|
e34e8e6c65 | |
|
|
657bd81658 | |
|
|
1d8bfa6064 | |
|
|
1b394c14b6 | |
|
|
f717d507a5 | |
|
|
65acbec16d | |
|
|
c04e4efbf1 | |
|
|
2ad8d81768 | |
|
|
159f08279a | |
|
|
895249b312 | |
|
|
c13ec87b15 | |
|
|
10ff1892b4 | |
|
|
edc1d882e8 | |
|
|
4589e4a744 | |
|
|
8b16de2575 | |
|
|
42f9736972 | |
|
|
03eeb5842f | |
|
|
bdea43aec1 | |
|
|
6d8133557c | |
|
|
6dc02bd8f7 | |
|
|
c00c2e0ed4 | |
|
|
765a897120 | |
|
|
056e1e6562 | |
|
|
1e0af36f3f | |
|
|
6aca6a2100 | |
|
|
5e3384e77b | |
|
|
adffebc8fb | |
|
|
20bada38a0 | |
|
|
6d6796c31a | |
|
|
853ad83647 | |
|
|
77fad5cdf1 | |
|
|
21842747aa | |
|
|
d3a9a57a0d | |
|
|
8f8228e2a6 | |
|
|
48846851ee | |
|
|
f66b8b807e | |
|
|
639aa643eb | |
|
|
00918d0908 | |
|
|
f8d26f5172 | |
|
|
7ace0684f2 | |
|
|
25007e0b06 | |
|
|
616828b19b | |
|
|
2cbc5d71e0 | |
|
|
be4a9e0ac8 | |
|
|
4382672c4a | |
|
|
706c57308e | |
|
|
fbe3b95e8c | |
|
|
b201e137d8 | |
|
|
3f20a101c5 | |
|
|
8a541f6f31 | |
|
|
716fc38c93 | |
|
|
4335fb7e41 | |
|
|
3380e56a7d | |
|
|
51be4e298c | |
|
|
1a917d8239 | |
|
|
6878fba926 | |
|
|
1872fed8f0 | |
|
|
d0f8571dd2 | |
|
|
d020aea02f | |
|
|
75a76d983a | |
|
|
597a70a8b6 | |
|
|
1e20c3bd07 | |
|
|
d6d4a3c3db | |
|
|
2043094ab5 | |
|
|
c3ee589681 | |
|
|
c7f2665d05 | |
|
|
417feed2ca | |
|
|
d08d63fadd | |
|
|
8b63e9ac06 | |
|
|
2184e301c8 | |
|
|
8b0bd16f18 | |
|
|
ae4ecb16f6 | |
|
|
e5b05c3109 | |
|
|
00c200b8c1 | |
|
|
3645b6f41b | |
|
|
1d6ace1886 | |
|
|
8830781f8f | |
|
|
81d6bf91a9 | |
|
|
c79e6ffe04 | |
|
|
5df0eafc92 | |
|
|
94f51343b8 | |
|
|
83f476ba8f | |
|
|
63d60d9826 | |
|
|
9820cafe9b | |
|
|
340db263fa | |
|
|
03d28fee03 | |
|
|
0076bb9a55 | |
|
|
8a2ae7e547 | |
|
|
547345c7f5 | |
|
|
2bded38216 | |
|
|
5bbddae80d | |
|
|
f37474d5c8 | |
|
|
22cd4e49c4 | |
|
|
7e2763a500 | |
|
|
16e1a1fff6 | |
|
|
76d2fc8d0e | |
|
|
8c295cfe80 | |
|
|
a0df1a0dc2 | |
|
|
6f3debd7a2 | |
|
|
bbf0b5c0e6 | |
|
|
67a28d90ef | |
|
|
9f1ac247e7 | |
|
|
f356b86c29 | |
|
|
fa987a1818 | |
|
|
ffd9e02e1e | |
|
|
4540745382 | |
|
|
5f12cabdac | |
|
|
5dd219ffa7 | |
|
|
1e63f33a85 | |
|
|
3a6d9481c9 | |
|
|
f07a34da59 | |
|
|
8b37b16f45 | |
|
|
fb196ead9b | |
|
|
6faa7bfcb5 | |
|
|
282e817919 | |
|
|
b3895a5124 | |
|
|
b54f530925 | |
|
|
42468464b5 | |
|
|
95277bae45 | |
|
|
834ffada11 | |
|
|
4a4e496171 | |
|
|
8a95ce759c | |
|
|
18334bcc8f | |
|
|
48ce95f0ae | |
|
|
d76779196f | |
|
|
0b330b562b | |
|
|
4eaf0d7cee | |
|
|
0e7d3cde68 |
|
|
@ -0,0 +1,42 @@
|
||||||
|
# Contributing to SDWebImage
|
||||||
|
|
||||||
|
We want to make contributing to this project as easy and transparent as possible. Here are a few guidelines for making all our lives easier.
|
||||||
|
|
||||||
|
## Asking questions
|
||||||
|
|
||||||
|
We don't use GitHub as a support forum. For any usage questions that are not specific to the project itself, please ask on [Stack Overflow](https://stackoverflow.com/) instead. By doing so, you'll be more likely to quickly solve your problem, and you'll allow anyone else with the same question to find the answer. This also allows maintainers to focus on improving the project for others.
|
||||||
|
|
||||||
|
## Reporting Issues
|
||||||
|
|
||||||
|
A great way to contribute to the project is to send a detailed issue when you encounter an problem.
|
||||||
|
It is very important to check for the same problem or suggestion in the project's issue list first. If you find a match, just add a small comment there.
|
||||||
|
Doing this helps prioritize the most common problems and requests.
|
||||||
|
|
||||||
|
When reporting issues, please include the following:
|
||||||
|
|
||||||
|
- The platform name and version (e.g. iOS 8.1)
|
||||||
|
- The library version
|
||||||
|
- The integration method (e.g. CocoaPods/Carthage/manually)
|
||||||
|
- The version of Xcode you're using
|
||||||
|
- The full output of any stack trace or compiler error
|
||||||
|
- A small demo project that replicates the issue (especially if the way to reproduce the issue is not straight-forward)
|
||||||
|
- Any other details that would be useful in understanding the problem
|
||||||
|
|
||||||
|
This information will help us review and fix your issue faster.
|
||||||
|
|
||||||
|
|
||||||
|
Please do not be offended if we close your issue and reference this document.
|
||||||
|
If you believe the issue is truely a fault in the project’s codebase, re-open it.
|
||||||
|
|
||||||
|
## Pull Requests
|
||||||
|
|
||||||
|
We gladly accept any PR's assuming they are well written, documented ( if necessary ) and preferably have test code.
|
||||||
|
If you're unsure if we'll accept a new feature please open an issue requesting it and we can have a discussion before you code and submit a PR.
|
||||||
|
|
||||||
|
Checklist:
|
||||||
|
- Fork the repo and create your branch from the latest master (to minimize the conflicts)
|
||||||
|
- If you've added code that should be tested, add tests.
|
||||||
|
- If you've changed APIs, update the documentation.
|
||||||
|
- Ensure the test suite passes.
|
||||||
|
- Make sure your code lints (pod lib lint)
|
||||||
|
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
### New Issue Checklist
|
||||||
|
|
||||||
|
* [ ] I have read and understood the [CONTRIBUTING guide](https://github.com/rs/SDWebImage/blob/master/.github/CONTRIBUTING.md)
|
||||||
|
* [ ] I have read the [Documentation](http://cocoadocs.org/docsets/SDWebImage/)
|
||||||
|
* [ ] I have searched for a similar issue in the [project](https://github.com/rs/SDWebImage/issues) and found none
|
||||||
|
|
||||||
|
### Issue Info
|
||||||
|
|
||||||
|
Info | Value |
|
||||||
|
-------------------------|-------------------------------------|
|
||||||
|
Platform Name | e.g. ios / tvos
|
||||||
|
Platform Version | e.g. 8.0
|
||||||
|
SDWebImage Version | e.g. 3.7.6
|
||||||
|
Integration Method | e.g. carthage / cocoapods / manually
|
||||||
|
Xcode Version | e.g. Xcode 7.3
|
||||||
|
Repro rate | e.g. all the time (100%) / sometimes x% / only once
|
||||||
|
Repro with our demo prj | e.g. does it happen with our demo project?
|
||||||
|
Demo project link | e.g. link to a demo project that highlights the issue
|
||||||
|
|
||||||
|
### Issue Description and Steps
|
||||||
|
|
||||||
|
Please fill in the detailed description of the issue (full output of any stack trace, compiler error, ...) and the steps to reproduce the issue.
|
||||||
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
### New Pull Request Checklist
|
||||||
|
|
||||||
|
* [ ] I have read and understood the [CONTRIBUTING guide](https://github.com/rs/SDWebImage/blob/master/.github/CONTRIBUTING.md)
|
||||||
|
* [ ] I have read the [Documentation](http://cocoadocs.org/docsets/SDWebImage/)
|
||||||
|
* [ ] I have searched for a similar pull request in the [project](https://github.com/rs/SDWebImage/pulls) and found none
|
||||||
|
|
||||||
|
* [ ] I have updated this branch with the latest master to avoid conflicts (via merge from master or rebase)
|
||||||
|
* [ ] I have added the required tests to prove the fix/feature I am adding
|
||||||
|
* [ ] I have updated the documentation (if necesarry)
|
||||||
|
* [ ] I have run the tests and they pass
|
||||||
|
* [ ] I have run the lint and it passes (`pod lib lint`)
|
||||||
|
|
||||||
|
This merge request fixes / reffers to the following issues: ...
|
||||||
|
|
||||||
|
### Pull Request Description
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
.DS_Store
|
|
||||||
|
|
||||||
# Xcode
|
# Xcode
|
||||||
build/*
|
#
|
||||||
|
build/
|
||||||
*.pbxuser
|
*.pbxuser
|
||||||
!default.pbxuser
|
!default.pbxuser
|
||||||
*.mode1v3
|
*.mode1v3
|
||||||
|
|
@ -10,8 +9,22 @@ build/*
|
||||||
!default.mode2v3
|
!default.mode2v3
|
||||||
*.perspectivev3
|
*.perspectivev3
|
||||||
!default.perspectivev3
|
!default.perspectivev3
|
||||||
*.xcworkspace
|
project.xcworkspace
|
||||||
!default.xcworkspace
|
!default.xcworkspace
|
||||||
xcuserdata
|
xcuserdata
|
||||||
profile
|
*.xccheckout
|
||||||
*.moved-aside
|
*.moved-aside
|
||||||
|
DerivedData
|
||||||
|
*.hmap
|
||||||
|
*.ipa
|
||||||
|
*.xcuserstate
|
||||||
|
*.xcscmblueprint
|
||||||
|
|
||||||
|
# CocoaPods
|
||||||
|
#
|
||||||
|
# We recommend against adding the Pods directory to your .gitignore. However
|
||||||
|
# you should judge for yourself, the pros and cons are mentioned at:
|
||||||
|
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
|
||||||
|
#
|
||||||
|
Pods/
|
||||||
|
Podfile.lock
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
[submodule "Vendors/libwebp"]
|
[submodule "Vendors/libwebp"]
|
||||||
path = Vendors/libwebp
|
path = Vendors/libwebp
|
||||||
url = http://git.chromium.org/webm/libwebp.git
|
url = https://github.com/webmproject/libwebp
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
|
||||||
|
language: objective-c
|
||||||
|
|
||||||
|
osx_image: xcode7.1
|
||||||
|
|
||||||
|
before_install:
|
||||||
|
|
||||||
|
- export LANG=en_US.UTF-8
|
||||||
|
- env
|
||||||
|
- locale
|
||||||
|
- gem install cocoapods --no-rdoc --no-ri --no-document --quiet
|
||||||
|
- pod --version
|
||||||
|
- pod setup --silent > /dev/null
|
||||||
|
- pod repo update --silent
|
||||||
|
|
||||||
|
script:
|
||||||
|
|
||||||
|
- pod lib lint --allow-warnings
|
||||||
|
- xctool -workspace SDWebImage.xcworkspace -scheme 'SDWebImage' -sdk iphonesimulator build
|
||||||
|
- xctool -workspace SDWebImage.xcworkspace -scheme 'SDWebImage+WebP' -sdk iphonesimulator build
|
||||||
|
- xctool -workspace SDWebImage.xcworkspace -scheme 'SDWebImage+MKAnnotation' -sdk iphonesimulator build
|
||||||
|
|
||||||
|
- xctool -workspace SDWebImage.xcworkspace -scheme 'SDWebImage Demo' -sdk iphonesimulator build
|
||||||
|
|
||||||
|
- pod install --project-directory=Tests
|
||||||
|
- xctool -workspace SDWebImage.xcworkspace -scheme 'SDWebImage' -sdk iphonesimulator clean
|
||||||
|
- xctool -workspace SDWebImage.xcworkspace -scheme 'Tests' -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6,OS=latest' test
|
||||||
|
|
@ -0,0 +1,283 @@
|
||||||
|
## [3.8.1 Patch release for 3.8.0 on Jun 7th, 2016](https://github.com/rs/SDWebImage/releases/tag/3.8.1)
|
||||||
|
|
||||||
|
#### Fixes:
|
||||||
|
|
||||||
|
- SDWebImage 3.8.0 get wrong image #1589 - the issue was caused by the changes in 3.8.0 (Removed the URL query params from the filename (key) fb0cdb6d 1bf62d4 #1584 - fixes #1433 #1553 #1583 #1585) - Reverted.
|
||||||
|
- Note: The solution for those issues (i.e. #1433 #1553) is to set the `SDWebImageManager` `cacheKeyFilter` block and do their own calculations there.
|
||||||
|
|
||||||
|
## [3.8.0 Minor release - Replaces NSURLConnection (deprecated) with NSURLSession - on Jun 6th, 2016](https://github.com/rs/SDWebImage/releases/tag/3.8.0)
|
||||||
|
|
||||||
|
#### Infrastructure:
|
||||||
|
|
||||||
|
- Had to update the iOS deployment target to 7.0 from 5 - 6545a3a
|
||||||
|
|
||||||
|
#### Features:
|
||||||
|
|
||||||
|
- Replace deprecated `NSURLConnection` with `NSURLSession` #1578 #1586 - fixes #1291 #1318 #823 #1566 #1515
|
||||||
|
- Allow to customise cache and image downloader instances used with `SDWebImageManager` 86fc47bf7b - fixes #1398 #870
|
||||||
|
|
||||||
|
#### Fixes:
|
||||||
|
|
||||||
|
- Removed the URL query params from the filename (key) fb0cdb6d 1bf62d4 #1584 - fixes #1433 #1553 #1583 #1585
|
||||||
|
- Fixed the WebP build with the official 1.0.0 CocoaPods release f1a471e - fixes #1444
|
||||||
|
- Updated doc: `removeImageForKey:` not synchronous e6e5c51 - fixes #1379 #1415
|
||||||
|
|
||||||
|
## [3.7.6 Patch release for 3.7.0 on May 8th, 2016](https://github.com/rs/SDWebImage/releases/tag/3.7.6)
|
||||||
|
|
||||||
|
#### Infrastructure:
|
||||||
|
- Changed the **libwebp git url** so that people from China can access it - #1390 (from `https://chromium.googlesource.com/webm/libwebp` to `https://github.com/webmproject/libwebp`)
|
||||||
|
|
||||||
|
#### Features:
|
||||||
|
- Added `cancelAllDownloads` method to `SDWebImageDownloader` #1504
|
||||||
|
- Added API to save image `NSData` to disk cache: `[SDImageCache storeImageDataToDisk:forKey:]` #1453
|
||||||
|
|
||||||
|
#### Fixes:
|
||||||
|
- Fix #1449: Version 3.7.5 breaks semantic versioning (removes public API). Re-added `sd_setImageWithPreviousCachedImageWithURL:andPlaceholderImage:options:progress:completed:` and deprecated it. Will remove it in 4.0.0 b40124c
|
||||||
|
- Fix `CGContextDrawImage: invalid context 0x0` - #1496 (fixes #1401 #1454 #1457)
|
||||||
|
- Fix `CGBitmapContextCreateImage: invalid context 0x0` - #1464 (fixes #1423)
|
||||||
|
- Fix changed image size when loading from disk #1540 (fixes #1437)
|
||||||
|
- Repair memory release in the iPad environment #1549 (had to switch `#if TARGET_OS_IPHONE` to `#if TARGET_OS_IOS`)
|
||||||
|
- Fixed completion logic in `MKAnnotationView+WebCache` #1547
|
||||||
|
- Optimize the decoder to avoid unwanted blended layer - #1527 (fixes #1524)
|
||||||
|
- Protect against malformed frame for GIFs - #1447
|
||||||
|
- updated doc: #1462 #1466 #1486 #1532 #1461
|
||||||
|
|
||||||
|
## [3.7.5 Patch release for 3.7.0 on Jan 21st, 2016](https://github.com/rs/SDWebImage/releases/tag/3.7.5)
|
||||||
|
- fixed #1425 and #1426 - Continuation of Fix #1366, addresses #1350 and reverts a part of #1221 - from commit 6406d8e, the wrong usage of `dispatch_apply`
|
||||||
|
- fixed #1422 - Added a fallback for #976 so that if there are images saved with the old format (no extension), they can still be loaded
|
||||||
|
|
||||||
|
## [3.7.4 Patch release for 3.7.0 with tvOS support on Jan 8th, 2016](https://github.com/rs/SDWebImage/releases/tag/3.7.4)
|
||||||
|
|
||||||
|
#### Updates
|
||||||
|
- bumped `libwep` version to `0.4.4`
|
||||||
|
|
||||||
|
#### Features:
|
||||||
|
- added tvOS support #1327 and #1358 - fix #1368 and #1302
|
||||||
|
|
||||||
|
#### Fixes:
|
||||||
|
- #1217 contains several of the above fixes
|
||||||
|
- fix #391 -> option to cache only on Disk. will replace #1130
|
||||||
|
- fix #343 -> iCloud backup Option
|
||||||
|
- fix #371 -> CGBitmapContextCreate: unsupported parameter combination + #1268 #1412 #1340
|
||||||
|
- fix #576 -> scale set to screen scale
|
||||||
|
- fix #1035 -> progress queue with dispatch_async
|
||||||
|
- new feature -> activity indicator using auto layout. The activity indicator feature will replace #131
|
||||||
|
- #1218 progress callbacks now report on main thread - fixes #1035
|
||||||
|
- #1321 Added a new constructor to SDWebImagePrefetcher - replaces #956
|
||||||
|
- #976 append the original path extension to the hash filename - fixes #967
|
||||||
|
- replaced #999 with #1221
|
||||||
|
- added cache tests #1125
|
||||||
|
- #1236 fixes #1203
|
||||||
|
- bf899e2 fixes #1261 #1263 compilation issue CocoaPods vs non-CocoaPods
|
||||||
|
- #1367 fixes a bug where image scale & orientation are ignored when decoding / decompressing an image
|
||||||
|
- cac21e1 fixes #1366, addresses #1350 and reverts a part of #1221 - from commit 6406d8e, the wrong usage of dispatch_apply
|
||||||
|
- #1363 fixes #1361 sd_cancelBackgroundImageLoadForState
|
||||||
|
- #1348 Create a strong ref of weakOperation in the entry of The image download subOperation, use the strong ref instead weakOperation. At the same time, repair some logic of the 'If cancelled'
|
||||||
|
- dcb7985 replaces #1345 - Load local credential file
|
||||||
|
- #1323 don't to perform download if url is "" but not nil
|
||||||
|
- #1310 Added support for SDWebImageAvoidAutoSetImage option to UIButton and highlighted UIImageView categories
|
||||||
|
- #1308 Added Swift installation tips
|
||||||
|
- 32923fa Xcode 7.1 updates
|
||||||
|
- #1297 cleaner implementation of failedUrl error handling - fixes #1275
|
||||||
|
- #1280 Fix sd_animatedImageByScalingAndCroppingToSize
|
||||||
|
- Remove logging from the image prefetcher - #1276
|
||||||
|
- Fix typos #1256 #1257 #1258 #1331 #1290
|
||||||
|
|
||||||
|
## [3.7.3 Patch release for 3.7.0 with iOS8+ framework and Carthage on Jun 13th, 2015](https://github.com/rs/SDWebImage/releases/tag/3.7.3)
|
||||||
|
|
||||||
|
- Adds support for **iOS 8+ Framework and Carthage** [#1071](https://github.com/rs/SDWebImage/pull/1071) [#1081](https://github.com/rs/SDWebImage/pull/1081) [#1101](https://github.com/rs/SDWebImage/pull/1101)
|
||||||
|
|
||||||
|
- [Refactor] Use `NSMutableSet` for failed URLs' storage instead of array [#1076](https://github.com/rs/SDWebImage/pull/1076)
|
||||||
|
- Make a constant for the error domain [#1011](https://github.com/rs/SDWebImage/pull/1011)
|
||||||
|
- Improve operation behavior [#988](https://github.com/rs/SDWebImage/pull/988)
|
||||||
|
- Bug fix: `Collection <__NSArrayM: > was mutated while being enumerated` [#985](https://github.com/rs/SDWebImage/pull/985)
|
||||||
|
- added `SDWebImageAvoidAutoSetImage` option to avoid automatic image addition in `UIImageView` and let developer to do it himself [#1188](https://github.com/rs/SDWebImage/pull/1188)
|
||||||
|
- Added support for custom disk cache folder with fall back for caches directory [#1153](https://github.com/rs/SDWebImage/pull/1153)
|
||||||
|
- Added some files to the workspace so they are easier to edit [8431481](https://github.com/rs/SDWebImage/commit/8431481)
|
||||||
|
- Doc update [72ed897](https://github.com/rs/SDWebImage/commit/72ed897) [7f99c01](https://github.com/rs/SDWebImage/commit/7f99c01) [#1016](https://github.com/rs/SDWebImage/pull/1016) [#1038](https://github.com/rs/SDWebImage/pull/1038) [#1045](https://github.com/rs/SDWebImage/pull/1045)
|
||||||
|
- [Memory Issue] Clear `SDWebImagePrefetcher` `progressBlock` when it has completed [#1017](https://github.com/rs/SDWebImage/pull/1017)
|
||||||
|
- avoid warning `<Error>: ImageIO: CGImageSourceCreateWithData data parameter is nil` if `imageData` is nil [88ee3c6](https://github.com/rs/SDWebImage/commit/88ee3c6) [#1018](https://github.com/rs/SDWebImage/pull/1018)
|
||||||
|
- allow override `diskCachePath` [#1041](https://github.com/rs/SDWebImage/pull/1041)
|
||||||
|
- Use `__typeof(self)` when assigning `weak` reference for block [#1054](https://github.com/rs/SDWebImage/pull/1054)
|
||||||
|
- [Refactor] Implement cache cost calculation as a inline function [#1075](https://github.com/rs/SDWebImage/pull/1075)
|
||||||
|
- @3x support [9620fff](https://github.com/rs/SDWebImage/commit/9620fff) [#1005](https://github.com/rs/SDWebImage/pull/1005)
|
||||||
|
- Fix parenthesis to avoid crashes [#1104](https://github.com/rs/SDWebImage/pull/1104)
|
||||||
|
- Add `NSCache` countLimit property [#1140](https://github.com/rs/SDWebImage/pull/1140)
|
||||||
|
- `failedURLs` can be removed at the appropriate time [#1111](https://github.com/rs/SDWebImage/pull/1111)
|
||||||
|
- Purge `NSCache` on system memory notifications [#1143](https://github.com/rs/SDWebImage/pull/1143)
|
||||||
|
- Determines at runtime is `UIApplication` is available as per [#1082](https://github.com/rs/SDWebImage/issues/1082) [#1085](https://github.com/rs/SDWebImage/pull/1085)
|
||||||
|
- Fixes http://git.chromium.org/webm/libwebp.git/info/refs not valid [#1175](https://github.com/rs/SDWebImage/pull/1175) + Reverted [#1193](https://github.com/rs/SDWebImage/pull/1193) + [#1177](https://github.com/rs/SDWebImage/pull/1177)
|
||||||
|
- 404 image url was causing the test to fail [0e761f4](https://github.com/rs/SDWebImage/commit/0e761f4)
|
||||||
|
- Fix for transparency being lost in transformed images. [#1121](https://github.com/rs/SDWebImage/pull/1121)
|
||||||
|
- Add handling for additional error codes that shouldn't be considered a permanent failure [#1159](https://github.com/rs/SDWebImage/pull/1159)
|
||||||
|
- add webp accepted content type only if `WebP` enabled [#1178](https://github.com/rs/SDWebImage/pull/1178)
|
||||||
|
- fix `ImageIO: CGImageSourceCreateWithData` data parameter is nil [#1167](https://github.com/rs/SDWebImage/pull/1167)
|
||||||
|
- Applied patch for issue [#1074](https://github.com/rs/SDWebImage/issues/1074) SDWebImage residing in swift module breaks the debugger [#1138](https://github.com/rs/SDWebImage/pull/1138)
|
||||||
|
- Fixed URLs with trailing parameters get assigned an incorrect image scale value [#1157](https://github.com/rs/SDWebImage/issues/1157) [#1158](https://github.com/rs/SDWebImage/pull/1158)
|
||||||
|
- Add newline to avoid compiler warning in `WebImage.h` [#1199](https://github.com/rs/SDWebImage/pull/1199)
|
||||||
|
|
||||||
|
## [3.7.2 Updated patch release for 3.7.0 on Mar 17th, 2015](https://github.com/rs/SDWebImage/releases/tag/3.7.2)
|
||||||
|
|
||||||
|
#### Updates
|
||||||
|
- bumped `libwep` version to `0.4.3`
|
||||||
|
|
||||||
|
#### Features:
|
||||||
|
- implement `SDWebImageDownloaderAllowInvalidSSLCertificates` option - [#937](https://github.com/rs/SDWebImage/pull/937)
|
||||||
|
- flag to transform animated images (`SDWebImageTransformAnimatedImage`) - [#703](https://github.com/rs/SDWebImage/pull/703)
|
||||||
|
- allows user to override default `SDWebImageDownloaderOperation` - [#876](https://github.com/rs/SDWebImage/pull/876)
|
||||||
|
- adds option to decompress images and select prefetcher queue - [#996](https://github.com/rs/SDWebImage/pull/996)
|
||||||
|
|
||||||
|
#### Fixes:
|
||||||
|
- fixed [#809](https://github.com/rs/SDWebImage/issues/809) `cancelAll` crash - [#838](https://github.com/rs/SDWebImage/pull/838)
|
||||||
|
- fixed [#900](https://github.com/rs/SDWebImage/issues/900) by adding a new flag `SD_LOG_NONE` that allows silencing the SD logs from the Prefetcher
|
||||||
|
- fixed [#895](https://github.com/rs/SDWebImage/issues/895) unsafe setImage in `setImageWithURL:` - [#896](https://github.com/rs/SDWebImage/pull/896)
|
||||||
|
- fix `NSNotificationCenter` dispatch on subthreads - [#987](https://github.com/rs/SDWebImage/pull/987)
|
||||||
|
- fix `SDWebImageDownloader` threading issue - [#104](https://github.com/rs/SDWebImage/pull/104)6
|
||||||
|
- fixed duplicate failed urls are added into `failedURLs` - [#994](https://github.com/rs/SDWebImage/pull/994)
|
||||||
|
- increased default `maxConcurrentOperationCount`, fixes [#527](https://github.com/rs/SDWebImage/issues/527) - [#897](https://github.com/rs/SDWebImage/pull/897)
|
||||||
|
- handle empty urls `NSArray` - [#929](https://github.com/rs/SDWebImage/pull/929)
|
||||||
|
- decoding webp, depends on source image data alpha status - [#936](https://github.com/rs/SDWebImage/pull/936)
|
||||||
|
- fix [#610](https://github.com/rs/SDWebImage/issues/610) display progressive jpeg issue - [#840](https://github.com/rs/SDWebImage/pull/840)
|
||||||
|
- the code from `SDWebImageDownloaderOperation connection:didFailWithError:` should match the code from `connectionDidFinishLoading:`. This fixes [#872](https://github.com/rs/SDWebImage/issues/872) - [7f39e5e](https://github.com/rs/SDWebImage/commit/7f39e5e)
|
||||||
|
- `304 - Not Modified` HTTP status code handling - [#942](https://github.com/rs/SDWebImage/pull/942)
|
||||||
|
- cost compute fix - [#941](https://github.com/rs/SDWebImage/pull/941)
|
||||||
|
- initialise `kPNGSignatureData` data - [#981](https://github.com/rs/SDWebImage/pull/981)
|
||||||
|
|
||||||
|
#### Documentation
|
||||||
|
- documentation updated
|
||||||
|
|
||||||
|
## [3.7.1 Patch release for 3.7.0 on Jul 23rd, 2014](https://github.com/rs/SDWebImage/releases/tag/3.7.1)
|
||||||
|
|
||||||
|
- fixed `sd_imageOrientationFromImageData:` crash if imageSource is nil - [#819](https://github.com/rs/SDWebImage/pull/819) [#813](https://github.com/rs/SDWebImage/pull/813) [#808](https://github.com/rs/SDWebImage/issues/808) [#828](https://github.com/rs/SDWebImage/issues/828) - temporary fix
|
||||||
|
- fixed `SDWebImageCombinedOperation cancel` crash (also visible as `SDWebImageManager cancelAll`) - [28109c4](https://github.com/rs/SDWebImage/commit/28109c4) [#798](https://github.com/rs/SDWebImage/issues/798) [#809](https://github.com/rs/SDWebImage/issues/809)
|
||||||
|
- fixed duplicate symbols when using with webp via pods - [#795](https://github.com/rs/SDWebImage/pull/795)
|
||||||
|
- fixed missing `mark` from `pragma mark` - [#827](https://github.com/rs/SDWebImage/pull/827)
|
||||||
|
|
||||||
|
## [3.7.0 Xcode6, arm64, highlight UIImageView, imageURL ref, NTLM, ... on Jul 14th, 2014](https://github.com/rs/SDWebImage/releases/tag/3.7.0)
|
||||||
|
|
||||||
|
## Features
|
||||||
|
- Add category for imageView's highlighted state `UIImageView+HighlightedWebCache` - [#646](https://github.com/rs/SDWebImage/pull/646) [#765](https://github.com/rs/SDWebImage/pull/765)
|
||||||
|
- Keep a reference to the image URL - [#560](https://github.com/rs/SDWebImage/pull/560)
|
||||||
|
- Pass imageURL in completedBlock - [#770](https://github.com/rs/SDWebImage/pull/770)
|
||||||
|
- Implemented NTLM auth support. Replaced deprecated auth challenge methods from `NSURLConnectionDelegate` - [#711](https://github.com/rs/SDWebImage/pull/711) [50c4d1d](https://github.com/rs/SDWebImage/commit/50c4d1d)
|
||||||
|
- Ability to suspend image downloaders `SDWebImageDownloader setSuspended:` - [#734](https://github.com/rs/SDWebImage/pull/734)
|
||||||
|
- Delay the loading of the placeholder image until after load - [#701](https://github.com/rs/SDWebImage/pull/701)
|
||||||
|
- Ability to save images to cache directly - [#714](https://github.com/rs/SDWebImage/pull/714)
|
||||||
|
- Support for image orientation - [#764](https://github.com/rs/SDWebImage/pull/764)
|
||||||
|
- Added async `SDImageCache removeImageForKey:withCompletion:` - [#732](https://github.com/rs/SDWebImage/pull/732) [cd4b925](https://github.com/rs/SDWebImage/commit/cd4b925)
|
||||||
|
- Exposed cache paths - [#339](https://github.com/rs/SDWebImage/issues/339)
|
||||||
|
- Exposed `SDWebImageManager cacheKeyForURL:` - [5fd21e5](https://github.com/rs/SDWebImage/commit/5fd21e5)
|
||||||
|
- Exposing `SDWebImageManager` instance from the `SDWebImagePrefetcher` class - [6c409cd](https://github.com/rs/SDWebImage/commit/6c409cd)
|
||||||
|
- `SDWebImageManager` uses the shared instance of `SDWebImageDownloader` - [0772019](https://github.com/rs/SDWebImage/commit/0772019)
|
||||||
|
- Refactor the cancel logic - [#771](https://github.com/rs/SDWebImage/pull/771) [6d01e80](https://github.com/rs/SDWebImage/commit/6d01e80) [23874cd](https://github.com/rs/SDWebImage/commit/23874cd) [a6f11b3](https://github.com/rs/SDWebImage/commit/a6f11b3)
|
||||||
|
- Added method `SDWebImageManager cachedImageExistsForURL:` to check if an image exists in either the disk OR the memory cache - [#644](https://github.com/rs/SDWebImage/pull/644)
|
||||||
|
- Added option to use the cached image instead of the placeholder for `UIImageView`. Replaces [#541](https://github.com/rs/SDWebImage/pull/541) - [#599](https://github.com/rs/SDWebImage/issues/599) [30f6726](https://github.com/rs/SDWebImage/commit/30f6726)
|
||||||
|
- Created workspace + added unit tests target
|
||||||
|
- Updated documentation - [#476](https://github.com/rs/SDWebImage/issues/476) [#384](https://github.com/rs/SDWebImage/issues/384) [#526](https://github.com/rs/SDWebImage/issues/526) [#376](https://github.com/rs/SDWebImage/pull/376) [a8f5627](https://github.com/rs/SDWebImage/commit/a8f5627)
|
||||||
|
|
||||||
|
## Bugfixes
|
||||||
|
- Fixed Xcode 6 builds - [#741](https://github.com/rs/SDWebImage/pull/741) [0b47342](https://github.com/rs/SDWebImage/commit/0b47342)
|
||||||
|
- Fixed `diskImageExistsWithKey:` deadlock - [#625](https://github.com/rs/SDWebImage/issues/625) [6e4fbaf](https://github.com/rs/SDWebImage/commit/6e4fbaf)
|
||||||
|
For consistency, added async methods in `SDWebImageManager` `cachedImageExistsForURL:completion:` and `diskImageExistsForURL:completion:`
|
||||||
|
- Fixed race condition that causes cancellation of one download operation to stop a run loop that is now used for another download operation. Race is introduced through `performSelector:onThread:withObject:waitUntilDone:` - [#698](https://github.com/rs/SDWebImage/pull/698)
|
||||||
|
- Fixed race condition between operation cancelation and loading finish - [39db378](https://github.com/rs/SDWebImage/commit/39db378) [#621](https://github.com/rs/SDWebImage/pull/621) [#783](https://github.com/rs/SDWebImage/pull/783)
|
||||||
|
- Fixed race condition in SDWebImageManager if one operation is cancelled - [f080e38](https://github.com/rs/SDWebImage/commit/f080e38) [#699](https://github.com/rs/SDWebImage/pull/699)
|
||||||
|
- Fixed issue where cancelled operations aren't removed from `runningOperations` - [#68](https://github.com/rs/SDWebImage/issues/68)
|
||||||
|
- Should not add url to failedURLs when timeout, cancel and so on - [#766](https://github.com/rs/SDWebImage/pull/766) [#707](https://github.com/rs/SDWebImage/issues/707)
|
||||||
|
- Fixed potential *object mutated while being enumerated* crash - [#727](https://github.com/rs/SDWebImage/pull/727) [#728](https://github.com/rs/SDWebImage/pull/728) (revert a threading fix from [#727](https://github.com/rs/SDWebImage/pull/727))
|
||||||
|
- Fixed `NSURLConnection` response statusCode not valid (e.g. 404), downloader never stops its runloop and hangs the operation queue - [#735](https://github.com/rs/SDWebImage/pull/735)
|
||||||
|
- Fixed `SDWebImageRefreshCached` bug for large images - [#744](https://github.com/rs/SDWebImage/pull/744)
|
||||||
|
- Added proper handling for `SDWebImageDownloaderLowPriority` - [#713](https://github.com/rs/SDWebImage/issues/713) [#745](https://github.com/rs/SDWebImage/issues/745)
|
||||||
|
- Fixed fixing potential bug when sending a nil url for UIButton+WebCache - [#761](https://github.com/rs/SDWebImage/issues/761) [#763](https://github.com/rs/SDWebImage/pull/763)
|
||||||
|
- Fixed issue [#529](https://github.com/rs/SDWebImage/pull/529) - if the `cacheKeyFilter` was set, this was ignored when computing the `scaledImageForKey`. For most of the developers that did not set `cacheKeyFilter`, the code will work exactly the same - [eb91fdd](https://github.com/rs/SDWebImage/commit/eb91fdd)
|
||||||
|
- Returning error in setImage completedBlock if the url was nil. Added `dispatch_main_async_safe` macro - [#505](https://github.com/rs/SDWebImage/issues/505) [af3e4f8](https://github.com/rs/SDWebImage/commit/af3e4f8)
|
||||||
|
- Avoid premature completion of prefetcher if request fails - [#751](https://github.com/rs/SDWebImage/pull/751)
|
||||||
|
- Return nil from `SDScaledImageForKey` if the input image is nil - [#365](https://github.com/rs/SDWebImage/issues/365) [#750](https://github.com/rs/SDWebImage/pull/750)
|
||||||
|
- Do not load placeholder image if `SDWebImageDelayPlaceholder` option specified - [#780](https://github.com/rs/SDWebImage/pull/780)
|
||||||
|
- Make sure we call the `startPrefetchingAtIndex:` method from main queue - [#694](https://github.com/rs/SDWebImage/pull/694)
|
||||||
|
- Save image in cache before calling completion block - [#700](https://github.com/rs/SDWebImage/pull/700)
|
||||||
|
- Fixed arm64 warnings - [#685](https://github.com/rs/SDWebImage/pull/685) [#720](https://github.com/rs/SDWebImage/pull/720) [#721](https://github.com/rs/SDWebImage/pull/721) [#687](https://github.com/rs/SDWebImage/pull/687)
|
||||||
|
- Improved logging - [#721](https://github.com/rs/SDWebImage/pull/721)
|
||||||
|
- Added `SDWebImageCompat.m` to `SDWebImage+MKAnnotation` target
|
||||||
|
|
||||||
|
## [3.6 Fix and cleanup on Mar 24th, 2014](https://github.com/rs/SDWebImage/releases/tag/3.6)
|
||||||
|
|
||||||
|
## [3.5.4 ARM64 Support on Feb 24th, 2014](https://github.com/rs/SDWebImage/releases/tag/3.5.4)
|
||||||
|
|
||||||
|
## [3.5.3 on Jan 7th, 2014](https://github.com/rs/SDWebImage/releases/tag/3.5.3)
|
||||||
|
|
||||||
|
## [3.5.2 on Jan 2nd, 2014](https://github.com/rs/SDWebImage/releases/tag/3.5.2)
|
||||||
|
|
||||||
|
## [3.5.1 on Dec 3rd, 2013](https://github.com/rs/SDWebImage/releases/tag/3.5.1)
|
||||||
|
|
||||||
|
## [3.5 WebP Target, iOS 7, Fixes on Oct 4th, 2013](https://github.com/rs/SDWebImage/releases/tag/3.5)
|
||||||
|
|
||||||
|
- Fix iOS 7 related issues
|
||||||
|
- Move `WebP` support to a dedicated target
|
||||||
|
- Removed strong reference to `UIImageView` which was causing a crash in the nested block
|
||||||
|
- Fix timeout issue
|
||||||
|
- Add some methods that allow to check if an image exists on disk without taking it off disk and decompressing it first
|
||||||
|
|
||||||
|
## [3.4 Animated image category, bug fixes on Aug 13th, 2013](https://github.com/rs/SDWebImage/releases/tag/3.4)
|
||||||
|
|
||||||
|
- Add `calculateSizeWithCompletionBlock`
|
||||||
|
- Add multiple download of images for animationImages property of `UIImageView`
|
||||||
|
- Add background task for disk cleanup [#306](https://github.com/rs/SDWebImage/issues/306)
|
||||||
|
- Fix dead thread issue on iOS 5 [#444](https://github.com/rs/SDWebImage/pull/444), [#399](https://github.com/rs/SDWebImage/issues/399), [#466](https://github.com/rs/SDWebImage/issues/466)
|
||||||
|
- Make IO operations cancelable to fix perf issue with heavy images [#462](https://github.com/rs/SDWebImage/issues/462)
|
||||||
|
- Fix crash `Collection <__NSArrayM: ...> was mutated while being enumerated.` [#471](https://github.com/rs/SDWebImage/pull/471)
|
||||||
|
|
||||||
|
## [3.3 WebP, Animated GIF and more on Jun 14th, 2013](https://github.com/rs/SDWebImage/releases/tag/3.3)
|
||||||
|
|
||||||
|
- WebP image format support [#410](https://github.com/rs/SDWebImage/issues/410)
|
||||||
|
- Animated GIF support [#375](https://github.com/rs/SDWebImage/pull/375)
|
||||||
|
- Custom image cache search paths [#156](https://github.com/rs/SDWebImage/pull/156)
|
||||||
|
- Bug fixes
|
||||||
|
|
||||||
|
## [3.2 Bug fixes on Mar 13th, 2013](https://github.com/rs/SDWebImage/releases/tag/3.2)
|
||||||
|
|
||||||
|
- `SDWebImageRefreshCached` download option [#326](https://github.com/rs/SDWebImage/pull/326)
|
||||||
|
- New `SDWebImageManager` delegate methods [ebd63a88c1](https://github.com/rs/SDWebImage/commit/ebd63a88c116ac7acfbeded5c84d0fffa2443438)
|
||||||
|
- Fix long standing issue with alpha en JPEGs [#299](https://github.com/rs/SDWebImage/pull/299)
|
||||||
|
- Add synchronous disk-cache loading method [#297](https://github.com/rs/SDWebImage/pull/297)
|
||||||
|
- Fix `SDWebImageCacheMemoryOnly` flag
|
||||||
|
- Bug fixes
|
||||||
|
|
||||||
|
## [3.1 Bug fixes on Jan 21st, 2013](https://github.com/rs/SDWebImage/releases/tag/3.1)
|
||||||
|
|
||||||
|
## [3.0 Complete rewrite on Nov 29th, 2012](https://github.com/rs/SDWebImage/releases/tag/3.0)
|
||||||
|
|
||||||
|
- Complete rewrite of the library using `GCD`, `ARC`, `NSCache` and blocks
|
||||||
|
- Drop compatibility with iOS 3 and 4
|
||||||
|
|
||||||
|
## [2.7.4 Bug fixes on Nov 14th, 2012](https://github.com/rs/SDWebImage/releases/tag/2.7.4)
|
||||||
|
|
||||||
|
## [2.7.3 on Nov 3rd, 2012](https://github.com/rs/SDWebImage/releases/tag/2.7.3)
|
||||||
|
|
||||||
|
## [2.7.2 on Oct 23rd, 2012](https://github.com/rs/SDWebImage/releases/tag/2.7.2)
|
||||||
|
|
||||||
|
## [2.7.1 on Oct 19th, 2012](https://github.com/rs/SDWebImage/releases/tag/2.7.1)
|
||||||
|
|
||||||
|
## [2.7 on Sep 8th, 2012](https://github.com/rs/SDWebImage/releases/tag/2.7)
|
||||||
|
|
||||||
|
## [2.6 on May 4th, 2012](https://github.com/rs/SDWebImage/releases/tag/2.6)
|
||||||
|
|
||||||
|
## [2.5 on Mar 22nd, 2012](https://github.com/rs/SDWebImage/releases/tag/2.5)
|
||||||
|
|
||||||
|
## [2.4 on Oct 1st, 2011](https://github.com/rs/SDWebImage/releases/tag/2.4)
|
||||||
|
|
||||||
|
## [2.3 on Sep 16th, 2010](https://github.com/rs/SDWebImage/releases/tag/2.3)
|
||||||
|
|
||||||
|
## [2.2 on Aug 29th, 2010](https://github.com/rs/SDWebImage/releases/tag/2.2)
|
||||||
|
|
||||||
|
## [2.1.0 on Jun 12th, 2010](https://github.com/rs/SDWebImage/releases/tag/2.1.0)
|
||||||
|
|
||||||
|
## [2.1 on Jun 12th, 2010](https://github.com/rs/SDWebImage/releases/tag/2.1)
|
||||||
|
|
||||||
|
## [2.0.0 on Jun 9th, 2010](https://github.com/rs/SDWebImage/releases/tag/2.0.0)
|
||||||
|
|
||||||
|
## [2.0 on Jun 9th, 2010](https://github.com/rs/SDWebImage/releases/tag/2.0)
|
||||||
|
|
||||||
|
## [1.0.0 on Dec 31st, 2009](https://github.com/rs/SDWebImage/releases/tag/1.0.0)
|
||||||
|
|
||||||
|
## [1.0 on Dec 31st, 2009](https://github.com/rs/SDWebImage/releases/tag/1.0)
|
||||||
|
|
@ -21,31 +21,46 @@
|
||||||
53A2B50D155B155A00B12423 /* placeholder.png in Resources */ = {isa = PBXBuildFile; fileRef = 53A2B50B155B155A00B12423 /* placeholder.png */; };
|
53A2B50D155B155A00B12423 /* placeholder.png in Resources */ = {isa = PBXBuildFile; fileRef = 53A2B50B155B155A00B12423 /* placeholder.png */; };
|
||||||
53A2B50E155B155A00B12423 /* placeholder@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 53A2B50C155B155A00B12423 /* placeholder@2x.png */; };
|
53A2B50E155B155A00B12423 /* placeholder@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 53A2B50C155B155A00B12423 /* placeholder@2x.png */; };
|
||||||
53EEC18916484553007601E1 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 53EEC18816484553007601E1 /* Default-568h@2x.png */; };
|
53EEC18916484553007601E1 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 53EEC18816484553007601E1 /* Default-568h@2x.png */; };
|
||||||
53EEC1B2164845E9007601E1 /* libSDWebImage.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 53EEC1AD164845D9007601E1 /* libSDWebImage.a */; };
|
DA248D44195470FD00390AB0 /* MapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 537612E3155ABA3C005750A4 /* MapKit.framework */; };
|
||||||
|
DA248D79195484A500390AB0 /* libSDWebImage+WebP.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DA248D761954841D00390AB0 /* libSDWebImage+WebP.a */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXContainerItemProxy section */
|
/* Begin PBXContainerItemProxy section */
|
||||||
53EEC1AC164845D9007601E1 /* PBXContainerItemProxy */ = {
|
43A0FAAE1BDD16AC00B7582B /* PBXContainerItemProxy */ = {
|
||||||
isa = PBXContainerItemProxy;
|
isa = PBXContainerItemProxy;
|
||||||
containerPortal = 53EEC1A3164845D8007601E1 /* SDWebImage.xcodeproj */;
|
containerPortal = DA248D6C1954841D00390AB0 /* SDWebImage.xcodeproj */;
|
||||||
|
proxyType = 2;
|
||||||
|
remoteGlobalIDString = 4A2CADFF1AB4BB5300B6BC39;
|
||||||
|
remoteInfo = WebImage;
|
||||||
|
};
|
||||||
|
43AEAFA91D008FEE005B41A8 /* PBXContainerItemProxy */ = {
|
||||||
|
isa = PBXContainerItemProxy;
|
||||||
|
containerPortal = DA248D6C1954841D00390AB0 /* SDWebImage.xcodeproj */;
|
||||||
|
proxyType = 2;
|
||||||
|
remoteGlobalIDString = 00733A4C1BC487C000A5A117;
|
||||||
|
remoteInfo = "WebImage tvOS";
|
||||||
|
};
|
||||||
|
DA248D731954841D00390AB0 /* PBXContainerItemProxy */ = {
|
||||||
|
isa = PBXContainerItemProxy;
|
||||||
|
containerPortal = DA248D6C1954841D00390AB0 /* SDWebImage.xcodeproj */;
|
||||||
proxyType = 2;
|
proxyType = 2;
|
||||||
remoteGlobalIDString = 53761325155AD0D5005750A4;
|
remoteGlobalIDString = 53761325155AD0D5005750A4;
|
||||||
remoteInfo = SDWebImage;
|
remoteInfo = SDWebImage;
|
||||||
};
|
};
|
||||||
53EEC1AE164845D9007601E1 /* PBXContainerItemProxy */ = {
|
DA248D751954841D00390AB0 /* PBXContainerItemProxy */ = {
|
||||||
isa = PBXContainerItemProxy;
|
isa = PBXContainerItemProxy;
|
||||||
containerPortal = 53EEC1A3164845D8007601E1 /* SDWebImage.xcodeproj */;
|
containerPortal = DA248D6C1954841D00390AB0 /* SDWebImage.xcodeproj */;
|
||||||
|
proxyType = 2;
|
||||||
|
remoteGlobalIDString = 537D95C117ECC1FE0097C263;
|
||||||
|
remoteInfo = "SDWebImage+WebP";
|
||||||
|
};
|
||||||
|
DA248D771954841D00390AB0 /* PBXContainerItemProxy */ = {
|
||||||
|
isa = PBXContainerItemProxy;
|
||||||
|
containerPortal = DA248D6C1954841D00390AB0 /* SDWebImage.xcodeproj */;
|
||||||
proxyType = 2;
|
proxyType = 2;
|
||||||
remoteGlobalIDString = 531041E0157EAFA400BBABC3;
|
remoteGlobalIDString = 531041E0157EAFA400BBABC3;
|
||||||
remoteInfo = "SDWebImage+MKAnnotation";
|
remoteInfo = "SDWebImage+MKAnnotation";
|
||||||
};
|
};
|
||||||
53EEC1B0164845E3007601E1 /* PBXContainerItemProxy */ = {
|
|
||||||
isa = PBXContainerItemProxy;
|
|
||||||
containerPortal = 53EEC1A3164845D8007601E1 /* SDWebImage.xcodeproj */;
|
|
||||||
proxyType = 1;
|
|
||||||
remoteGlobalIDString = 53761307155AD0D5005750A4;
|
|
||||||
remoteInfo = SDWebImage;
|
|
||||||
};
|
|
||||||
/* End PBXContainerItemProxy section */
|
/* End PBXContainerItemProxy section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
|
|
@ -70,7 +85,7 @@
|
||||||
53A2B50B155B155A00B12423 /* placeholder.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = placeholder.png; sourceTree = "<group>"; };
|
53A2B50B155B155A00B12423 /* placeholder.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = placeholder.png; sourceTree = "<group>"; };
|
||||||
53A2B50C155B155A00B12423 /* placeholder@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "placeholder@2x.png"; sourceTree = "<group>"; };
|
53A2B50C155B155A00B12423 /* placeholder@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "placeholder@2x.png"; sourceTree = "<group>"; };
|
||||||
53EEC18816484553007601E1 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Default-568h@2x.png"; path = "../Default-568h@2x.png"; sourceTree = "<group>"; };
|
53EEC18816484553007601E1 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Default-568h@2x.png"; path = "../Default-568h@2x.png"; sourceTree = "<group>"; };
|
||||||
53EEC1A3164845D8007601E1 /* SDWebImage.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SDWebImage.xcodeproj; path = ../SDWebImage.xcodeproj; sourceTree = "<group>"; };
|
DA248D6C1954841D00390AB0 /* SDWebImage.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SDWebImage.xcodeproj; path = ../SDWebImage.xcodeproj; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
|
|
@ -78,7 +93,8 @@
|
||||||
isa = PBXFrameworksBuildPhase;
|
isa = PBXFrameworksBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
53EEC1B2164845E9007601E1 /* libSDWebImage.a in Frameworks */,
|
DA248D79195484A500390AB0 /* libSDWebImage+WebP.a in Frameworks */,
|
||||||
|
DA248D44195470FD00390AB0 /* MapKit.framework in Frameworks */,
|
||||||
531041C1157EAC8F00BBABC3 /* ImageIO.framework in Frameworks */,
|
531041C1157EAC8F00BBABC3 /* ImageIO.framework in Frameworks */,
|
||||||
5376129A155AB74D005750A4 /* UIKit.framework in Frameworks */,
|
5376129A155AB74D005750A4 /* UIKit.framework in Frameworks */,
|
||||||
5376129C155AB74D005750A4 /* Foundation.framework in Frameworks */,
|
5376129C155AB74D005750A4 /* Foundation.framework in Frameworks */,
|
||||||
|
|
@ -92,6 +108,7 @@
|
||||||
5376128A155AB74D005750A4 = {
|
5376128A155AB74D005750A4 = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
DA248D6C1954841D00390AB0 /* SDWebImage.xcodeproj */,
|
||||||
5376129F155AB74D005750A4 /* SDWebImage Demo */,
|
5376129F155AB74D005750A4 /* SDWebImage Demo */,
|
||||||
53761298155AB74D005750A4 /* Frameworks */,
|
53761298155AB74D005750A4 /* Frameworks */,
|
||||||
53761296155AB74D005750A4 /* Products */,
|
53761296155AB74D005750A4 /* Products */,
|
||||||
|
|
@ -109,7 +126,6 @@
|
||||||
53761298155AB74D005750A4 /* Frameworks */ = {
|
53761298155AB74D005750A4 /* Frameworks */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
53EEC1A3164845D8007601E1 /* SDWebImage.xcodeproj */,
|
|
||||||
537612E6155ABA44005750A4 /* ImageIO.framework */,
|
537612E6155ABA44005750A4 /* ImageIO.framework */,
|
||||||
537612E3155ABA3C005750A4 /* MapKit.framework */,
|
537612E3155ABA3C005750A4 /* MapKit.framework */,
|
||||||
53761299155AB74D005750A4 /* UIKit.framework */,
|
53761299155AB74D005750A4 /* UIKit.framework */,
|
||||||
|
|
@ -149,11 +165,14 @@
|
||||||
name = "Supporting Files";
|
name = "Supporting Files";
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
53EEC1A4164845D8007601E1 /* Products */ = {
|
DA248D6D1954841D00390AB0 /* Products */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
53EEC1AD164845D9007601E1 /* libSDWebImage.a */,
|
DA248D741954841D00390AB0 /* libSDWebImage.a */,
|
||||||
53EEC1AF164845D9007601E1 /* libSDWebImage+MKAnnotation.a */,
|
DA248D761954841D00390AB0 /* libSDWebImage+WebP.a */,
|
||||||
|
DA248D781954841D00390AB0 /* libSDWebImage+MKAnnotation.a */,
|
||||||
|
43A0FAAF1BDD16AC00B7582B /* WebImage.framework */,
|
||||||
|
43AEAFAA1D008FEE005B41A8 /* WebImage.framework */,
|
||||||
);
|
);
|
||||||
name = Products;
|
name = Products;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
|
@ -172,7 +191,6 @@
|
||||||
buildRules = (
|
buildRules = (
|
||||||
);
|
);
|
||||||
dependencies = (
|
dependencies = (
|
||||||
53EEC1B1164845E3007601E1 /* PBXTargetDependency */,
|
|
||||||
);
|
);
|
||||||
name = "SDWebImage Demo";
|
name = "SDWebImage Demo";
|
||||||
productName = "SDWebImage Demo";
|
productName = "SDWebImage Demo";
|
||||||
|
|
@ -185,7 +203,7 @@
|
||||||
5376128C155AB74D005750A4 /* Project object */ = {
|
5376128C155AB74D005750A4 /* Project object */ = {
|
||||||
isa = PBXProject;
|
isa = PBXProject;
|
||||||
attributes = {
|
attributes = {
|
||||||
LastUpgradeCheck = 0430;
|
LastUpgradeCheck = 0710;
|
||||||
ORGANIZATIONNAME = Dailymotion;
|
ORGANIZATIONNAME = Dailymotion;
|
||||||
};
|
};
|
||||||
buildConfigurationList = 5376128F155AB74D005750A4 /* Build configuration list for PBXProject "SDWebImage Demo" */;
|
buildConfigurationList = 5376128F155AB74D005750A4 /* Build configuration list for PBXProject "SDWebImage Demo" */;
|
||||||
|
|
@ -200,8 +218,8 @@
|
||||||
projectDirPath = "";
|
projectDirPath = "";
|
||||||
projectReferences = (
|
projectReferences = (
|
||||||
{
|
{
|
||||||
ProductGroup = 53EEC1A4164845D8007601E1 /* Products */;
|
ProductGroup = DA248D6D1954841D00390AB0 /* Products */;
|
||||||
ProjectRef = 53EEC1A3164845D8007601E1 /* SDWebImage.xcodeproj */;
|
ProjectRef = DA248D6C1954841D00390AB0 /* SDWebImage.xcodeproj */;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
projectRoot = "";
|
projectRoot = "";
|
||||||
|
|
@ -212,18 +230,39 @@
|
||||||
/* End PBXProject section */
|
/* End PBXProject section */
|
||||||
|
|
||||||
/* Begin PBXReferenceProxy section */
|
/* Begin PBXReferenceProxy section */
|
||||||
53EEC1AD164845D9007601E1 /* libSDWebImage.a */ = {
|
43A0FAAF1BDD16AC00B7582B /* WebImage.framework */ = {
|
||||||
|
isa = PBXReferenceProxy;
|
||||||
|
fileType = wrapper.framework;
|
||||||
|
path = WebImage.framework;
|
||||||
|
remoteRef = 43A0FAAE1BDD16AC00B7582B /* PBXContainerItemProxy */;
|
||||||
|
sourceTree = BUILT_PRODUCTS_DIR;
|
||||||
|
};
|
||||||
|
43AEAFAA1D008FEE005B41A8 /* WebImage.framework */ = {
|
||||||
|
isa = PBXReferenceProxy;
|
||||||
|
fileType = wrapper.framework;
|
||||||
|
path = WebImage.framework;
|
||||||
|
remoteRef = 43AEAFA91D008FEE005B41A8 /* PBXContainerItemProxy */;
|
||||||
|
sourceTree = BUILT_PRODUCTS_DIR;
|
||||||
|
};
|
||||||
|
DA248D741954841D00390AB0 /* libSDWebImage.a */ = {
|
||||||
isa = PBXReferenceProxy;
|
isa = PBXReferenceProxy;
|
||||||
fileType = archive.ar;
|
fileType = archive.ar;
|
||||||
path = libSDWebImage.a;
|
path = libSDWebImage.a;
|
||||||
remoteRef = 53EEC1AC164845D9007601E1 /* PBXContainerItemProxy */;
|
remoteRef = DA248D731954841D00390AB0 /* PBXContainerItemProxy */;
|
||||||
sourceTree = BUILT_PRODUCTS_DIR;
|
sourceTree = BUILT_PRODUCTS_DIR;
|
||||||
};
|
};
|
||||||
53EEC1AF164845D9007601E1 /* libSDWebImage+MKAnnotation.a */ = {
|
DA248D761954841D00390AB0 /* libSDWebImage+WebP.a */ = {
|
||||||
|
isa = PBXReferenceProxy;
|
||||||
|
fileType = archive.ar;
|
||||||
|
path = "libSDWebImage+WebP.a";
|
||||||
|
remoteRef = DA248D751954841D00390AB0 /* PBXContainerItemProxy */;
|
||||||
|
sourceTree = BUILT_PRODUCTS_DIR;
|
||||||
|
};
|
||||||
|
DA248D781954841D00390AB0 /* libSDWebImage+MKAnnotation.a */ = {
|
||||||
isa = PBXReferenceProxy;
|
isa = PBXReferenceProxy;
|
||||||
fileType = archive.ar;
|
fileType = archive.ar;
|
||||||
path = "libSDWebImage+MKAnnotation.a";
|
path = "libSDWebImage+MKAnnotation.a";
|
||||||
remoteRef = 53EEC1AE164845D9007601E1 /* PBXContainerItemProxy */;
|
remoteRef = DA248D771954841D00390AB0 /* PBXContainerItemProxy */;
|
||||||
sourceTree = BUILT_PRODUCTS_DIR;
|
sourceTree = BUILT_PRODUCTS_DIR;
|
||||||
};
|
};
|
||||||
/* End PBXReferenceProxy section */
|
/* End PBXReferenceProxy section */
|
||||||
|
|
@ -258,14 +297,6 @@
|
||||||
};
|
};
|
||||||
/* End PBXSourcesBuildPhase section */
|
/* End PBXSourcesBuildPhase section */
|
||||||
|
|
||||||
/* Begin PBXTargetDependency section */
|
|
||||||
53EEC1B1164845E3007601E1 /* PBXTargetDependency */ = {
|
|
||||||
isa = PBXTargetDependency;
|
|
||||||
name = SDWebImage;
|
|
||||||
targetProxy = 53EEC1B0164845E3007601E1 /* PBXContainerItemProxy */;
|
|
||||||
};
|
|
||||||
/* End PBXTargetDependency section */
|
|
||||||
|
|
||||||
/* Begin PBXVariantGroup section */
|
/* Begin PBXVariantGroup section */
|
||||||
537612B1155AB74D005750A4 /* MasterViewController.xib */ = {
|
537612B1155AB74D005750A4 /* MasterViewController.xib */ = {
|
||||||
isa = PBXVariantGroup;
|
isa = PBXVariantGroup;
|
||||||
|
|
@ -290,10 +321,10 @@
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||||
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
|
|
||||||
CLANG_ENABLE_OBJC_ARC = YES;
|
CLANG_ENABLE_OBJC_ARC = YES;
|
||||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||||
COPY_PHASE_STRIP = NO;
|
COPY_PHASE_STRIP = NO;
|
||||||
|
ENABLE_TESTABILITY = YES;
|
||||||
GCC_C_LANGUAGE_STANDARD = "compiler-default";
|
GCC_C_LANGUAGE_STANDARD = "compiler-default";
|
||||||
GCC_DYNAMIC_NO_PIC = NO;
|
GCC_DYNAMIC_NO_PIC = NO;
|
||||||
GCC_OPTIMIZATION_LEVEL = 0;
|
GCC_OPTIMIZATION_LEVEL = 0;
|
||||||
|
|
@ -306,7 +337,8 @@
|
||||||
GCC_WARN_ABOUT_RETURN_TYPE = YES;
|
GCC_WARN_ABOUT_RETURN_TYPE = YES;
|
||||||
GCC_WARN_UNINITIALIZED_AUTOS = YES;
|
GCC_WARN_UNINITIALIZED_AUTOS = YES;
|
||||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
|
||||||
|
ONLY_ACTIVE_ARCH = YES;
|
||||||
SDKROOT = iphoneos;
|
SDKROOT = iphoneos;
|
||||||
};
|
};
|
||||||
name = Debug;
|
name = Debug;
|
||||||
|
|
@ -315,7 +347,6 @@
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||||
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
|
|
||||||
CLANG_ENABLE_OBJC_ARC = YES;
|
CLANG_ENABLE_OBJC_ARC = YES;
|
||||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||||
COPY_PHASE_STRIP = YES;
|
COPY_PHASE_STRIP = YES;
|
||||||
|
|
@ -324,7 +355,7 @@
|
||||||
GCC_WARN_ABOUT_RETURN_TYPE = YES;
|
GCC_WARN_ABOUT_RETURN_TYPE = YES;
|
||||||
GCC_WARN_UNINITIALIZED_AUTOS = YES;
|
GCC_WARN_UNINITIALIZED_AUTOS = YES;
|
||||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
|
||||||
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
|
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
|
||||||
SDKROOT = iphoneos;
|
SDKROOT = iphoneos;
|
||||||
VALIDATE_PRODUCT = YES;
|
VALIDATE_PRODUCT = YES;
|
||||||
|
|
@ -348,6 +379,7 @@
|
||||||
INFOPLIST_FILE = "SDWebImage Demo/SDWebImage Demo-Info.plist";
|
INFOPLIST_FILE = "SDWebImage Demo/SDWebImage Demo-Info.plist";
|
||||||
OTHER_CFLAGS = "";
|
OTHER_CFLAGS = "";
|
||||||
OTHER_LDFLAGS = "-ObjC";
|
OTHER_LDFLAGS = "-ObjC";
|
||||||
|
PRODUCT_BUNDLE_IDENTIFIER = "com.dailymotion.${PRODUCT_NAME:rfc1034identifier}";
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
WRAPPER_EXTENSION = app;
|
WRAPPER_EXTENSION = app;
|
||||||
};
|
};
|
||||||
|
|
@ -369,6 +401,7 @@
|
||||||
);
|
);
|
||||||
INFOPLIST_FILE = "SDWebImage Demo/SDWebImage Demo-Info.plist";
|
INFOPLIST_FILE = "SDWebImage Demo/SDWebImage Demo-Info.plist";
|
||||||
OTHER_LDFLAGS = "-ObjC";
|
OTHER_LDFLAGS = "-ObjC";
|
||||||
|
PRODUCT_BUNDLE_IDENTIFIER = "com.dailymotion.${PRODUCT_NAME:rfc1034identifier}";
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
WRAPPER_EXTENSION = app;
|
WRAPPER_EXTENSION = app;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -31,24 +31,23 @@
|
||||||
|
|
||||||
- (void)configureView
|
- (void)configureView
|
||||||
{
|
{
|
||||||
if (self.imageURL)
|
if (self.imageURL) {
|
||||||
{
|
|
||||||
__block UIActivityIndicatorView *activityIndicator;
|
__block UIActivityIndicatorView *activityIndicator;
|
||||||
__weak UIImageView *weakImageView = self.imageView;
|
__weak UIImageView *weakImageView = self.imageView;
|
||||||
[self.imageView setImageWithURL:self.imageURL placeholderImage:nil options:SDWebImageProgressiveDownload progress:^(NSUInteger receivedSize, long long expectedSize)
|
[self.imageView sd_setImageWithURL:self.imageURL
|
||||||
{
|
placeholderImage:nil
|
||||||
if (!activityIndicator)
|
options:SDWebImageProgressiveDownload
|
||||||
{
|
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
|
||||||
[weakImageView addSubview:activityIndicator = [UIActivityIndicatorView.alloc initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]];
|
if (!activityIndicator) {
|
||||||
activityIndicator.center = weakImageView.center;
|
[weakImageView addSubview:activityIndicator = [UIActivityIndicatorView.alloc initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]];
|
||||||
[activityIndicator startAnimating];
|
activityIndicator.center = weakImageView.center;
|
||||||
}
|
[activityIndicator startAnimating];
|
||||||
}
|
}
|
||||||
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType)
|
}
|
||||||
{
|
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||||
[activityIndicator removeFromSuperview];
|
[activityIndicator removeFromSuperview];
|
||||||
activityIndicator = nil;
|
activityIndicator = nil;
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,310 +29,23 @@
|
||||||
style:UIBarButtonItemStylePlain
|
style:UIBarButtonItemStylePlain
|
||||||
target:self
|
target:self
|
||||||
action:@selector(flushCache)];
|
action:@selector(flushCache)];
|
||||||
_objects = [NSArray arrayWithObjects:
|
|
||||||
|
// HTTP NTLM auth example
|
||||||
|
// Add your NTLM image url to the array below and replace the credentials
|
||||||
|
[SDWebImageManager sharedManager].imageDownloader.username = @"httpwatch";
|
||||||
|
[SDWebImageManager sharedManager].imageDownloader.password = @"httpwatch01";
|
||||||
|
|
||||||
|
_objects = [NSMutableArray arrayWithObjects:
|
||||||
|
@"http://www.httpwatch.com/httpgallery/authentication/authenticatedimage/default.aspx?0.35786508303135633", // requires HTTP auth, used to demo the NTLM auth
|
||||||
@"http://assets.sbnation.com/assets/2512203/dogflops.gif",
|
@"http://assets.sbnation.com/assets/2512203/dogflops.gif",
|
||||||
@"http://www.ioncannon.net/wp-content/uploads/2011/06/test2.webp",
|
@"http://www.ioncannon.net/wp-content/uploads/2011/06/test2.webp",
|
||||||
@"http://www.ioncannon.net/wp-content/uploads/2011/06/test9.webp",
|
@"http://www.ioncannon.net/wp-content/uploads/2011/06/test9.webp",
|
||||||
@"http://static2.dmcdn.net/static/video/656/177/44771656:jpeg_preview_small.jpg?20120509154705",
|
|
||||||
@"http://static2.dmcdn.net/static/video/629/228/44822926:jpeg_preview_small.jpg?20120509181018",
|
|
||||||
@"http://static2.dmcdn.net/static/video/116/367/44763611:jpeg_preview_small.jpg?20120509101749",
|
|
||||||
@"http://static2.dmcdn.net/static/video/340/086/44680043:jpeg_preview_small.jpg?20120509180118",
|
|
||||||
@"http://static2.dmcdn.net/static/video/666/645/43546666:jpeg_preview_small.jpg?20120412153140",
|
|
||||||
@"http://static2.dmcdn.net/static/video/771/577/44775177:jpeg_preview_small.jpg?20120509183230",
|
|
||||||
@"http://static2.dmcdn.net/static/video/810/508/44805018:jpeg_preview_small.jpg?20120508125339",
|
|
||||||
@"http://static2.dmcdn.net/static/video/152/008/44800251:jpeg_preview_small.jpg?20120508103336",
|
|
||||||
@"http://static2.dmcdn.net/static/video/694/741/35147496:jpeg_preview_small.jpg?20120508111445",
|
|
||||||
@"http://static2.dmcdn.net/static/video/988/667/44766889:jpeg_preview_small.jpg?20120508130425",
|
|
||||||
@"http://static2.dmcdn.net/static/video/282/467/44764282:jpeg_preview_small.jpg?20120507130637",
|
|
||||||
@"http://static2.dmcdn.net/static/video/754/657/44756457:jpeg_preview_small.jpg?20120507093012",
|
|
||||||
@"http://static2.dmcdn.net/static/video/831/107/44701138:jpeg_preview_small.jpg?20120506133917",
|
|
||||||
@"http://static2.dmcdn.net/static/video/411/057/44750114:jpeg_preview_small.jpg?20120507014914",
|
|
||||||
@"http://static2.dmcdn.net/static/video/894/547/44745498:jpeg_preview_small.jpg?20120509183004",
|
|
||||||
@"http://static2.dmcdn.net/static/video/082/947/44749280:jpeg_preview_small.jpg?20120507015022",
|
|
||||||
@"http://static2.dmcdn.net/static/video/833/347/44743338:jpeg_preview_small.jpg?20120509183004",
|
|
||||||
@"http://static2.dmcdn.net/static/video/683/666/44666386:jpeg_preview_small.jpg?20120505111208",
|
|
||||||
@"http://static2.dmcdn.net/static/video/595/946/44649595:jpeg_preview_small.jpg?20120507194104",
|
|
||||||
@"http://static2.dmcdn.net/static/video/984/935/44539489:jpeg_preview_small.jpg?20120501184650",
|
|
||||||
@"http://static2.dmcdn.net/static/video/440/416/44614044:jpeg_preview_small.jpg?20120505174152",
|
|
||||||
@"http://static2.dmcdn.net/static/video/561/977/20779165:jpeg_preview_small.jpg?20120423161805",
|
|
||||||
@"http://static2.dmcdn.net/static/video/104/546/44645401:jpeg_preview_small.jpg?20120507185246",
|
|
||||||
@"http://static2.dmcdn.net/static/video/671/636/44636176:jpeg_preview_small.jpg?20120504021339",
|
|
||||||
@"http://static2.dmcdn.net/static/video/142/746/44647241:jpeg_preview_small.jpg?20120504104451",
|
|
||||||
@"http://static2.dmcdn.net/static/video/776/860/44068677:jpeg_preview_small.jpg?20120507185251",
|
|
||||||
@"http://static2.dmcdn.net/static/video/026/626/44626620:jpeg_preview_small.jpg?20120503203036",
|
|
||||||
@"http://static2.dmcdn.net/static/video/364/663/39366463:jpeg_preview_small.jpg?20120509163505",
|
|
||||||
@"http://static2.dmcdn.net/static/video/392/895/44598293:jpeg_preview_small.jpg?20120503165252",
|
|
||||||
@"http://static2.dmcdn.net/static/video/620/865/44568026:jpeg_preview_small.jpg?20120507185121",
|
|
||||||
@"http://static2.dmcdn.net/static/video/031/395/44593130:jpeg_preview_small.jpg?20120507185139",
|
|
||||||
@"http://static2.dmcdn.net/static/video/676/495/44594676:jpeg_preview_small.jpg?20120503121341",
|
|
||||||
@"http://static2.dmcdn.net/static/video/025/195/44591520:jpeg_preview_small.jpg?20120503132132",
|
|
||||||
@"http://static2.dmcdn.net/static/video/993/665/44566399:jpeg_preview_small.jpg?20120503182623",
|
|
||||||
@"http://static2.dmcdn.net/static/video/137/635/44536731:jpeg_preview_small.jpg?20120501165940",
|
|
||||||
@"http://static2.dmcdn.net/static/video/611/794/44497116:jpeg_preview_small.jpg?20120507184954",
|
|
||||||
@"http://static2.dmcdn.net/static/video/732/790/44097237:jpeg_preview_small.jpg?20120430162348",
|
|
||||||
@"http://static2.dmcdn.net/static/video/064/991/44199460:jpeg_preview_small.jpg?20120430101250",
|
|
||||||
@"http://static2.dmcdn.net/static/video/404/094/44490404:jpeg_preview_small.jpg?20120507184948",
|
|
||||||
@"http://static2.dmcdn.net/static/video/413/120/44021314:jpeg_preview_small.jpg?20120507180850",
|
|
||||||
@"http://static2.dmcdn.net/static/video/200/584/44485002:jpeg_preview_small.jpg?20120507184941",
|
|
||||||
@"http://static2.dmcdn.net/static/video/551/318/42813155:jpeg_preview_small.jpg?20120412153202",
|
|
||||||
@"http://static2.dmcdn.net/static/video/524/750/44057425:jpeg_preview_small.jpg?20120501220912",
|
|
||||||
@"http://static2.dmcdn.net/static/video/124/843/44348421:jpeg_preview_small.jpg?20120507184551",
|
|
||||||
@"http://static2.dmcdn.net/static/video/496/394/42493694:jpeg_preview_small.jpg?20120430105337",
|
|
||||||
@"http://static2.dmcdn.net/static/video/548/883/44388845:jpeg_preview_small.jpg?20120428212713",
|
|
||||||
@"http://static2.dmcdn.net/static/video/282/533/44335282:jpeg_preview_small.jpg?20120427102844",
|
|
||||||
@"http://static2.dmcdn.net/static/video/257/132/44231752:jpeg_preview_small.jpg?20120428212609",
|
|
||||||
@"http://static2.dmcdn.net/static/video/480/193/44391084:jpeg_preview_small.jpg?20120501143214",
|
|
||||||
@"http://static2.dmcdn.net/static/video/903/432/44234309:jpeg_preview_small.jpg?20120427200002",
|
|
||||||
@"http://static2.dmcdn.net/static/video/646/573/44375646:jpeg_preview_small.jpg?20120507184652",
|
|
||||||
@"http://static2.dmcdn.net/static/video/709/573/44375907:jpeg_preview_small.jpg?20120507184652",
|
|
||||||
@"http://static2.dmcdn.net/static/video/885/633/44336588:jpeg_preview_small.jpg?20120507184540",
|
|
||||||
@"http://static2.dmcdn.net/static/video/732/523/44325237:jpeg_preview_small.jpg?20120426110308",
|
|
||||||
@"http://static2.dmcdn.net/static/video/935/132/44231539:jpeg_preview_small.jpg?20120426115744",
|
|
||||||
@"http://static2.dmcdn.net/static/video/941/129/43921149:jpeg_preview_small.jpg?20120426094640",
|
|
||||||
@"http://static2.dmcdn.net/static/video/775/942/44249577:jpeg_preview_small.jpg?20120425011228",
|
|
||||||
@"http://static2.dmcdn.net/static/video/868/332/44233868:jpeg_preview_small.jpg?20120429152901",
|
|
||||||
@"http://static2.dmcdn.net/static/video/959/732/44237959:jpeg_preview_small.jpg?20120425133534",
|
|
||||||
@"http://static2.dmcdn.net/static/video/383/402/44204383:jpeg_preview_small.jpg?20120424185842",
|
|
||||||
@"http://static2.dmcdn.net/static/video/971/932/44239179:jpeg_preview_small.jpg?20120424154419",
|
|
||||||
@"http://static2.dmcdn.net/static/video/096/991/44199690:jpeg_preview_small.jpg?20120423162001",
|
|
||||||
@"http://static2.dmcdn.net/static/video/661/450/44054166:jpeg_preview_small.jpg?20120507180921",
|
|
||||||
@"http://static2.dmcdn.net/static/video/419/322/44223914:jpeg_preview_small.jpg?20120424112858",
|
|
||||||
@"http://static2.dmcdn.net/static/video/673/391/44193376:jpeg_preview_small.jpg?20120507181450",
|
|
||||||
@"http://static2.dmcdn.net/static/video/907/781/44187709:jpeg_preview_small.jpg?20120423103507",
|
|
||||||
@"http://static2.dmcdn.net/static/video/446/571/44175644:jpeg_preview_small.jpg?20120423033122",
|
|
||||||
@"http://static2.dmcdn.net/static/video/146/671/44176641:jpeg_preview_small.jpg?20120428235503",
|
|
||||||
@"http://static2.dmcdn.net/static/video/463/571/44175364:jpeg_preview_small.jpg?20120428235503",
|
|
||||||
@"http://static2.dmcdn.net/static/video/442/471/44174244:jpeg_preview_small.jpg?20120428235502",
|
|
||||||
@"http://static2.dmcdn.net/static/video/523/471/44174325:jpeg_preview_small.jpg?20120422205107",
|
|
||||||
@"http://static2.dmcdn.net/static/video/977/159/43951779:jpeg_preview_small.jpg?20120420182100",
|
|
||||||
@"http://static2.dmcdn.net/static/video/875/880/40088578:jpeg_preview_small.jpg?20120501131026",
|
|
||||||
@"http://static2.dmcdn.net/static/video/434/992/38299434:jpeg_preview_small.jpg?20120503193356",
|
|
||||||
@"http://static2.dmcdn.net/static/video/448/798/42897844:jpeg_preview_small.jpg?20120418155203",
|
|
||||||
@"http://static2.dmcdn.net/static/video/374/690/44096473:jpeg_preview_small.jpg?20120507181124",
|
|
||||||
@"http://static2.dmcdn.net/static/video/284/313/43313482:jpeg_preview_small.jpg?20120420184511",
|
|
||||||
@"http://static2.dmcdn.net/static/video/682/060/44060286:jpeg_preview_small.jpg?20120421122436",
|
|
||||||
@"http://static2.dmcdn.net/static/video/701/750/44057107:jpeg_preview_small.jpg?20120420112918",
|
|
||||||
@"http://static2.dmcdn.net/static/video/790/850/44058097:jpeg_preview_small.jpg?20120424114522",
|
|
||||||
@"http://static2.dmcdn.net/static/video/153/617/43716351:jpeg_preview_small.jpg?20120419190650",
|
|
||||||
@"http://static2.dmcdn.net/static/video/394/633/37336493:jpeg_preview_small.jpg?20111109151109",
|
|
||||||
@"http://static2.dmcdn.net/static/video/893/330/44033398:jpeg_preview_small.jpg?20120419123322",
|
|
||||||
@"http://static2.dmcdn.net/static/video/395/046/42640593:jpeg_preview_small.jpg?20120418103546",
|
|
||||||
@"http://static2.dmcdn.net/static/video/913/040/44040319:jpeg_preview_small.jpg?20120419164908",
|
|
||||||
@"http://static2.dmcdn.net/static/video/090/020/44020090:jpeg_preview_small.jpg?20120418185934",
|
|
||||||
@"http://static2.dmcdn.net/static/video/349/299/43992943:jpeg_preview_small.jpg?20120418112749",
|
|
||||||
@"http://static2.dmcdn.net/static/video/530/189/43981035:jpeg_preview_small.jpg?20120419013834",
|
|
||||||
@"http://static2.dmcdn.net/static/video/763/469/43964367:jpeg_preview_small.jpg?20120425111931",
|
|
||||||
@"http://static2.dmcdn.net/static/video/961/455/43554169:jpeg_preview_small.jpg?20120418110127",
|
|
||||||
@"http://static2.dmcdn.net/static/video/666/889/43988666:jpeg_preview_small.jpg?20120507180735",
|
|
||||||
@"http://static2.dmcdn.net/static/video/160/459/43954061:jpeg_preview_small.jpg?20120501202847",
|
|
||||||
@"http://static2.dmcdn.net/static/video/352/069/43960253:jpeg_preview_small.jpg?20120503175747",
|
|
||||||
@"http://static2.dmcdn.net/static/video/096/502/43205690:jpeg_preview_small.jpg?20120417142655",
|
|
||||||
@"http://static2.dmcdn.net/static/video/257/119/43911752:jpeg_preview_small.jpg?20120416101238",
|
|
||||||
@"http://static2.dmcdn.net/static/video/874/098/43890478:jpeg_preview_small.jpg?20120415193608",
|
|
||||||
@"http://static2.dmcdn.net/static/video/406/148/43841604:jpeg_preview_small.jpg?20120416123145",
|
|
||||||
@"http://static2.dmcdn.net/static/video/463/885/43588364:jpeg_preview_small.jpg?20120409130206",
|
|
||||||
@"http://static2.dmcdn.net/static/video/176/845/38548671:jpeg_preview_small.jpg?20120414200742",
|
|
||||||
@"http://static2.dmcdn.net/static/video/447/848/51848744:jpeg_preview_small.jpg?20121105223446",
|
|
||||||
@"http://static2.dmcdn.net/static/video/337/848/51848733:jpeg_preview_small.jpg?20121105223433",
|
|
||||||
@"http://static2.dmcdn.net/static/video/707/848/51848707:jpeg_preview_small.jpg?20121105223428",
|
|
||||||
@"http://static2.dmcdn.net/static/video/102/848/51848201:jpeg_preview_small.jpg?20121105223411",
|
|
||||||
@"http://static2.dmcdn.net/static/video/817/848/51848718:jpeg_preview_small.jpg?20121105223402",
|
|
||||||
@"http://static2.dmcdn.net/static/video/007/848/51848700:jpeg_preview_small.jpg?20121105223345",
|
|
||||||
@"http://static2.dmcdn.net/static/video/696/848/51848696:jpeg_preview_small.jpg?20121105223355",
|
|
||||||
@"http://static2.dmcdn.net/static/video/296/848/51848692:jpeg_preview_small.jpg?20121105223337",
|
|
||||||
@"http://static2.dmcdn.net/static/video/080/848/51848080:jpeg_preview_small.jpg?20121105223653",
|
|
||||||
@"http://static2.dmcdn.net/static/video/386/848/51848683:jpeg_preview_small.jpg?20121105223343",
|
|
||||||
@"http://static2.dmcdn.net/static/video/876/848/51848678:jpeg_preview_small.jpg?20121105223301",
|
|
||||||
@"http://static2.dmcdn.net/static/video/866/848/51848668:jpeg_preview_small.jpg?20121105223244",
|
|
||||||
@"http://static2.dmcdn.net/static/video/572/548/51845275:jpeg_preview_small.jpg?20121105223229",
|
|
||||||
@"http://static2.dmcdn.net/static/video/972/548/51845279:jpeg_preview_small.jpg?20121105223227",
|
|
||||||
@"http://static2.dmcdn.net/static/video/112/548/51845211:jpeg_preview_small.jpg?20121105223226",
|
|
||||||
@"http://static2.dmcdn.net/static/video/549/448/51844945:jpeg_preview_small.jpg?20121105223223",
|
|
||||||
@"http://static2.dmcdn.net/static/video/166/848/51848661:jpeg_preview_small.jpg?20121105223228",
|
|
||||||
@"http://static2.dmcdn.net/static/video/856/848/51848658:jpeg_preview_small.jpg?20121105223223",
|
|
||||||
@"http://static2.dmcdn.net/static/video/746/848/51848647:jpeg_preview_small.jpg?20121105223204",
|
|
||||||
@"http://static2.dmcdn.net/static/video/446/848/51848644:jpeg_preview_small.jpg?20121105223204",
|
|
||||||
@"http://static2.dmcdn.net/static/video/726/848/51848627:jpeg_preview_small.jpg?20121105223221",
|
|
||||||
@"http://static2.dmcdn.net/static/video/436/848/51848634:jpeg_preview_small.jpg?20121105223445",
|
|
||||||
@"http://static2.dmcdn.net/static/video/836/848/51848638:jpeg_preview_small.jpg?20121105223144",
|
|
||||||
@"http://static2.dmcdn.net/static/video/036/848/51848630:jpeg_preview_small.jpg?20121105223125",
|
|
||||||
@"http://static2.dmcdn.net/static/video/026/848/51848620:jpeg_preview_small.jpg?20121105223102",
|
|
||||||
@"http://static2.dmcdn.net/static/video/895/848/51848598:jpeg_preview_small.jpg?20121105223112",
|
|
||||||
@"http://static2.dmcdn.net/static/video/116/848/51848611:jpeg_preview_small.jpg?20121105223052",
|
|
||||||
@"http://static2.dmcdn.net/static/video/006/848/51848600:jpeg_preview_small.jpg?20121105223043",
|
|
||||||
@"http://static2.dmcdn.net/static/video/432/548/51845234:jpeg_preview_small.jpg?20121105223022",
|
|
||||||
@"http://static2.dmcdn.net/static/video/785/848/51848587:jpeg_preview_small.jpg?20121105223031",
|
|
||||||
@"http://static2.dmcdn.net/static/video/975/848/51848579:jpeg_preview_small.jpg?20121105223012",
|
|
||||||
@"http://static2.dmcdn.net/static/video/965/848/51848569:jpeg_preview_small.jpg?20121105222952",
|
|
||||||
@"http://static2.dmcdn.net/static/video/365/848/51848563:jpeg_preview_small.jpg?20121105222943",
|
|
||||||
@"http://static2.dmcdn.net/static/video/755/848/51848557:jpeg_preview_small.jpg?20121105222943",
|
|
||||||
@"http://static2.dmcdn.net/static/video/722/248/51842227:jpeg_preview_small.jpg?20121105222908",
|
|
||||||
@"http://static2.dmcdn.net/static/video/155/848/51848551:jpeg_preview_small.jpg?20121105222913",
|
|
||||||
@"http://static2.dmcdn.net/static/video/345/848/51848543:jpeg_preview_small.jpg?20121105222907",
|
|
||||||
@"http://static2.dmcdn.net/static/video/535/848/51848535:jpeg_preview_small.jpg?20121105222848",
|
|
||||||
@"http://static2.dmcdn.net/static/video/035/848/51848530:jpeg_preview_small.jpg?20121105222837",
|
|
||||||
@"http://static2.dmcdn.net/static/video/525/848/51848525:jpeg_preview_small.jpg?20121105222826",
|
|
||||||
@"http://static2.dmcdn.net/static/video/233/848/51848332:jpeg_preview_small.jpg?20121105223414",
|
|
||||||
@"http://static2.dmcdn.net/static/video/125/848/51848521:jpeg_preview_small.jpg?20121105222809",
|
|
||||||
@"http://static2.dmcdn.net/static/video/005/848/51848500:jpeg_preview_small.jpg?20121105222802",
|
|
||||||
@"http://static2.dmcdn.net/static/video/015/848/51848510:jpeg_preview_small.jpg?20121105222755",
|
|
||||||
@"http://static2.dmcdn.net/static/video/121/548/51845121:jpeg_preview_small.jpg?20121105222850",
|
|
||||||
@"http://static2.dmcdn.net/static/video/205/848/51848502:jpeg_preview_small.jpg?20121105222737",
|
|
||||||
@"http://static2.dmcdn.net/static/video/697/448/51844796:jpeg_preview_small.jpg?20121105222818",
|
|
||||||
@"http://static2.dmcdn.net/static/video/494/848/51848494:jpeg_preview_small.jpg?20121105222724",
|
|
||||||
@"http://static2.dmcdn.net/static/video/806/448/51844608:jpeg_preview_small.jpg?20121105222811",
|
|
||||||
@"http://static2.dmcdn.net/static/video/729/348/51843927:jpeg_preview_small.jpg?20121105222805",
|
|
||||||
@"http://static2.dmcdn.net/static/video/865/148/51841568:jpeg_preview_small.jpg?20121105222803",
|
|
||||||
@"http://static2.dmcdn.net/static/video/481/548/51845184:jpeg_preview_small.jpg?20121105222700",
|
|
||||||
@"http://static2.dmcdn.net/static/video/190/548/51845091:jpeg_preview_small.jpg?20121105222656",
|
|
||||||
@"http://static2.dmcdn.net/static/video/128/448/51844821:jpeg_preview_small.jpg?20121105222656",
|
|
||||||
@"http://static2.dmcdn.net/static/video/784/848/51848487:jpeg_preview_small.jpg?20121105222704",
|
|
||||||
@"http://static2.dmcdn.net/static/video/182/448/51844281:jpeg_preview_small.jpg?20121105222652",
|
|
||||||
@"http://static2.dmcdn.net/static/video/801/848/51848108:jpeg_preview_small.jpg?20121105222907",
|
|
||||||
@"http://static2.dmcdn.net/static/video/974/848/51848479:jpeg_preview_small.jpg?20121105222657",
|
|
||||||
@"http://static2.dmcdn.net/static/video/274/848/51848472:jpeg_preview_small.jpg?20121105222644",
|
|
||||||
@"http://static2.dmcdn.net/static/video/954/848/51848459:jpeg_preview_small.jpg?20121105222637",
|
|
||||||
@"http://static2.dmcdn.net/static/video/554/848/51848455:jpeg_preview_small.jpg?20121105222615",
|
|
||||||
@"http://static2.dmcdn.net/static/video/944/848/51848449:jpeg_preview_small.jpg?20121105222558",
|
|
||||||
@"http://static2.dmcdn.net/static/video/144/848/51848441:jpeg_preview_small.jpg?20121105222556",
|
|
||||||
@"http://static2.dmcdn.net/static/video/134/848/51848431:jpeg_preview_small.jpg?20121105222539",
|
|
||||||
@"http://static2.dmcdn.net/static/video/624/848/51848426:jpeg_preview_small.jpg?20121105222523",
|
|
||||||
@"http://static2.dmcdn.net/static/video/281/448/51844182:jpeg_preview_small.jpg?20121105222502",
|
|
||||||
@"http://static2.dmcdn.net/static/video/414/848/51848414:jpeg_preview_small.jpg?20121105222516",
|
|
||||||
@"http://static2.dmcdn.net/static/video/171/848/51848171:jpeg_preview_small.jpg?20121105223449",
|
|
||||||
@"http://static2.dmcdn.net/static/video/904/848/51848409:jpeg_preview_small.jpg?20121105222514",
|
|
||||||
@"http://static2.dmcdn.net/static/video/004/848/51848400:jpeg_preview_small.jpg?20121105222443",
|
|
||||||
@"http://static2.dmcdn.net/static/video/693/848/51848396:jpeg_preview_small.jpg?20121105222439",
|
|
||||||
@"http://static2.dmcdn.net/static/video/401/848/51848104:jpeg_preview_small.jpg?20121105222832",
|
|
||||||
@"http://static2.dmcdn.net/static/video/957/648/51846759:jpeg_preview_small.jpg?20121105223109",
|
|
||||||
@"http://static2.dmcdn.net/static/video/603/848/51848306:jpeg_preview_small.jpg?20121105222324",
|
|
||||||
@"http://static2.dmcdn.net/static/video/990/848/51848099:jpeg_preview_small.jpg?20121105222807",
|
|
||||||
@"http://static2.dmcdn.net/static/video/929/448/51844929:jpeg_preview_small.jpg?20121105222216",
|
|
||||||
@"http://static2.dmcdn.net/static/video/320/548/51845023:jpeg_preview_small.jpg?20121105222214",
|
|
||||||
@"http://static2.dmcdn.net/static/video/387/448/51844783:jpeg_preview_small.jpg?20121105222212",
|
|
||||||
@"http://static2.dmcdn.net/static/video/833/248/51842338:jpeg_preview_small.jpg?20121105222209",
|
|
||||||
@"http://static2.dmcdn.net/static/video/993/348/51843399:jpeg_preview_small.jpg?20121105222012",
|
|
||||||
@"http://static2.dmcdn.net/static/video/660/848/51848066:jpeg_preview_small.jpg?20121105222754",
|
|
||||||
@"http://static2.dmcdn.net/static/video/471/848/51848174:jpeg_preview_small.jpg?20121105223419",
|
|
||||||
@"http://static2.dmcdn.net/static/video/255/748/51847552:jpeg_preview_small.jpg?20121105222420",
|
|
||||||
@"http://static2.dmcdn.net/static/video/257/448/51844752:jpeg_preview_small.jpg?20121105221728",
|
|
||||||
@"http://static2.dmcdn.net/static/video/090/848/51848090:jpeg_preview_small.jpg?20121105223020",
|
|
||||||
@"http://static2.dmcdn.net/static/video/807/448/51844708:jpeg_preview_small.jpg?20121105221654",
|
|
||||||
@"http://static2.dmcdn.net/static/video/196/448/51844691:jpeg_preview_small.jpg?20121105222110",
|
|
||||||
@"http://static2.dmcdn.net/static/video/406/448/51844604:jpeg_preview_small.jpg?20121105221647",
|
|
||||||
@"http://static2.dmcdn.net/static/video/865/348/51843568:jpeg_preview_small.jpg?20121105221644",
|
|
||||||
@"http://static2.dmcdn.net/static/video/932/448/51844239:jpeg_preview_small.jpg?20121105221309",
|
|
||||||
@"http://static2.dmcdn.net/static/video/967/438/51834769:jpeg_preview_small.jpg?20121105221020",
|
|
||||||
@"http://static2.dmcdn.net/static/video/362/348/51843263:jpeg_preview_small.jpg?20121105220855",
|
|
||||||
@"http://static2.dmcdn.net/static/video/777/448/51844777:jpeg_preview_small.jpg?20121105220715",
|
|
||||||
@"http://static2.dmcdn.net/static/video/567/348/51843765:jpeg_preview_small.jpg?20121105220708",
|
|
||||||
@"http://static2.dmcdn.net/static/video/905/248/51842509:jpeg_preview_small.jpg?20121105220640",
|
|
||||||
@"http://static2.dmcdn.net/static/video/857/748/51847758:jpeg_preview_small.jpg?20121105221003",
|
|
||||||
@"http://static2.dmcdn.net/static/video/578/348/51843875:jpeg_preview_small.jpg?20121105220350",
|
|
||||||
@"http://static2.dmcdn.net/static/video/214/448/51844412:jpeg_preview_small.jpg?20121105220415",
|
|
||||||
@"http://static2.dmcdn.net/static/video/264/748/51847462:jpeg_preview_small.jpg?20121105220635",
|
|
||||||
@"http://static2.dmcdn.net/static/video/817/748/51847718:jpeg_preview_small.jpg?20121105220233",
|
|
||||||
@"http://static2.dmcdn.net/static/video/784/848/51848487:jpeg_preview_small.jpg?20121105222704",
|
|
||||||
@"http://static2.dmcdn.net/static/video/182/448/51844281:jpeg_preview_small.jpg?20121105222652",
|
|
||||||
@"http://static2.dmcdn.net/static/video/801/848/51848108:jpeg_preview_small.jpg?20121105222907",
|
|
||||||
@"http://static2.dmcdn.net/static/video/974/848/51848479:jpeg_preview_small.jpg?20121105222657",
|
|
||||||
@"http://static2.dmcdn.net/static/video/274/848/51848472:jpeg_preview_small.jpg?20121105222644",
|
|
||||||
@"http://static2.dmcdn.net/static/video/954/848/51848459:jpeg_preview_small.jpg?20121105222637",
|
|
||||||
@"http://static2.dmcdn.net/static/video/554/848/51848455:jpeg_preview_small.jpg?20121105222615",
|
|
||||||
@"http://static2.dmcdn.net/static/video/944/848/51848449:jpeg_preview_small.jpg?20121105222558",
|
|
||||||
@"http://static2.dmcdn.net/static/video/144/848/51848441:jpeg_preview_small.jpg?20121105222556",
|
|
||||||
@"http://static2.dmcdn.net/static/video/134/848/51848431:jpeg_preview_small.jpg?20121105222539",
|
|
||||||
@"http://static2.dmcdn.net/static/video/624/848/51848426:jpeg_preview_small.jpg?20121105222523",
|
|
||||||
@"http://static2.dmcdn.net/static/video/281/448/51844182:jpeg_preview_small.jpg?20121105222502",
|
|
||||||
@"http://static2.dmcdn.net/static/video/414/848/51848414:jpeg_preview_small.jpg?20121105222516",
|
|
||||||
@"http://static2.dmcdn.net/static/video/171/848/51848171:jpeg_preview_small.jpg?20121105223449",
|
|
||||||
@"http://static2.dmcdn.net/static/video/904/848/51848409:jpeg_preview_small.jpg?20121105222514",
|
|
||||||
@"http://static2.dmcdn.net/static/video/004/848/51848400:jpeg_preview_small.jpg?20121105222443",
|
|
||||||
@"http://static2.dmcdn.net/static/video/693/848/51848396:jpeg_preview_small.jpg?20121105222439",
|
|
||||||
@"http://static2.dmcdn.net/static/video/401/848/51848104:jpeg_preview_small.jpg?20121105222832",
|
|
||||||
@"http://static2.dmcdn.net/static/video/957/648/51846759:jpeg_preview_small.jpg?20121105223109",
|
|
||||||
@"http://static2.dmcdn.net/static/video/603/848/51848306:jpeg_preview_small.jpg?20121105222324",
|
|
||||||
@"http://static2.dmcdn.net/static/video/990/848/51848099:jpeg_preview_small.jpg?20121105222807",
|
|
||||||
@"http://static2.dmcdn.net/static/video/929/448/51844929:jpeg_preview_small.jpg?20121105222216",
|
|
||||||
@"http://static2.dmcdn.net/static/video/320/548/51845023:jpeg_preview_small.jpg?20121105222214",
|
|
||||||
@"http://static2.dmcdn.net/static/video/387/448/51844783:jpeg_preview_small.jpg?20121105222212",
|
|
||||||
@"http://static2.dmcdn.net/static/video/833/248/51842338:jpeg_preview_small.jpg?20121105222209",
|
|
||||||
@"http://static2.dmcdn.net/static/video/993/348/51843399:jpeg_preview_small.jpg?20121105222012",
|
|
||||||
@"http://static2.dmcdn.net/static/video/660/848/51848066:jpeg_preview_small.jpg?20121105222754",
|
|
||||||
@"http://static2.dmcdn.net/static/video/471/848/51848174:jpeg_preview_small.jpg?20121105223419",
|
|
||||||
@"http://static2.dmcdn.net/static/video/255/748/51847552:jpeg_preview_small.jpg?20121105222420",
|
|
||||||
@"http://static2.dmcdn.net/static/video/257/448/51844752:jpeg_preview_small.jpg?20121105221728",
|
|
||||||
@"http://static2.dmcdn.net/static/video/090/848/51848090:jpeg_preview_small.jpg?20121105224514",
|
|
||||||
@"http://static2.dmcdn.net/static/video/807/448/51844708:jpeg_preview_small.jpg?20121105221654",
|
|
||||||
@"http://static2.dmcdn.net/static/video/196/448/51844691:jpeg_preview_small.jpg?20121105222110",
|
|
||||||
@"http://static2.dmcdn.net/static/video/406/448/51844604:jpeg_preview_small.jpg?20121105221647",
|
|
||||||
@"http://static2.dmcdn.net/static/video/865/348/51843568:jpeg_preview_small.jpg?20121105221644",
|
|
||||||
@"http://static2.dmcdn.net/static/video/932/448/51844239:jpeg_preview_small.jpg?20121105221309",
|
|
||||||
@"http://static2.dmcdn.net/static/video/967/438/51834769:jpeg_preview_small.jpg?20121105221020",
|
|
||||||
@"http://static2.dmcdn.net/static/video/362/348/51843263:jpeg_preview_small.jpg?20121105220855",
|
|
||||||
@"http://static2.dmcdn.net/static/video/777/448/51844777:jpeg_preview_small.jpg?20121105220715",
|
|
||||||
@"http://static2.dmcdn.net/static/video/567/348/51843765:jpeg_preview_small.jpg?20121105220708",
|
|
||||||
@"http://static2.dmcdn.net/static/video/905/248/51842509:jpeg_preview_small.jpg?20121105220640",
|
|
||||||
@"http://static2.dmcdn.net/static/video/857/748/51847758:jpeg_preview_small.jpg?20121105221003",
|
|
||||||
@"http://static2.dmcdn.net/static/video/578/348/51843875:jpeg_preview_small.jpg?20121105220350",
|
|
||||||
@"http://static2.dmcdn.net/static/video/214/448/51844412:jpeg_preview_small.jpg?20121105220415",
|
|
||||||
@"http://static2.dmcdn.net/static/video/264/748/51847462:jpeg_preview_small.jpg?20121105220635",
|
|
||||||
@"http://static2.dmcdn.net/static/video/817/748/51847718:jpeg_preview_small.jpg?20121105220233",
|
|
||||||
@"http://static2.dmcdn.net/static/video/807/748/51847708:jpeg_preview_small.jpg?20121105220241",
|
|
||||||
@"http://static2.dmcdn.net/static/video/199/838/51838991:jpeg_preview_small.jpg?20121105220605",
|
|
||||||
@"http://static2.dmcdn.net/static/video/776/748/51847677:jpeg_preview_small.jpg?20121105220150",
|
|
||||||
@"http://static2.dmcdn.net/static/video/986/748/51847689:jpeg_preview_small.jpg?20121105224514",
|
|
||||||
@"http://static2.dmcdn.net/static/video/915/748/51847519:jpeg_preview_small.jpg?20121105222216",
|
|
||||||
@"http://static2.dmcdn.net/static/video/983/448/51844389:jpeg_preview_small.jpg?20121105220116",
|
|
||||||
@"http://static2.dmcdn.net/static/video/751/348/51843157:jpeg_preview_small.jpg?20121105220104",
|
|
||||||
@"http://static2.dmcdn.net/static/video/192/538/51835291:jpeg_preview_small.jpg?20121105220103",
|
|
||||||
@"http://static2.dmcdn.net/static/video/596/448/51844695:jpeg_preview_small.jpg?20121105220033",
|
|
||||||
@"http://static2.dmcdn.net/static/video/750/648/51846057:jpeg_preview_small.jpg?20121105221259",
|
|
||||||
@"http://static2.dmcdn.net/static/video/441/148/51841144:jpeg_preview_small.jpg?20121105215911",
|
|
||||||
@"http://static2.dmcdn.net/static/video/860/448/51844068:jpeg_preview_small.jpg?20121105215905",
|
|
||||||
@"http://static2.dmcdn.net/static/video/995/748/51847599:jpeg_preview_small.jpg?20121105215939",
|
|
||||||
@"http://static2.dmcdn.net/static/video/774/748/51847477:jpeg_preview_small.jpg?20121105223414",
|
|
||||||
@"http://static2.dmcdn.net/static/video/498/648/51846894:jpeg_preview_small.jpg?20121105221807",
|
|
||||||
@"http://static2.dmcdn.net/static/video/011/748/51847110:jpeg_preview_small.jpg?20121105221118",
|
|
||||||
@"http://static2.dmcdn.net/static/video/794/748/51847497:jpeg_preview_small.jpg?20121105220829",
|
|
||||||
@"http://static2.dmcdn.net/static/video/988/648/51846889:jpeg_preview_small.jpg?20121105222149",
|
|
||||||
@"http://static2.dmcdn.net/static/video/769/548/51845967:jpeg_preview_small.jpg?20121105215601",
|
|
||||||
@"http://static2.dmcdn.net/static/video/225/448/51844522:jpeg_preview_small.jpg?20121105215552",
|
|
||||||
@"http://static2.dmcdn.net/static/video/172/308/51803271:jpeg_preview_small.jpg?20121105215455",
|
|
||||||
@"http://static2.dmcdn.net/static/video/994/748/51847499:jpeg_preview_small.jpg?20121105220343",
|
|
||||||
@"http://static2.dmcdn.net/static/video/852/748/51847258:jpeg_preview_small.jpg?20121105221031",
|
|
||||||
@"http://static2.dmcdn.net/static/video/671/838/51838176:jpeg_preview_small.jpg?20121105215421",
|
|
||||||
@"http://static2.dmcdn.net/static/video/172/448/51844271:jpeg_preview_small.jpg?20121105215420",
|
|
||||||
@"http://static2.dmcdn.net/static/video/735/448/51844537:jpeg_preview_small.jpg?20121105215437",
|
|
||||||
@"http://static2.dmcdn.net/static/video/834/448/51844438:jpeg_preview_small.jpg?20121105215431",
|
|
||||||
@"http://static2.dmcdn.net/static/video/613/448/51844316:jpeg_preview_small.jpg?20121105215431",
|
|
||||||
@"http://static2.dmcdn.net/static/video/581/748/51847185:jpeg_preview_small.jpg?20121105220637",
|
|
||||||
@"http://static2.dmcdn.net/static/video/407/648/51846704:jpeg_preview_small.jpg?20121105220316",
|
|
||||||
@"http://static2.dmcdn.net/static/video/460/448/51844064:jpeg_preview_small.jpg?20121105215245",
|
|
||||||
@"http://static2.dmcdn.net/static/video/298/648/51846892:jpeg_preview_small.jpg?20121105220953",
|
|
||||||
@"http://static2.dmcdn.net/static/video/053/748/51847350:jpeg_preview_small.jpg?20121105221113",
|
|
||||||
@"http://static2.dmcdn.net/static/video/996/448/51844699:jpeg_preview_small.jpg?20121105222807",
|
|
||||||
@"http://static2.dmcdn.net/static/video/451/448/51844154:jpeg_preview_small.jpg?20121105221955",
|
|
||||||
@"http://static2.dmcdn.net/static/video/049/648/51846940:jpeg_preview_small.jpg?20121105215910",
|
|
||||||
@"http://static2.dmcdn.net/static/video/091/748/51847190:jpeg_preview_small.jpg?20121105215617",
|
|
||||||
@"http://static2.dmcdn.net/static/video/573/748/51847375:jpeg_preview_small.jpg?20121105223420",
|
|
||||||
@"http://static2.dmcdn.net/static/video/103/248/51842301:jpeg_preview_small.jpg?20121105215014",
|
|
||||||
@"http://static2.dmcdn.net/static/video/991/548/51845199:jpeg_preview_small.jpg?20121105215407",
|
|
||||||
@"http://static2.dmcdn.net/static/video/872/648/51846278:jpeg_preview_small.jpg?20121105220635",
|
|
||||||
@"http://static2.dmcdn.net/static/video/813/748/51847318:jpeg_preview_small.jpg?20121105214729",
|
|
||||||
@"http://static2.dmcdn.net/static/video/153/448/51844351:jpeg_preview_small.jpg?20121105214622",
|
|
||||||
@"http://static2.dmcdn.net/static/video/328/648/51846823:jpeg_preview_small.jpg?20121105214944",
|
|
||||||
@"http://static2.dmcdn.net/static/video/892/748/51847298:jpeg_preview_small.jpg?20121105224514",
|
|
||||||
@"http://static2.dmcdn.net/static/video/640/048/51840046:jpeg_preview_small.jpg?20121105214430",
|
|
||||||
@"http://static2.dmcdn.net/static/video/153/648/51846351:jpeg_preview_small.jpg?20121105214426",
|
|
||||||
@"http://static2.dmcdn.net/static/video/769/248/51842967:jpeg_preview_small.jpg?20121105214255",
|
|
||||||
@"http://static2.dmcdn.net/static/video/720/448/51844027:jpeg_preview_small.jpg?20121105214248",
|
|
||||||
@"http://static2.dmcdn.net/static/video/895/048/51840598:jpeg_preview_small.jpg?20121105214234",
|
|
||||||
@"http://static2.dmcdn.net/static/video/893/348/51843398:jpeg_preview_small.jpg?20121105214157",
|
|
||||||
@"http://static2.dmcdn.net/static/video/351/748/51847153:jpeg_preview_small.jpg?20121105214106",
|
|
||||||
@"http://static2.dmcdn.net/static/video/364/648/51846463:jpeg_preview_small.jpg?20121105215005",
|
|
||||||
@"http://static2.dmcdn.net/static/video/269/938/51839962:jpeg_preview_small.jpg?20121105214014",
|
|
||||||
nil];
|
nil];
|
||||||
|
|
||||||
|
for (int i=0; i<100; i++) {
|
||||||
|
[_objects addObject:[NSString stringWithFormat:@"https://s3.amazonaws.com/fast-image-cache/demo-images/FICDDemoImage%03d.jpg", i]];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
[SDWebImageManager.sharedManager.imageDownloader setValue:@"SDWebImage Demo" forHTTPHeaderField:@"AppName"];
|
[SDWebImageManager.sharedManager.imageDownloader setValue:@"SDWebImage Demo" forHTTPHeaderField:@"AppName"];
|
||||||
SDWebImageManager.sharedManager.imageDownloader.executionOrder = SDWebImageDownloaderLIFOExecutionOrder;
|
SDWebImageManager.sharedManager.imageDownloader.executionOrder = SDWebImageDownloaderLIFOExecutionOrder;
|
||||||
|
|
@ -372,10 +85,13 @@
|
||||||
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
|
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
|
||||||
}
|
}
|
||||||
|
|
||||||
cell.textLabel.text = [NSString stringWithFormat:@"Image #%d", indexPath.row];
|
[cell.imageView setShowActivityIndicatorView:YES];
|
||||||
|
[cell.imageView setIndicatorStyle:UIActivityIndicatorViewStyleGray];
|
||||||
|
|
||||||
|
cell.textLabel.text = [NSString stringWithFormat:@"Image #%ld", (long)indexPath.row];
|
||||||
cell.imageView.contentMode = UIViewContentModeScaleAspectFill;
|
cell.imageView.contentMode = UIViewContentModeScaleAspectFill;
|
||||||
[cell.imageView setImageWithURL:[NSURL URLWithString:[_objects objectAtIndex:indexPath.row]]
|
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:[_objects objectAtIndex:indexPath.row]]
|
||||||
placeholderImage:[UIImage imageNamed:@"placeholder"] options:indexPath.row == 0 ? SDWebImageRefreshCached : 0];
|
placeholderImage:[UIImage imageNamed:@"placeholder"] options:indexPath.row == 0 ? SDWebImageRefreshCached : 0];
|
||||||
return cell;
|
return cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
<key>CFBundleExecutable</key>
|
<key>CFBundleExecutable</key>
|
||||||
<string>${EXECUTABLE_NAME}</string>
|
<string>${EXECUTABLE_NAME}</string>
|
||||||
<key>CFBundleIdentifier</key>
|
<key>CFBundleIdentifier</key>
|
||||||
<string>com.dailymotion.${PRODUCT_NAME:rfc1034identifier}</string>
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||||
<key>CFBundleInfoDictionaryVersion</key>
|
<key>CFBundleInfoDictionaryVersion</key>
|
||||||
<string>6.0</string>
|
<string>6.0</string>
|
||||||
<key>CFBundleName</key>
|
<key>CFBundleName</key>
|
||||||
|
|
@ -24,6 +24,11 @@
|
||||||
<string>1.0</string>
|
<string>1.0</string>
|
||||||
<key>LSRequiresIPhoneOS</key>
|
<key>LSRequiresIPhoneOS</key>
|
||||||
<true/>
|
<true/>
|
||||||
|
<key>NSAppTransportSecurity</key>
|
||||||
|
<dict>
|
||||||
|
<key>NSAllowsArbitraryLoads</key>
|
||||||
|
<true/>
|
||||||
|
</dict>
|
||||||
<key>UIRequiredDeviceCapabilities</key>
|
<key>UIRequiredDeviceCapabilities</key>
|
||||||
<array>
|
<array>
|
||||||
<string>armv7</string>
|
<string>armv7</string>
|
||||||
|
|
|
||||||
2
LICENSE
2
LICENSE
|
|
@ -1,4 +1,4 @@
|
||||||
Copyright (c) 2009 Olivier Poitrey <rs@dailymotion.com>
|
Copyright (c) 2016 Olivier Poitrey rs@dailymotion.com
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
||||||
202
README.md
202
README.md
|
|
@ -1,11 +1,18 @@
|
||||||
Web Image
|
Web Image
|
||||||
=========
|
=========
|
||||||
|
[](https://travis-ci.org/rs/SDWebImage)
|
||||||
|
[](http://cocoadocs.org/docsets/SDWebImage/)
|
||||||
|
[](http://cocoadocs.org/docsets/SDWebImage/)
|
||||||
|
[](https://www.apache.org/licenses/LICENSE-2.0.html)
|
||||||
|
[](https://www.versioneye.com/objective-c/sdwebimage/3.3)
|
||||||
|
[](https://www.versioneye.com/objective-c/sdwebimage/references)
|
||||||
|
[](https://github.com/rs/SDWebImage)
|
||||||
|
|
||||||
This library provides a category for UIImageVIew with support for remote images coming from the web.
|
This library provides a category for UIImageView with support for remote images coming from the web.
|
||||||
|
|
||||||
It provides:
|
It provides:
|
||||||
|
|
||||||
- An UIImageView category adding web image and cache management to the Cocoa Touch framework
|
- An `UIImageView` category adding web image and cache management to the Cocoa Touch framework
|
||||||
- An asynchronous image downloader
|
- An asynchronous image downloader
|
||||||
- An asynchronous memory + disk image caching with automatic cache expiration handling
|
- An asynchronous memory + disk image caching with automatic cache expiration handling
|
||||||
- Animated GIF support
|
- Animated GIF support
|
||||||
|
|
@ -16,25 +23,26 @@ It provides:
|
||||||
- A guarantee that main thread will never be blocked
|
- A guarantee that main thread will never be blocked
|
||||||
- Performances!
|
- Performances!
|
||||||
- Use GCD and ARC
|
- Use GCD and ARC
|
||||||
|
- Arm64 support
|
||||||
|
|
||||||
NOTE: The version 3.0 of SDWebImage isn't fully backward compatible with 2.0 and requires iOS 5.0
|
NOTE: Version 3.8 of SDWebImage requires iOS 7 or later (because of NSURLSession).
|
||||||
minimum deployement version. If you need iOS < 5.0 support, please use the last [2.0 version](https://github.com/rs/SDWebImage/tree/2.0-compat).
|
Versions 3.7 to 3.0 requires iOS 5.1.1. If you need iOS < 5.0 support, please use the last [2.0 version](https://github.com/rs/SDWebImage/tree/2.0-compat).
|
||||||
|
|
||||||
[How is SDWebImage better than X?](https://github.com/rs/SDWebImage/wiki/How-is-SDWebImage-better-than-X%3F)
|
[How is SDWebImage better than X?](https://github.com/rs/SDWebImage/wiki/How-is-SDWebImage-better-than-X%3F)
|
||||||
|
|
||||||
Who Use It
|
Who Uses It
|
||||||
----------
|
----------
|
||||||
|
|
||||||
Find out [who use SDWebImage](https://github.com/rs/SDWebImage/wiki/Who-Use-SDWebImage) and add your app to the list.
|
Find out [who uses SDWebImage](https://github.com/rs/SDWebImage/wiki/Who-Uses-SDWebImage) and add your app to the list.
|
||||||
|
|
||||||
How To Use
|
How To Use
|
||||||
----------
|
----------
|
||||||
|
|
||||||
API documentation is available at [http://hackemist.com/SDWebImage/doc/](http://hackemist.com/SDWebImage/doc/)
|
API documentation is available at [CocoaDocs - SDWebImage](http://cocoadocs.org/docsets/SDWebImage/)
|
||||||
|
|
||||||
### Using UIImageView+WebCache category with UITableView
|
### Using UIImageView+WebCache category with UITableView
|
||||||
|
|
||||||
Just #import the UIImageView+WebCache.h header, and call the setImageWithURL:placeholderImage:
|
Just #import the UIImageView+WebCache.h header, and call the sd_setImageWithURL:placeholderImage:
|
||||||
method from the tableView:cellForRowAtIndexPath: UITableViewDataSource method. Everything will be
|
method from the tableView:cellForRowAtIndexPath: UITableViewDataSource method. Everything will be
|
||||||
handled for you, from async downloads to caching management.
|
handled for you, from async downloads to caching management.
|
||||||
|
|
||||||
|
|
@ -43,21 +51,18 @@ handled for you, from async downloads to caching management.
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|
||||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||||
{
|
|
||||||
static NSString *MyIdentifier = @"MyIdentifier";
|
static NSString *MyIdentifier = @"MyIdentifier";
|
||||||
|
|
||||||
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
|
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
|
||||||
|
if (cell == nil) {
|
||||||
if (cell == nil)
|
|
||||||
{
|
|
||||||
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
|
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
|
||||||
reuseIdentifier:MyIdentifier] autorelease];
|
reuseIdentifier:MyIdentifier] autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Here we use the new provided setImageWithURL: method to load the web image
|
// Here we use the new provided sd_setImageWithURL: method to load the web image
|
||||||
[cell.imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
|
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
|
||||||
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
|
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
|
||||||
|
|
||||||
cell.textLabel.text = @"My Text";
|
cell.textLabel.text = @"My Text";
|
||||||
return cell;
|
return cell;
|
||||||
|
|
@ -66,14 +71,16 @@ handled for you, from async downloads to caching management.
|
||||||
|
|
||||||
### Using blocks
|
### Using blocks
|
||||||
|
|
||||||
With blocks, you can be notified about the image download progress and whenever the image retrival
|
With blocks, you can be notified about the image download progress and whenever the image retrieval
|
||||||
has completed with success or not:
|
has completed with success or not:
|
||||||
|
|
||||||
```objective-c
|
```objective-c
|
||||||
// Here we use the new provided setImageWithURL: method to load the web image
|
// Here we use the new provided sd_setImageWithURL: method to load the web image
|
||||||
[cell.imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
|
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
|
||||||
placeholderImage:[UIImage imageNamed:@"placeholder.png"]
|
placeholderImage:[UIImage imageNamed:@"placeholder.png"]
|
||||||
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {... completion code here ...}];
|
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||||
|
... completion code here ...
|
||||||
|
}];
|
||||||
```
|
```
|
||||||
|
|
||||||
Note: neither your success nor failure block will be call if your image request is canceled before completion.
|
Note: neither your success nor failure block will be call if your image request is canceled before completion.
|
||||||
|
|
@ -88,19 +95,16 @@ Here is a simple example of how to use SDWebImageManager:
|
||||||
|
|
||||||
```objective-c
|
```objective-c
|
||||||
SDWebImageManager *manager = [SDWebImageManager sharedManager];
|
SDWebImageManager *manager = [SDWebImageManager sharedManager];
|
||||||
[manager downloadWithURL:imageURL
|
[manager downloadImageWithURL:imageURL
|
||||||
options:0
|
options:0
|
||||||
progress:^(NSUInteger receivedSize, long long expectedSize)
|
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
|
||||||
{
|
// progression tracking code
|
||||||
// progression tracking code
|
|
||||||
}
|
|
||||||
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType)
|
|
||||||
{
|
|
||||||
if (image)
|
|
||||||
{
|
|
||||||
// do something with image
|
|
||||||
}
|
}
|
||||||
}];
|
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||||
|
if (image) {
|
||||||
|
// do something with image
|
||||||
|
}
|
||||||
|
}];
|
||||||
```
|
```
|
||||||
|
|
||||||
### Using Asynchronous Image Downloader Independently
|
### Using Asynchronous Image Downloader Independently
|
||||||
|
|
@ -108,39 +112,36 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager];
|
||||||
It's also possible to use the async image downloader independently:
|
It's also possible to use the async image downloader independently:
|
||||||
|
|
||||||
```objective-c
|
```objective-c
|
||||||
[SDWebImageDownloader.sharedDownloader downloadImageWithURL:imageURL
|
SDWebImageDownloader *downloader = [SDWebImageDownloader sharedDownloader];
|
||||||
options:0
|
[downloader downloadImageWithURL:imageURL
|
||||||
progress:^(NSUInteger receivedSize, long long expectedSize)
|
options:0
|
||||||
{
|
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
|
||||||
// progression tracking code
|
// progression tracking code
|
||||||
}
|
}
|
||||||
completed:^(UIImage *image, NSError *error, BOOL finished)
|
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
|
||||||
{
|
if (image && finished) {
|
||||||
if (image && finished)
|
// do something with image
|
||||||
{
|
}
|
||||||
// do something with image
|
}];
|
||||||
}
|
|
||||||
}];
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Using Asynchronous Image Caching Independently
|
### Using Asynchronous Image Caching Independently
|
||||||
|
|
||||||
It is also possible to use the aync based image cache store independently. SDImageCache
|
It is also possible to use the async based image cache store independently. SDImageCache
|
||||||
maintains a memory cache and an optional disk cache. Disk cache write operations are performed
|
maintains a memory cache and an optional disk cache. Disk cache write operations are performed
|
||||||
asynchronous so it doesn't add unnecessary latency to the UI.
|
asynchronous so it doesn't add unnecessary latency to the UI.
|
||||||
|
|
||||||
The SDImageCache class provides a singleton instance for convenience but you can create your own
|
The SDImageCache class provides a singleton instance for convenience but you can create your own
|
||||||
instance if you want to create separated cache namespace.
|
instance if you want to create separated cache namespace.
|
||||||
|
|
||||||
To lookup the cache, you use the imageForKey: method. If the method returns nil, it means the cache
|
To lookup the cache, you use the `queryDiskCacheForKey:done:` method. If the method returns nil, it means the cache
|
||||||
doesn't currently own the image. You are thus responsible for generating and caching it. The cache
|
doesn't currently own the image. You are thus responsible for generating and caching it. The cache
|
||||||
key is an application unique identifier for the image to cache. It is generally the absolute URL of
|
key is an application unique identifier for the image to cache. It is generally the absolute URL of
|
||||||
the image.
|
the image.
|
||||||
|
|
||||||
```objective-c
|
```objective-c
|
||||||
SDImageCache *imageCache = [SDImageCache.alloc initWithNamespace:@"myNamespace"];
|
SDImageCache *imageCache = [[SDImageCache alloc] initWithNamespace:@"myNamespace"];
|
||||||
[imageCache queryDiskCacheForKey:myCacheKey done:^(UIImage *image)
|
[imageCache queryDiskCacheForKey:myCacheKey done:^(UIImage *image) {
|
||||||
{
|
|
||||||
// image is not nil if image was found
|
// image is not nil if image was found
|
||||||
}];
|
}];
|
||||||
```
|
```
|
||||||
|
|
@ -168,11 +169,9 @@ The following example sets a filter in the application delegate that will remove
|
||||||
the URL before to use it as a cache key:
|
the URL before to use it as a cache key:
|
||||||
|
|
||||||
```objective-c
|
```objective-c
|
||||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||||
{
|
SDWebImageManager.sharedManager.cacheKeyFilter = ^(NSURL *url) {
|
||||||
SDWebImageManager.sharedManager.cacheKeyFilter:^(NSURL *url)
|
url = [[NSURL alloc] initWithScheme:url.scheme host:url.host path:url.path];
|
||||||
{
|
|
||||||
url = [[[NSURL alloc] initWithScheme:url.scheme host:url.host path:url.path] autorelease];
|
|
||||||
return [url absoluteString];
|
return [url absoluteString];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -187,7 +186,7 @@ Common Problems
|
||||||
|
|
||||||
### Using dynamic image size with UITableViewCell
|
### Using dynamic image size with UITableViewCell
|
||||||
|
|
||||||
UITableView determins the size of the image by the first image set for a cell. If your remote images
|
UITableView determines the size of the image by the first image set for a cell. If your remote images
|
||||||
don't have the same size as your placeholder image, you may experience strange anamorphic scaling issue.
|
don't have the same size as your placeholder image, you may experience strange anamorphic scaling issue.
|
||||||
The following article gives a way to workaround this issue:
|
The following article gives a way to workaround this issue:
|
||||||
|
|
||||||
|
|
@ -201,9 +200,9 @@ SDWebImage does very aggressive caching by default. It ignores all kind of cachi
|
||||||
If you don't control the image server you're using, you may not be able to change the URL when its content is updated. This is the case for Facebook avatar URLs for instance. In such case, you may use the `SDWebImageRefreshCached` flag. This will slightly degrade the performance but will respect the HTTP caching control headers:
|
If you don't control the image server you're using, you may not be able to change the URL when its content is updated. This is the case for Facebook avatar URLs for instance. In such case, you may use the `SDWebImageRefreshCached` flag. This will slightly degrade the performance but will respect the HTTP caching control headers:
|
||||||
|
|
||||||
``` objective-c
|
``` objective-c
|
||||||
[imageView setImageWithURL:[NSURL URLWithString:@"https://graph.facebook.com/olivier.poitrey/picture"]
|
[imageView sd_setImageWithURL:[NSURL URLWithString:@"https://graph.facebook.com/olivier.poitrey/picture"]
|
||||||
placeholderImage:[UIImage imageNamed:@"avatar-placeholder.png"]
|
placeholderImage:[UIImage imageNamed:@"avatar-placeholder.png"]
|
||||||
options:SDWebImageRefreshCached];
|
options:SDWebImageRefreshCached];
|
||||||
```
|
```
|
||||||
|
|
||||||
### Add a progress indicator
|
### Add a progress indicator
|
||||||
|
|
@ -213,11 +212,76 @@ See this category: https://github.com/JJSaccolo/UIActivityIndicator-for-SDWebIma
|
||||||
Installation
|
Installation
|
||||||
------------
|
------------
|
||||||
|
|
||||||
There are two ways to use this in your project: copy all the files into your project, or import the project as a static library.
|
There are three ways to use SDWebImage in your project:
|
||||||
|
- using CocoaPods
|
||||||
|
- copying all the files into your project
|
||||||
|
- importing the project as a static library
|
||||||
|
|
||||||
|
### Installation with CocoaPods
|
||||||
|
|
||||||
|
[CocoaPods](http://cocoapods.org/) is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries in your projects. See the [Get Started](http://cocoapods.org/#get_started) section for more details.
|
||||||
|
|
||||||
|
#### Podfile
|
||||||
|
```
|
||||||
|
platform :ios, '7.0'
|
||||||
|
pod 'SDWebImage', '~>3.8'
|
||||||
|
```
|
||||||
|
|
||||||
|
If you are using Swift, be sure to add `use_frameworks!` and set your target to iOS 8+:
|
||||||
|
```
|
||||||
|
platform :ios, '8.0'
|
||||||
|
use_frameworks!
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Subspecs
|
||||||
|
|
||||||
|
There are 3 subspecs available now: `Core`, `MapKit` and `WebP` (this means you can install only some of the SDWebImage modules. By default, you get just `Core`, so if you need `WebP`, you need to specify it).
|
||||||
|
|
||||||
|
Podfile example:
|
||||||
|
```
|
||||||
|
pod 'SDWebImage/WebP'
|
||||||
|
```
|
||||||
|
|
||||||
|
### Installation with Carthage (iOS 8+)
|
||||||
|
|
||||||
|
[Carthage](https://github.com/Carthage/Carthage) is a lightweight dependency manager for Swift and Objective-C. It leverages CocoaTouch modules and is less invasive than CocoaPods.
|
||||||
|
|
||||||
|
To install with carthage, follow the instruction on [Carthage](https://github.com/Carthage/Carthage)
|
||||||
|
|
||||||
|
#### Cartfile
|
||||||
|
```
|
||||||
|
github "rs/SDWebImage"
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Usage
|
||||||
|
Swift
|
||||||
|
|
||||||
|
If you installed using CocoaPods:
|
||||||
|
```
|
||||||
|
import SDWebImage
|
||||||
|
```
|
||||||
|
|
||||||
|
If you installed manually:
|
||||||
|
```
|
||||||
|
import WebImage
|
||||||
|
```
|
||||||
|
|
||||||
|
Objective-C
|
||||||
|
|
||||||
|
```
|
||||||
|
@import WebImage;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Installation by cloning the repository
|
||||||
|
|
||||||
|
In order to gain access to all the files from the repository, you should clone it.
|
||||||
|
```
|
||||||
|
git clone --recursive https://github.com/rs/SDWebImage.git
|
||||||
|
```
|
||||||
|
|
||||||
### Add the SDWebImage project to your project
|
### Add the SDWebImage project to your project
|
||||||
|
|
||||||
- Download and unzip the last version of the framework from the [download page](https://github.com/rs/SDWebImage/wiki/Download-Compiled-Framework)
|
- Download and unzip the last version of the framework from the [download page](https://github.com/rs/SDWebImage/releases)
|
||||||
- Right-click on the project navigator and select "Add Files to "Your Project":
|
- Right-click on the project navigator and select "Add Files to "Your Project":
|
||||||
- In the dialog, select SDWebImage.framework:
|
- In the dialog, select SDWebImage.framework:
|
||||||
- Check the "Copy items into destination group's folder (if needed)" checkbox
|
- Check the "Copy items into destination group's folder (if needed)" checkbox
|
||||||
|
|
@ -233,6 +297,20 @@ Open the "Build Settings" tab, in the "Linking" section, locate the "Other Linke
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
Alternatively, if this causes compilation problems with frameworks that extend optional libraries, such as Parse, RestKit or opencv2, instead of the -ObjC flag use:
|
||||||
|
```
|
||||||
|
-force_load SDWebImage.framework/Versions/Current/SDWebImage
|
||||||
|
```
|
||||||
|
|
||||||
|
If you're using Cocoa Pods and have any frameworks that extend optional libraries, such as Parsen RestKit or opencv2, instead of the -ObjC flag use:
|
||||||
|
```
|
||||||
|
-force_load $(TARGET_BUILD_DIR)/libPods.a
|
||||||
|
```
|
||||||
|
and this:
|
||||||
|
```
|
||||||
|
$(inherited)
|
||||||
|
```
|
||||||
|
|
||||||
### Import headers in your source files
|
### Import headers in your source files
|
||||||
|
|
||||||
In the source files where you need to use the library, import the header file:
|
In the source files where you need to use the library, import the header file:
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
Pod::Spec.new do |s|
|
Pod::Spec.new do |s|
|
||||||
s.name = 'SDWebImage'
|
s.name = 'SDWebImage'
|
||||||
s.version = '3.3'
|
s.version = '3.8.1'
|
||||||
s.platform = :ios, '5.0'
|
s.ios.deployment_target = '7.0'
|
||||||
|
s.tvos.deployment_target = '9.0'
|
||||||
s.license = 'MIT'
|
s.license = 'MIT'
|
||||||
s.summary = 'Asynchronous image downloader with cache support with an UIImageView category.'
|
s.summary = 'Asynchronous image downloader with cache support with an UIImageView category.'
|
||||||
s.homepage = 'https://github.com/rs/SDWebImage'
|
s.homepage = 'https://github.com/rs/SDWebImage'
|
||||||
s.author = { 'Olivier Poitrey' => 'rs@dailymotion.com' }
|
s.author = { 'Olivier Poitrey' => 'rs@dailymotion.com' }
|
||||||
s.source = { :git => 'https://github.com/rs/SDWebImage.git', :tag => '3.3' }
|
s.source = { :git => 'https://github.com/rs/SDWebImage.git', :tag => s.version.to_s }
|
||||||
|
|
||||||
s.description = 'This library provides a category for UIImageView with support for remote ' \
|
s.description = 'This library provides a category for UIImageView with support for remote ' \
|
||||||
'images coming from the web. It provides an UIImageView category adding web ' \
|
'images coming from the web. It provides an UIImageView category adding web ' \
|
||||||
|
|
@ -17,14 +18,30 @@ Pod::Spec.new do |s|
|
||||||
'and performances!'
|
'and performances!'
|
||||||
|
|
||||||
s.requires_arc = true
|
s.requires_arc = true
|
||||||
s.source_files = 'SDWebImage/{NS,SD,UI}*.{h,m}'
|
|
||||||
s.framework = 'ImageIO'
|
s.framework = 'ImageIO'
|
||||||
|
|
||||||
s.dependency 'libwebp'
|
s.default_subspec = 'Core'
|
||||||
|
|
||||||
|
s.subspec 'Core' do |core|
|
||||||
|
core.source_files = 'SDWebImage/{NS,SD,UI}*.{h,m}'
|
||||||
|
core.exclude_files = 'SDWebImage/UIImage+WebP.{h,m}'
|
||||||
|
core.tvos.exclude_files = 'SDWebImage/MKAnnotationView+WebCache.*'
|
||||||
|
end
|
||||||
|
|
||||||
# TODO currently CocoaPods always tries to install the subspec even if the dependency is on just 'SDWebImage'
|
|
||||||
s.subspec 'MapKit' do |mk|
|
s.subspec 'MapKit' do |mk|
|
||||||
|
mk.ios.deployment_target = '7.0'
|
||||||
mk.source_files = 'SDWebImage/MKAnnotationView+WebCache.*'
|
mk.source_files = 'SDWebImage/MKAnnotationView+WebCache.*'
|
||||||
mk.framework = 'MapKit'
|
mk.framework = 'MapKit'
|
||||||
|
mk.dependency 'SDWebImage/Core'
|
||||||
|
end
|
||||||
|
|
||||||
|
s.subspec 'WebP' do |webp|
|
||||||
|
webp.source_files = 'SDWebImage/UIImage+WebP.{h,m}'
|
||||||
|
webp.xcconfig = {
|
||||||
|
'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) SD_WEBP=1',
|
||||||
|
'USER_HEADER_SEARCH_PATHS' => '$(inherited) $(SRCROOT)/libwebp/src'
|
||||||
|
}
|
||||||
|
webp.dependency 'SDWebImage/Core'
|
||||||
|
webp.dependency 'libwebp'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,80 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Scheme
|
||||||
|
LastUpgradeVersion = "0710"
|
||||||
|
version = "1.3">
|
||||||
|
<BuildAction
|
||||||
|
parallelizeBuildables = "YES"
|
||||||
|
buildImplicitDependencies = "YES">
|
||||||
|
<BuildActionEntries>
|
||||||
|
<BuildActionEntry
|
||||||
|
buildForTesting = "YES"
|
||||||
|
buildForRunning = "YES"
|
||||||
|
buildForProfiling = "YES"
|
||||||
|
buildForArchiving = "YES"
|
||||||
|
buildForAnalyzing = "YES">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "00733A4B1BC487C000A5A117"
|
||||||
|
BuildableName = "WebImage.framework"
|
||||||
|
BlueprintName = "WebImage tvOS"
|
||||||
|
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</BuildActionEntry>
|
||||||
|
</BuildActionEntries>
|
||||||
|
</BuildAction>
|
||||||
|
<TestAction
|
||||||
|
buildConfiguration = "Debug"
|
||||||
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||||
|
<Testables>
|
||||||
|
</Testables>
|
||||||
|
<AdditionalOptions>
|
||||||
|
</AdditionalOptions>
|
||||||
|
</TestAction>
|
||||||
|
<LaunchAction
|
||||||
|
buildConfiguration = "Debug"
|
||||||
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
launchStyle = "0"
|
||||||
|
useCustomWorkingDirectory = "NO"
|
||||||
|
ignoresPersistentStateOnLaunch = "NO"
|
||||||
|
debugDocumentVersioning = "YES"
|
||||||
|
debugServiceExtension = "internal"
|
||||||
|
allowLocationSimulation = "YES">
|
||||||
|
<MacroExpansion>
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "00733A4B1BC487C000A5A117"
|
||||||
|
BuildableName = "WebImage.framework"
|
||||||
|
BlueprintName = "WebImage tvOS"
|
||||||
|
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</MacroExpansion>
|
||||||
|
<AdditionalOptions>
|
||||||
|
</AdditionalOptions>
|
||||||
|
</LaunchAction>
|
||||||
|
<ProfileAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||||
|
savedToolIdentifier = ""
|
||||||
|
useCustomWorkingDirectory = "NO"
|
||||||
|
debugDocumentVersioning = "YES">
|
||||||
|
<MacroExpansion>
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "00733A4B1BC487C000A5A117"
|
||||||
|
BuildableName = "WebImage.framework"
|
||||||
|
BlueprintName = "WebImage tvOS"
|
||||||
|
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</MacroExpansion>
|
||||||
|
</ProfileAction>
|
||||||
|
<AnalyzeAction
|
||||||
|
buildConfiguration = "Debug">
|
||||||
|
</AnalyzeAction>
|
||||||
|
<ArchiveAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
revealArchiveInOrganizer = "YES">
|
||||||
|
</ArchiveAction>
|
||||||
|
</Scheme>
|
||||||
|
|
@ -0,0 +1,80 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Scheme
|
||||||
|
LastUpgradeVersion = "0710"
|
||||||
|
version = "1.3">
|
||||||
|
<BuildAction
|
||||||
|
parallelizeBuildables = "YES"
|
||||||
|
buildImplicitDependencies = "YES">
|
||||||
|
<BuildActionEntries>
|
||||||
|
<BuildActionEntry
|
||||||
|
buildForTesting = "YES"
|
||||||
|
buildForRunning = "YES"
|
||||||
|
buildForProfiling = "YES"
|
||||||
|
buildForArchiving = "YES"
|
||||||
|
buildForAnalyzing = "YES">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "4A2CADFE1AB4BB5300B6BC39"
|
||||||
|
BuildableName = "WebImage.framework"
|
||||||
|
BlueprintName = "WebImage"
|
||||||
|
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</BuildActionEntry>
|
||||||
|
</BuildActionEntries>
|
||||||
|
</BuildAction>
|
||||||
|
<TestAction
|
||||||
|
buildConfiguration = "Debug"
|
||||||
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||||
|
<Testables>
|
||||||
|
</Testables>
|
||||||
|
<AdditionalOptions>
|
||||||
|
</AdditionalOptions>
|
||||||
|
</TestAction>
|
||||||
|
<LaunchAction
|
||||||
|
buildConfiguration = "Debug"
|
||||||
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
launchStyle = "0"
|
||||||
|
useCustomWorkingDirectory = "NO"
|
||||||
|
ignoresPersistentStateOnLaunch = "NO"
|
||||||
|
debugDocumentVersioning = "YES"
|
||||||
|
debugServiceExtension = "internal"
|
||||||
|
allowLocationSimulation = "YES">
|
||||||
|
<MacroExpansion>
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "4A2CADFE1AB4BB5300B6BC39"
|
||||||
|
BuildableName = "WebImage.framework"
|
||||||
|
BlueprintName = "WebImage"
|
||||||
|
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</MacroExpansion>
|
||||||
|
<AdditionalOptions>
|
||||||
|
</AdditionalOptions>
|
||||||
|
</LaunchAction>
|
||||||
|
<ProfileAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||||
|
savedToolIdentifier = ""
|
||||||
|
useCustomWorkingDirectory = "NO"
|
||||||
|
debugDocumentVersioning = "YES">
|
||||||
|
<MacroExpansion>
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "4A2CADFE1AB4BB5300B6BC39"
|
||||||
|
BuildableName = "WebImage.framework"
|
||||||
|
BlueprintName = "WebImage"
|
||||||
|
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</MacroExpansion>
|
||||||
|
</ProfileAction>
|
||||||
|
<AnalyzeAction
|
||||||
|
buildConfiguration = "Debug">
|
||||||
|
</AnalyzeAction>
|
||||||
|
<ArchiveAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
revealArchiveInOrganizer = "YES">
|
||||||
|
</ArchiveAction>
|
||||||
|
</Scheme>
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Workspace
|
||||||
|
version = "1.0">
|
||||||
|
<FileRef
|
||||||
|
location = "group:Examples/SDWebImage Demo.xcodeproj">
|
||||||
|
</FileRef>
|
||||||
|
<FileRef
|
||||||
|
location = "group:Tests/SDWebImage Tests.xcodeproj">
|
||||||
|
</FileRef>
|
||||||
|
<FileRef
|
||||||
|
location = "group:LICENSE">
|
||||||
|
</FileRef>
|
||||||
|
<FileRef
|
||||||
|
location = "group:README.md">
|
||||||
|
</FileRef>
|
||||||
|
<FileRef
|
||||||
|
location = "group:SDWebImage.podspec">
|
||||||
|
</FileRef>
|
||||||
|
<FileRef
|
||||||
|
location = "group:CHANGELOG.md">
|
||||||
|
</FileRef>
|
||||||
|
<FileRef
|
||||||
|
location = "group:Tests/Pods/Pods.xcodeproj">
|
||||||
|
</FileRef>
|
||||||
|
</Workspace>
|
||||||
|
|
@ -0,0 +1,91 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Scheme
|
||||||
|
LastUpgradeVersion = "0710"
|
||||||
|
version = "1.3">
|
||||||
|
<BuildAction
|
||||||
|
parallelizeBuildables = "YES"
|
||||||
|
buildImplicitDependencies = "YES">
|
||||||
|
<BuildActionEntries>
|
||||||
|
<BuildActionEntry
|
||||||
|
buildForTesting = "YES"
|
||||||
|
buildForRunning = "YES"
|
||||||
|
buildForProfiling = "YES"
|
||||||
|
buildForArchiving = "YES"
|
||||||
|
buildForAnalyzing = "YES">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "53761294155AB74D005750A4"
|
||||||
|
BuildableName = "SDWebImage Demo.app"
|
||||||
|
BlueprintName = "SDWebImage Demo"
|
||||||
|
ReferencedContainer = "container:Examples/SDWebImage Demo.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</BuildActionEntry>
|
||||||
|
</BuildActionEntries>
|
||||||
|
</BuildAction>
|
||||||
|
<TestAction
|
||||||
|
buildConfiguration = "Debug"
|
||||||
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||||
|
<Testables>
|
||||||
|
</Testables>
|
||||||
|
<MacroExpansion>
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "53761294155AB74D005750A4"
|
||||||
|
BuildableName = "SDWebImage Demo.app"
|
||||||
|
BlueprintName = "SDWebImage Demo"
|
||||||
|
ReferencedContainer = "container:Examples/SDWebImage Demo.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</MacroExpansion>
|
||||||
|
<AdditionalOptions>
|
||||||
|
</AdditionalOptions>
|
||||||
|
</TestAction>
|
||||||
|
<LaunchAction
|
||||||
|
buildConfiguration = "Debug"
|
||||||
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
launchStyle = "0"
|
||||||
|
useCustomWorkingDirectory = "NO"
|
||||||
|
ignoresPersistentStateOnLaunch = "NO"
|
||||||
|
debugDocumentVersioning = "YES"
|
||||||
|
debugServiceExtension = "internal"
|
||||||
|
allowLocationSimulation = "YES">
|
||||||
|
<BuildableProductRunnable
|
||||||
|
runnableDebuggingMode = "0">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "53761294155AB74D005750A4"
|
||||||
|
BuildableName = "SDWebImage Demo.app"
|
||||||
|
BlueprintName = "SDWebImage Demo"
|
||||||
|
ReferencedContainer = "container:Examples/SDWebImage Demo.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</BuildableProductRunnable>
|
||||||
|
<AdditionalOptions>
|
||||||
|
</AdditionalOptions>
|
||||||
|
</LaunchAction>
|
||||||
|
<ProfileAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||||
|
savedToolIdentifier = ""
|
||||||
|
useCustomWorkingDirectory = "NO"
|
||||||
|
debugDocumentVersioning = "YES">
|
||||||
|
<BuildableProductRunnable
|
||||||
|
runnableDebuggingMode = "0">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "53761294155AB74D005750A4"
|
||||||
|
BuildableName = "SDWebImage Demo.app"
|
||||||
|
BlueprintName = "SDWebImage Demo"
|
||||||
|
ReferencedContainer = "container:Examples/SDWebImage Demo.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</BuildableProductRunnable>
|
||||||
|
</ProfileAction>
|
||||||
|
<AnalyzeAction
|
||||||
|
buildConfiguration = "Debug">
|
||||||
|
</AnalyzeAction>
|
||||||
|
<ArchiveAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
revealArchiveInOrganizer = "YES">
|
||||||
|
</ArchiveAction>
|
||||||
|
</Scheme>
|
||||||
|
|
@ -0,0 +1,71 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Scheme
|
||||||
|
LastUpgradeVersion = "0710"
|
||||||
|
version = "1.3">
|
||||||
|
<BuildAction
|
||||||
|
parallelizeBuildables = "YES"
|
||||||
|
buildImplicitDependencies = "YES">
|
||||||
|
<BuildActionEntries>
|
||||||
|
<BuildActionEntry
|
||||||
|
buildForTesting = "YES"
|
||||||
|
buildForRunning = "YES"
|
||||||
|
buildForProfiling = "YES"
|
||||||
|
buildForArchiving = "YES"
|
||||||
|
buildForAnalyzing = "YES">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "531041C2157EAFA400BBABC3"
|
||||||
|
BuildableName = "libSDWebImage+MKAnnotation.a"
|
||||||
|
BlueprintName = "SDWebImage+MKAnnotation"
|
||||||
|
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</BuildActionEntry>
|
||||||
|
</BuildActionEntries>
|
||||||
|
</BuildAction>
|
||||||
|
<TestAction
|
||||||
|
buildConfiguration = "Debug"
|
||||||
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||||
|
<Testables>
|
||||||
|
</Testables>
|
||||||
|
<AdditionalOptions>
|
||||||
|
</AdditionalOptions>
|
||||||
|
</TestAction>
|
||||||
|
<LaunchAction
|
||||||
|
buildConfiguration = "Debug"
|
||||||
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
launchStyle = "0"
|
||||||
|
useCustomWorkingDirectory = "NO"
|
||||||
|
ignoresPersistentStateOnLaunch = "NO"
|
||||||
|
debugDocumentVersioning = "YES"
|
||||||
|
debugServiceExtension = "internal"
|
||||||
|
allowLocationSimulation = "YES">
|
||||||
|
<MacroExpansion>
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "531041C2157EAFA400BBABC3"
|
||||||
|
BuildableName = "libSDWebImage+MKAnnotation.a"
|
||||||
|
BlueprintName = "SDWebImage+MKAnnotation"
|
||||||
|
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</MacroExpansion>
|
||||||
|
<AdditionalOptions>
|
||||||
|
</AdditionalOptions>
|
||||||
|
</LaunchAction>
|
||||||
|
<ProfileAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||||
|
savedToolIdentifier = ""
|
||||||
|
useCustomWorkingDirectory = "NO"
|
||||||
|
debugDocumentVersioning = "YES">
|
||||||
|
</ProfileAction>
|
||||||
|
<AnalyzeAction
|
||||||
|
buildConfiguration = "Debug">
|
||||||
|
</AnalyzeAction>
|
||||||
|
<ArchiveAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
revealArchiveInOrganizer = "YES">
|
||||||
|
</ArchiveAction>
|
||||||
|
</Scheme>
|
||||||
|
|
@ -0,0 +1,71 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Scheme
|
||||||
|
LastUpgradeVersion = "0710"
|
||||||
|
version = "1.3">
|
||||||
|
<BuildAction
|
||||||
|
parallelizeBuildables = "YES"
|
||||||
|
buildImplicitDependencies = "YES">
|
||||||
|
<BuildActionEntries>
|
||||||
|
<BuildActionEntry
|
||||||
|
buildForTesting = "YES"
|
||||||
|
buildForRunning = "YES"
|
||||||
|
buildForProfiling = "YES"
|
||||||
|
buildForArchiving = "YES"
|
||||||
|
buildForAnalyzing = "YES">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "537D957317ECC1FE0097C263"
|
||||||
|
BuildableName = "libSDWebImage+WebP.a"
|
||||||
|
BlueprintName = "SDWebImage+WebP"
|
||||||
|
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</BuildActionEntry>
|
||||||
|
</BuildActionEntries>
|
||||||
|
</BuildAction>
|
||||||
|
<TestAction
|
||||||
|
buildConfiguration = "Debug"
|
||||||
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||||
|
<Testables>
|
||||||
|
</Testables>
|
||||||
|
<AdditionalOptions>
|
||||||
|
</AdditionalOptions>
|
||||||
|
</TestAction>
|
||||||
|
<LaunchAction
|
||||||
|
buildConfiguration = "Debug"
|
||||||
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
launchStyle = "0"
|
||||||
|
useCustomWorkingDirectory = "NO"
|
||||||
|
ignoresPersistentStateOnLaunch = "NO"
|
||||||
|
debugDocumentVersioning = "YES"
|
||||||
|
debugServiceExtension = "internal"
|
||||||
|
allowLocationSimulation = "YES">
|
||||||
|
<MacroExpansion>
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "537D957317ECC1FE0097C263"
|
||||||
|
BuildableName = "libSDWebImage+WebP.a"
|
||||||
|
BlueprintName = "SDWebImage+WebP"
|
||||||
|
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</MacroExpansion>
|
||||||
|
<AdditionalOptions>
|
||||||
|
</AdditionalOptions>
|
||||||
|
</LaunchAction>
|
||||||
|
<ProfileAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||||
|
savedToolIdentifier = ""
|
||||||
|
useCustomWorkingDirectory = "NO"
|
||||||
|
debugDocumentVersioning = "YES">
|
||||||
|
</ProfileAction>
|
||||||
|
<AnalyzeAction
|
||||||
|
buildConfiguration = "Debug">
|
||||||
|
</AnalyzeAction>
|
||||||
|
<ArchiveAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
revealArchiveInOrganizer = "YES">
|
||||||
|
</ArchiveAction>
|
||||||
|
</Scheme>
|
||||||
|
|
@ -0,0 +1,71 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Scheme
|
||||||
|
LastUpgradeVersion = "0710"
|
||||||
|
version = "1.3">
|
||||||
|
<BuildAction
|
||||||
|
parallelizeBuildables = "YES"
|
||||||
|
buildImplicitDependencies = "YES">
|
||||||
|
<BuildActionEntries>
|
||||||
|
<BuildActionEntry
|
||||||
|
buildForTesting = "YES"
|
||||||
|
buildForRunning = "YES"
|
||||||
|
buildForProfiling = "YES"
|
||||||
|
buildForArchiving = "YES"
|
||||||
|
buildForAnalyzing = "YES">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "53761307155AD0D5005750A4"
|
||||||
|
BuildableName = "libSDWebImage.a"
|
||||||
|
BlueprintName = "SDWebImage"
|
||||||
|
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</BuildActionEntry>
|
||||||
|
</BuildActionEntries>
|
||||||
|
</BuildAction>
|
||||||
|
<TestAction
|
||||||
|
buildConfiguration = "Debug"
|
||||||
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||||
|
<Testables>
|
||||||
|
</Testables>
|
||||||
|
<AdditionalOptions>
|
||||||
|
</AdditionalOptions>
|
||||||
|
</TestAction>
|
||||||
|
<LaunchAction
|
||||||
|
buildConfiguration = "Debug"
|
||||||
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
launchStyle = "0"
|
||||||
|
useCustomWorkingDirectory = "NO"
|
||||||
|
ignoresPersistentStateOnLaunch = "NO"
|
||||||
|
debugDocumentVersioning = "YES"
|
||||||
|
debugServiceExtension = "internal"
|
||||||
|
allowLocationSimulation = "YES">
|
||||||
|
<MacroExpansion>
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "53761307155AD0D5005750A4"
|
||||||
|
BuildableName = "libSDWebImage.a"
|
||||||
|
BlueprintName = "SDWebImage"
|
||||||
|
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</MacroExpansion>
|
||||||
|
<AdditionalOptions>
|
||||||
|
</AdditionalOptions>
|
||||||
|
</LaunchAction>
|
||||||
|
<ProfileAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||||
|
savedToolIdentifier = ""
|
||||||
|
useCustomWorkingDirectory = "NO"
|
||||||
|
debugDocumentVersioning = "YES">
|
||||||
|
</ProfileAction>
|
||||||
|
<AnalyzeAction
|
||||||
|
buildConfiguration = "Debug">
|
||||||
|
</AnalyzeAction>
|
||||||
|
<ArchiveAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
revealArchiveInOrganizer = "YES">
|
||||||
|
</ArchiveAction>
|
||||||
|
</Scheme>
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<Scheme
|
<Scheme
|
||||||
LastUpgradeVersion = "0460"
|
LastUpgradeVersion = "0710"
|
||||||
version = "1.3">
|
version = "1.3">
|
||||||
<BuildAction
|
<BuildAction
|
||||||
parallelizeBuildables = "YES"
|
parallelizeBuildables = "YES"
|
||||||
|
|
@ -23,30 +23,42 @@
|
||||||
</BuildActionEntries>
|
</BuildActionEntries>
|
||||||
</BuildAction>
|
</BuildAction>
|
||||||
<TestAction
|
<TestAction
|
||||||
|
buildConfiguration = "Debug"
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||||
buildConfiguration = "Debug">
|
|
||||||
<Testables>
|
<Testables>
|
||||||
</Testables>
|
</Testables>
|
||||||
|
<AdditionalOptions>
|
||||||
|
</AdditionalOptions>
|
||||||
</TestAction>
|
</TestAction>
|
||||||
<LaunchAction
|
<LaunchAction
|
||||||
|
buildConfiguration = "Debug"
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
launchStyle = "0"
|
launchStyle = "0"
|
||||||
useCustomWorkingDirectory = "NO"
|
useCustomWorkingDirectory = "NO"
|
||||||
buildConfiguration = "Debug"
|
|
||||||
ignoresPersistentStateOnLaunch = "NO"
|
ignoresPersistentStateOnLaunch = "NO"
|
||||||
debugDocumentVersioning = "YES"
|
debugDocumentVersioning = "YES"
|
||||||
|
debugServiceExtension = "internal"
|
||||||
allowLocationSimulation = "YES">
|
allowLocationSimulation = "YES">
|
||||||
|
<MacroExpansion>
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "539F912B16316D2D00160719"
|
||||||
|
BuildableName = "SDWebImageFramework"
|
||||||
|
BlueprintName = "SDWebImageFramework"
|
||||||
|
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</MacroExpansion>
|
||||||
<AdditionalOptions>
|
<AdditionalOptions>
|
||||||
</AdditionalOptions>
|
</AdditionalOptions>
|
||||||
</LaunchAction>
|
</LaunchAction>
|
||||||
<ProfileAction
|
<ProfileAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||||
savedToolIdentifier = ""
|
savedToolIdentifier = ""
|
||||||
useCustomWorkingDirectory = "NO"
|
useCustomWorkingDirectory = "NO"
|
||||||
buildConfiguration = "Release"
|
|
||||||
debugDocumentVersioning = "YES">
|
debugDocumentVersioning = "YES">
|
||||||
</ProfileAction>
|
</ProfileAction>
|
||||||
<AnalyzeAction
|
<AnalyzeAction
|
||||||
|
|
@ -0,0 +1,99 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Scheme
|
||||||
|
LastUpgradeVersion = "0710"
|
||||||
|
version = "1.3">
|
||||||
|
<BuildAction
|
||||||
|
parallelizeBuildables = "YES"
|
||||||
|
buildImplicitDependencies = "YES">
|
||||||
|
<BuildActionEntries>
|
||||||
|
<BuildActionEntry
|
||||||
|
buildForTesting = "YES"
|
||||||
|
buildForRunning = "YES"
|
||||||
|
buildForProfiling = "NO"
|
||||||
|
buildForArchiving = "NO"
|
||||||
|
buildForAnalyzing = "YES">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "DA248D52195472AA00390AB0"
|
||||||
|
BuildableName = "Tests.xctest"
|
||||||
|
BlueprintName = "Tests"
|
||||||
|
ReferencedContainer = "container:Tests/SDWebImage Tests.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</BuildActionEntry>
|
||||||
|
</BuildActionEntries>
|
||||||
|
</BuildAction>
|
||||||
|
<TestAction
|
||||||
|
buildConfiguration = "Debug"
|
||||||
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||||
|
<Testables>
|
||||||
|
<TestableReference
|
||||||
|
skipped = "NO">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "DA248D52195472AA00390AB0"
|
||||||
|
BuildableName = "Tests.xctest"
|
||||||
|
BlueprintName = "Tests"
|
||||||
|
ReferencedContainer = "container:Tests/SDWebImage Tests.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</TestableReference>
|
||||||
|
</Testables>
|
||||||
|
<MacroExpansion>
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "DA248D52195472AA00390AB0"
|
||||||
|
BuildableName = "Tests.xctest"
|
||||||
|
BlueprintName = "Tests"
|
||||||
|
ReferencedContainer = "container:Tests/SDWebImage Tests.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</MacroExpansion>
|
||||||
|
<AdditionalOptions>
|
||||||
|
</AdditionalOptions>
|
||||||
|
</TestAction>
|
||||||
|
<LaunchAction
|
||||||
|
buildConfiguration = "Debug"
|
||||||
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
launchStyle = "0"
|
||||||
|
useCustomWorkingDirectory = "NO"
|
||||||
|
ignoresPersistentStateOnLaunch = "NO"
|
||||||
|
debugDocumentVersioning = "YES"
|
||||||
|
debugServiceExtension = "internal"
|
||||||
|
allowLocationSimulation = "YES">
|
||||||
|
<MacroExpansion>
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "DA248D52195472AA00390AB0"
|
||||||
|
BuildableName = "Tests.xctest"
|
||||||
|
BlueprintName = "Tests"
|
||||||
|
ReferencedContainer = "container:Tests/SDWebImage Tests.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</MacroExpansion>
|
||||||
|
<AdditionalOptions>
|
||||||
|
</AdditionalOptions>
|
||||||
|
</LaunchAction>
|
||||||
|
<ProfileAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||||
|
savedToolIdentifier = ""
|
||||||
|
useCustomWorkingDirectory = "NO"
|
||||||
|
debugDocumentVersioning = "YES">
|
||||||
|
<MacroExpansion>
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "DA248D52195472AA00390AB0"
|
||||||
|
BuildableName = "Tests.xctest"
|
||||||
|
BlueprintName = "Tests"
|
||||||
|
ReferencedContainer = "container:Tests/SDWebImage Tests.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</MacroExpansion>
|
||||||
|
</ProfileAction>
|
||||||
|
<AnalyzeAction
|
||||||
|
buildConfiguration = "Debug">
|
||||||
|
</AnalyzeAction>
|
||||||
|
<ArchiveAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
revealArchiveInOrganizer = "YES">
|
||||||
|
</ArchiveAction>
|
||||||
|
</Scheme>
|
||||||
|
|
@ -0,0 +1,80 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Scheme
|
||||||
|
LastUpgradeVersion = "0710"
|
||||||
|
version = "1.3">
|
||||||
|
<BuildAction
|
||||||
|
parallelizeBuildables = "YES"
|
||||||
|
buildImplicitDependencies = "YES">
|
||||||
|
<BuildActionEntries>
|
||||||
|
<BuildActionEntry
|
||||||
|
buildForTesting = "YES"
|
||||||
|
buildForRunning = "YES"
|
||||||
|
buildForProfiling = "YES"
|
||||||
|
buildForArchiving = "YES"
|
||||||
|
buildForAnalyzing = "YES">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "4A2CADFE1AB4BB5300B6BC39"
|
||||||
|
BuildableName = "WebImage.framework"
|
||||||
|
BlueprintName = "WebImage"
|
||||||
|
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</BuildActionEntry>
|
||||||
|
</BuildActionEntries>
|
||||||
|
</BuildAction>
|
||||||
|
<TestAction
|
||||||
|
buildConfiguration = "Debug"
|
||||||
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||||
|
<Testables>
|
||||||
|
</Testables>
|
||||||
|
<AdditionalOptions>
|
||||||
|
</AdditionalOptions>
|
||||||
|
</TestAction>
|
||||||
|
<LaunchAction
|
||||||
|
buildConfiguration = "Debug"
|
||||||
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
launchStyle = "0"
|
||||||
|
useCustomWorkingDirectory = "NO"
|
||||||
|
ignoresPersistentStateOnLaunch = "NO"
|
||||||
|
debugDocumentVersioning = "YES"
|
||||||
|
debugServiceExtension = "internal"
|
||||||
|
allowLocationSimulation = "YES">
|
||||||
|
<MacroExpansion>
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "4A2CADFE1AB4BB5300B6BC39"
|
||||||
|
BuildableName = "WebImage.framework"
|
||||||
|
BlueprintName = "WebImage"
|
||||||
|
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</MacroExpansion>
|
||||||
|
<AdditionalOptions>
|
||||||
|
</AdditionalOptions>
|
||||||
|
</LaunchAction>
|
||||||
|
<ProfileAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||||
|
savedToolIdentifier = ""
|
||||||
|
useCustomWorkingDirectory = "NO"
|
||||||
|
debugDocumentVersioning = "YES">
|
||||||
|
<MacroExpansion>
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "4A2CADFE1AB4BB5300B6BC39"
|
||||||
|
BuildableName = "WebImage.framework"
|
||||||
|
BlueprintName = "WebImage"
|
||||||
|
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</MacroExpansion>
|
||||||
|
</ProfileAction>
|
||||||
|
<AnalyzeAction
|
||||||
|
buildConfiguration = "Debug">
|
||||||
|
</AnalyzeAction>
|
||||||
|
<ArchiveAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
revealArchiveInOrganizer = "YES">
|
||||||
|
</ArchiveAction>
|
||||||
|
</Scheme>
|
||||||
|
|
@ -14,82 +14,111 @@
|
||||||
*/
|
*/
|
||||||
@interface MKAnnotationView (WebCache)
|
@interface MKAnnotationView (WebCache)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current image URL.
|
||||||
|
*
|
||||||
|
* Note that because of the limitations of categories this property can get out of sync
|
||||||
|
* if you use sd_setImage: directly.
|
||||||
|
*/
|
||||||
|
- (NSURL *)sd_imageURL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`.
|
* Set the imageView `image` with an `url`.
|
||||||
*
|
*
|
||||||
* The downloand is asynchronous and cached.
|
* The download is asynchronous and cached.
|
||||||
*
|
*
|
||||||
* @param url The url for the image.
|
* @param url The url for the image.
|
||||||
*/
|
*/
|
||||||
- (void)setImageWithURL:(NSURL *)url;
|
- (void)sd_setImageWithURL:(NSURL *)url;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url` and a placeholder.
|
* Set the imageView `image` with an `url` and a placeholder.
|
||||||
*
|
*
|
||||||
* The downloand is asynchronous and cached.
|
* The download is asynchronous and cached.
|
||||||
*
|
*
|
||||||
* @param url The url for the image.
|
* @param url The url for the image.
|
||||||
* @param placeholder The image to be set initially, until the image request finishes.
|
* @param placeholder The image to be set initially, until the image request finishes.
|
||||||
* @see setImageWithURL:placeholderImage:options:
|
* @see sd_setImageWithURL:placeholderImage:options:
|
||||||
*/
|
*/
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder;
|
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||||
*
|
*
|
||||||
* The downloand is asynchronous and cached.
|
* The download is asynchronous and cached.
|
||||||
*
|
*
|
||||||
* @param url The url for the image.
|
* @param url The url for the image.
|
||||||
* @param placeholder The image to be set initially, until the image request finishes.
|
* @param placeholder The image to be set initially, until the image request finishes.
|
||||||
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||||
*/
|
*/
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
|
|
||||||
|
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`.
|
* Set the imageView `image` with an `url`.
|
||||||
*
|
*
|
||||||
* The downloand is asynchronous and cached.
|
* The download is asynchronous and cached.
|
||||||
*
|
*
|
||||||
* @param url The url for the image.
|
* @param url The url for the image.
|
||||||
* @param completedBlock A block called when operation has been completed. This block as no return value
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||||
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||||
* indicating if the image was retrived from the local cache of from the network.
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
|
* The fourth parameter is the original image url.
|
||||||
*/
|
*/
|
||||||
- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock;
|
- (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`, placeholder.
|
* Set the imageView `image` with an `url`, placeholder.
|
||||||
*
|
*
|
||||||
* The downloand is asynchronous and cached.
|
* The download is asynchronous and cached.
|
||||||
*
|
*
|
||||||
* @param url The url for the image.
|
* @param url The url for the image.
|
||||||
* @param placeholder The image to be set initially, until the image request finishes.
|
* @param placeholder The image to be set initially, until the image request finishes.
|
||||||
* @param completedBlock A block called when operation has been completed. This block as no return value
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||||
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||||
* indicating if the image was retrived from the local cache of from the network.
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
|
* The fourth parameter is the original image url.
|
||||||
*/
|
*/
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock;
|
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||||
*
|
*
|
||||||
* The downloand is asynchronous and cached.
|
* The download is asynchronous and cached.
|
||||||
*
|
*
|
||||||
* @param url The url for the image.
|
* @param url The url for the image.
|
||||||
* @param placeholder The image to be set initially, until the image request finishes.
|
* @param placeholder The image to be set initially, until the image request finishes.
|
||||||
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||||
* @param completedBlock A block called when operation has been completed. This block as no return value
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||||
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||||
* indicating if the image was retrived from the local cache of from the network.
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
|
* The fourth parameter is the original image url.
|
||||||
*/
|
*/
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock;
|
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancel the current download
|
* Cancel the current download
|
||||||
*/
|
*/
|
||||||
- (void)cancelCurrentImageLoad;
|
- (void)sd_cancelCurrentImageLoad;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@interface MKAnnotationView (WebCacheDeprecated)
|
||||||
|
|
||||||
|
- (NSURL *)imageURL __deprecated_msg("Use `sd_imageURL`");
|
||||||
|
|
||||||
|
- (void)setImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:`");
|
||||||
|
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:`");
|
||||||
|
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:`");
|
||||||
|
|
||||||
|
- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:completed:`");
|
||||||
|
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:completed:`");
|
||||||
|
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:completed:`");
|
||||||
|
|
||||||
|
- (void)cancelCurrentImageLoad __deprecated_msg("Use `sd_cancelCurrentImageLoad`");
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -8,83 +8,128 @@
|
||||||
|
|
||||||
#import "MKAnnotationView+WebCache.h"
|
#import "MKAnnotationView+WebCache.h"
|
||||||
#import "objc/runtime.h"
|
#import "objc/runtime.h"
|
||||||
|
#import "UIView+WebCacheOperation.h"
|
||||||
|
|
||||||
static char operationKey;
|
static char imageURLKey;
|
||||||
|
|
||||||
@implementation MKAnnotationView (WebCache)
|
@implementation MKAnnotationView (WebCache)
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url
|
- (NSURL *)sd_imageURL {
|
||||||
{
|
return objc_getAssociatedObject(self, &imageURLKey);
|
||||||
[self setImageWithURL:url placeholderImage:nil options:0 completed:nil];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder
|
- (void)sd_setImageWithURL:(NSURL *)url {
|
||||||
{
|
[self sd_setImageWithURL:url placeholderImage:nil options:0 completed:nil];
|
||||||
[self setImageWithURL:url placeholderImage:placeholder options:0 completed:nil];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options
|
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
|
||||||
{
|
[self sd_setImageWithURL:url placeholderImage:placeholder options:0 completed:nil];
|
||||||
[self setImageWithURL:url placeholderImage:placeholder options:options completed:nil];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock
|
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
||||||
{
|
[self sd_setImageWithURL:url placeholderImage:placeholder options:options completed:nil];
|
||||||
[self setImageWithURL:url placeholderImage:nil options:0 completed:completedBlock];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock
|
- (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock {
|
||||||
{
|
[self sd_setImageWithURL:url placeholderImage:nil options:0 completed:completedBlock];
|
||||||
[self setImageWithURL:url placeholderImage:placeholder options:0 completed:completedBlock];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock
|
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock {
|
||||||
{
|
[self sd_setImageWithURL:url placeholderImage:placeholder options:0 completed:completedBlock];
|
||||||
[self cancelCurrentImageLoad];
|
}
|
||||||
|
|
||||||
|
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
|
||||||
|
[self sd_cancelCurrentImageLoad];
|
||||||
|
|
||||||
|
objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||||
self.image = placeholder;
|
self.image = placeholder;
|
||||||
|
|
||||||
if (url)
|
if (url) {
|
||||||
{
|
__weak __typeof(self)wself = self;
|
||||||
__weak MKAnnotationView *wself = self;
|
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||||
id<SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished)
|
|
||||||
{
|
|
||||||
if (!wself) return;
|
if (!wself) return;
|
||||||
void (^block)(void) = ^
|
dispatch_main_sync_safe(^{
|
||||||
{
|
|
||||||
__strong MKAnnotationView *sself = wself;
|
__strong MKAnnotationView *sself = wself;
|
||||||
if (!sself) return;
|
if (!sself) return;
|
||||||
if (image)
|
if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock) {
|
||||||
{
|
completedBlock(image, error, cacheType, url);
|
||||||
sself.image = image;
|
return;
|
||||||
|
} else if (image) {
|
||||||
|
wself.image = image;
|
||||||
|
[wself setNeedsLayout];
|
||||||
|
} else {
|
||||||
|
if ((options & SDWebImageDelayPlaceholder)) {
|
||||||
|
wself.image = placeholder;
|
||||||
|
[wself setNeedsLayout];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (completedBlock && finished)
|
if (completedBlock && finished) {
|
||||||
{
|
completedBlock(image, error, cacheType, url);
|
||||||
completedBlock(image, error, cacheType);
|
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
if ([NSThread isMainThread])
|
|
||||||
{
|
|
||||||
block();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dispatch_sync(dispatch_get_main_queue(), block);
|
|
||||||
}
|
|
||||||
}];
|
}];
|
||||||
objc_setAssociatedObject(self, &operationKey, operation, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
[self sd_setImageLoadOperation:operation forKey:@"MKAnnotationViewImage"];
|
||||||
|
} else {
|
||||||
|
dispatch_main_async_safe(^{
|
||||||
|
NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
|
||||||
|
if (completedBlock) {
|
||||||
|
completedBlock(nil, error, SDImageCacheTypeNone, url);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)cancelCurrentImageLoad
|
- (void)sd_cancelCurrentImageLoad {
|
||||||
{
|
[self sd_cancelImageLoadOperationWithKey:@"MKAnnotationViewImage"];
|
||||||
// Cancel in progress downloader from queue
|
}
|
||||||
id<SDWebImageOperation> operation = objc_getAssociatedObject(self, &operationKey);
|
|
||||||
if (operation)
|
@end
|
||||||
{
|
|
||||||
[operation cancel];
|
|
||||||
objc_setAssociatedObject(self, &operationKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
@implementation MKAnnotationView (WebCacheDeprecated)
|
||||||
}
|
|
||||||
|
- (NSURL *)imageURL {
|
||||||
|
return [self sd_imageURL];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setImageWithURL:(NSURL *)url {
|
||||||
|
[self sd_setImageWithURL:url placeholderImage:nil options:0 completed:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
|
||||||
|
[self sd_setImageWithURL:url placeholderImage:placeholder options:0 completed:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
||||||
|
[self sd_setImageWithURL:url placeholderImage:placeholder options:options completed:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock {
|
||||||
|
[self sd_setImageWithURL:url placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||||
|
if (completedBlock) {
|
||||||
|
completedBlock(image, error, cacheType);
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock {
|
||||||
|
[self sd_setImageWithURL:url placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||||
|
if (completedBlock) {
|
||||||
|
completedBlock(image, error, cacheType);
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
|
||||||
|
[self sd_setImageWithURL:url placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||||
|
if (completedBlock) {
|
||||||
|
completedBlock(image, error, cacheType);
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)cancelCurrentImageLoad {
|
||||||
|
[self sd_cancelCurrentImageLoad];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
//
|
|
||||||
// NSData+GIF.h
|
|
||||||
// SDWebImage
|
|
||||||
//
|
|
||||||
// Created by Andy LaVoy on 4/28/13.
|
|
||||||
// Copyright (c) 2013 Dailymotion. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
|
|
||||||
@interface NSData (GIF)
|
|
||||||
|
|
||||||
- (BOOL)sd_isGIF;
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
//
|
|
||||||
// NSData+GIF.m
|
|
||||||
// SDWebImage
|
|
||||||
//
|
|
||||||
// Created by Andy LaVoy on 4/28/13.
|
|
||||||
// Copyright (c) 2013 Dailymotion. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import "NSData+GIF.h"
|
|
||||||
|
|
||||||
@implementation NSData (GIF)
|
|
||||||
|
|
||||||
- (BOOL)sd_isGIF
|
|
||||||
{
|
|
||||||
BOOL isGIF = NO;
|
|
||||||
|
|
||||||
uint8_t c;
|
|
||||||
[self getBytes:&c length:1];
|
|
||||||
|
|
||||||
switch (c)
|
|
||||||
{
|
|
||||||
case 0x47: // probably a GIF
|
|
||||||
isGIF = YES;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return isGIF;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
//
|
||||||
|
// Created by Fabrice Aneche on 06/01/14.
|
||||||
|
// Copyright (c) 2014 Dailymotion. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
@interface NSData (ImageContentType)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute the content type for an image data
|
||||||
|
*
|
||||||
|
* @param data the input data
|
||||||
|
*
|
||||||
|
* @return the content type as string (i.e. image/jpeg, image/gif)
|
||||||
|
*/
|
||||||
|
+ (NSString *)sd_contentTypeForImageData:(NSData *)data;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@interface NSData (ImageContentTypeDeprecated)
|
||||||
|
|
||||||
|
+ (NSString *)contentTypeForImageData:(NSData *)data __deprecated_msg("Use `sd_contentTypeForImageData:`");
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
//
|
||||||
|
// Created by Fabrice Aneche on 06/01/14.
|
||||||
|
// Copyright (c) 2014 Dailymotion. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "NSData+ImageContentType.h"
|
||||||
|
|
||||||
|
|
||||||
|
@implementation NSData (ImageContentType)
|
||||||
|
|
||||||
|
+ (NSString *)sd_contentTypeForImageData:(NSData *)data {
|
||||||
|
uint8_t c;
|
||||||
|
[data getBytes:&c length:1];
|
||||||
|
switch (c) {
|
||||||
|
case 0xFF:
|
||||||
|
return @"image/jpeg";
|
||||||
|
case 0x89:
|
||||||
|
return @"image/png";
|
||||||
|
case 0x47:
|
||||||
|
return @"image/gif";
|
||||||
|
case 0x49:
|
||||||
|
case 0x4D:
|
||||||
|
return @"image/tiff";
|
||||||
|
case 0x52:
|
||||||
|
// R as RIFF for WEBP
|
||||||
|
if ([data length] < 12) {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSString *testString = [[NSString alloc] initWithData:[data subdataWithRange:NSMakeRange(0, 12)] encoding:NSASCIIStringEncoding];
|
||||||
|
if ([testString hasPrefix:@"RIFF"] && [testString hasSuffix:@"WEBP"]) {
|
||||||
|
return @"image/webp";
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@implementation NSData (ImageContentTypeDeprecated)
|
||||||
|
|
||||||
|
+ (NSString *)contentTypeForImageData:(NSData *)data {
|
||||||
|
return [self sd_contentTypeForImageData:data];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
@ -9,12 +9,11 @@
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import "SDWebImageCompat.h"
|
#import "SDWebImageCompat.h"
|
||||||
|
|
||||||
enum SDImageCacheType
|
typedef NS_ENUM(NSInteger, SDImageCacheType) {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* The image wasn't available the SDWebImage caches, but was downloaded from the web.
|
* The image wasn't available the SDWebImage caches, but was downloaded from the web.
|
||||||
*/
|
*/
|
||||||
SDImageCacheTypeNone = 0,
|
SDImageCacheTypeNone,
|
||||||
/**
|
/**
|
||||||
* The image was obtained from the disk cache.
|
* The image was obtained from the disk cache.
|
||||||
*/
|
*/
|
||||||
|
|
@ -24,7 +23,12 @@ enum SDImageCacheType
|
||||||
*/
|
*/
|
||||||
SDImageCacheTypeMemory
|
SDImageCacheTypeMemory
|
||||||
};
|
};
|
||||||
typedef enum SDImageCacheType SDImageCacheType;
|
|
||||||
|
typedef void(^SDWebImageQueryCompletedBlock)(UIImage *image, SDImageCacheType cacheType);
|
||||||
|
|
||||||
|
typedef void(^SDWebImageCheckCacheCompletionBlock)(BOOL isInCache);
|
||||||
|
|
||||||
|
typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger totalSize);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SDImageCache maintains a memory cache and an optional disk cache. Disk cache write operations are performed
|
* SDImageCache maintains a memory cache and an optional disk cache. Disk cache write operations are performed
|
||||||
|
|
@ -32,6 +36,32 @@ typedef enum SDImageCacheType SDImageCacheType;
|
||||||
*/
|
*/
|
||||||
@interface SDImageCache : NSObject
|
@interface SDImageCache : NSObject
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decompressing images that are downloaded and cached can improve performance but can consume lot of memory.
|
||||||
|
* Defaults to YES. Set this to NO if you are experiencing a crash due to excessive memory consumption.
|
||||||
|
*/
|
||||||
|
@property (assign, nonatomic) BOOL shouldDecompressImages;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* disable iCloud backup [defaults to YES]
|
||||||
|
*/
|
||||||
|
@property (assign, nonatomic) BOOL shouldDisableiCloud;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* use memory cache [defaults to YES]
|
||||||
|
*/
|
||||||
|
@property (assign, nonatomic) BOOL shouldCacheImagesInMemory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The maximum "total cost" of the in-memory image cache. The cost function is the number of pixels held in memory.
|
||||||
|
*/
|
||||||
|
@property (assign, nonatomic) NSUInteger maxMemoryCost;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The maximum number of objects the cache should hold.
|
||||||
|
*/
|
||||||
|
@property (assign, nonatomic) NSUInteger maxMemoryCountLimit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The maximum length of time to keep an image in the cache, in seconds
|
* The maximum length of time to keep an image in the cache, in seconds
|
||||||
*/
|
*/
|
||||||
|
|
@ -40,7 +70,7 @@ typedef enum SDImageCacheType SDImageCacheType;
|
||||||
/**
|
/**
|
||||||
* The maximum size of the cache, in bytes.
|
* The maximum size of the cache, in bytes.
|
||||||
*/
|
*/
|
||||||
@property (assign, nonatomic) unsigned long long maxCacheSize;
|
@property (assign, nonatomic) NSUInteger maxCacheSize;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns global shared cache instance
|
* Returns global shared cache instance
|
||||||
|
|
@ -56,6 +86,16 @@ typedef enum SDImageCacheType SDImageCacheType;
|
||||||
*/
|
*/
|
||||||
- (id)initWithNamespace:(NSString *)ns;
|
- (id)initWithNamespace:(NSString *)ns;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init a new cache store with a specific namespace and directory
|
||||||
|
*
|
||||||
|
* @param ns The namespace to use for this cache store
|
||||||
|
* @param directory Directory to cache disk images in
|
||||||
|
*/
|
||||||
|
- (id)initWithNamespace:(NSString *)ns diskCacheDirectory:(NSString *)directory;
|
||||||
|
|
||||||
|
-(NSString *)makeDiskCachePath:(NSString*)fullNamespace;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a read-only cache path to search for images pre-cached by SDImageCache
|
* Add a read-only cache path to search for images pre-cached by SDImageCache
|
||||||
* Useful if you want to bundle pre-loaded images with your app
|
* Useful if you want to bundle pre-loaded images with your app
|
||||||
|
|
@ -68,15 +108,15 @@ typedef enum SDImageCacheType SDImageCacheType;
|
||||||
* Store an image into memory and disk cache at the given key.
|
* Store an image into memory and disk cache at the given key.
|
||||||
*
|
*
|
||||||
* @param image The image to store
|
* @param image The image to store
|
||||||
* @param key The unique image cache key, usually it's image absolute URL
|
* @param key The unique image cache key, usually it's image absolute URL
|
||||||
*/
|
*/
|
||||||
- (void)storeImage:(UIImage *)image forKey:(NSString *)key;
|
- (void)storeImage:(UIImage *)image forKey:(NSString *)key;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store an image into memory and optionally disk cache at the given key.
|
* Store an image into memory and optionally disk cache at the given key.
|
||||||
*
|
*
|
||||||
* @param image The image to store
|
* @param image The image to store
|
||||||
* @param key The unique image cache key, usually it's image absolute URL
|
* @param key The unique image cache key, usually it's image absolute URL
|
||||||
* @param toDisk Store the image to disk cache if YES
|
* @param toDisk Store the image to disk cache if YES
|
||||||
*/
|
*/
|
||||||
- (void)storeImage:(UIImage *)image forKey:(NSString *)key toDisk:(BOOL)toDisk;
|
- (void)storeImage:(UIImage *)image forKey:(NSString *)key toDisk:(BOOL)toDisk;
|
||||||
|
|
@ -84,21 +124,30 @@ typedef enum SDImageCacheType SDImageCacheType;
|
||||||
/**
|
/**
|
||||||
* Store an image into memory and optionally disk cache at the given key.
|
* Store an image into memory and optionally disk cache at the given key.
|
||||||
*
|
*
|
||||||
* @param image The image to store
|
* @param image The image to store
|
||||||
* @param data The image data as returned by the server, this representation will be used for disk storage
|
* @param recalculate BOOL indicates if imageData can be used or a new data should be constructed from the UIImage
|
||||||
* instead of converting the given image object into a storable/compressed image format in order
|
* @param imageData The image data as returned by the server, this representation will be used for disk storage
|
||||||
* to save quality and CPU
|
* instead of converting the given image object into a storable/compressed image format in order
|
||||||
* @param key The unique image cache key, usually it's image absolute URL
|
* to save quality and CPU
|
||||||
* @param toDisk Store the image to disk cache if YES
|
* @param key The unique image cache key, usually it's image absolute URL
|
||||||
|
* @param toDisk Store the image to disk cache if YES
|
||||||
*/
|
*/
|
||||||
- (void)storeImage:(UIImage *)image imageData:(NSData *)data forKey:(NSString *)key toDisk:(BOOL)toDisk;
|
- (void)storeImage:(UIImage *)image recalculateFromImage:(BOOL)recalculate imageData:(NSData *)imageData forKey:(NSString *)key toDisk:(BOOL)toDisk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store image NSData into disk cache at the given key.
|
||||||
|
*
|
||||||
|
* @param imageData The image data to store
|
||||||
|
* @param key The unique image cache key, usually it's image absolute URL
|
||||||
|
*/
|
||||||
|
- (void)storeImageDataToDisk:(NSData *)imageData forKey:(NSString *)key;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query the disk cache asynchronously.
|
* Query the disk cache asynchronously.
|
||||||
*
|
*
|
||||||
* @param key The unique key used to store the wanted image
|
* @param key The unique key used to store the wanted image
|
||||||
*/
|
*/
|
||||||
- (void)queryDiskCacheForKey:(NSString *)key done:(void (^)(UIImage *image, SDImageCacheType cacheType))doneBlock;
|
- (NSOperation *)queryDiskCacheForKey:(NSString *)key done:(SDWebImageQueryCompletedBlock)doneBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query the memory cache synchronously.
|
* Query the memory cache synchronously.
|
||||||
|
|
@ -115,43 +164,117 @@ typedef enum SDImageCacheType SDImageCacheType;
|
||||||
- (UIImage *)imageFromDiskCacheForKey:(NSString *)key;
|
- (UIImage *)imageFromDiskCacheForKey:(NSString *)key;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the image from memory and disk cache synchronously
|
* Remove the image from memory and disk cache asynchronously
|
||||||
*
|
*
|
||||||
* @param key The unique image cache key
|
* @param key The unique image cache key
|
||||||
*/
|
*/
|
||||||
- (void)removeImageForKey:(NSString *)key;
|
- (void)removeImageForKey:(NSString *)key;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the image from memory and optionaly disk cache synchronously
|
* Remove the image from memory and disk cache asynchronously
|
||||||
*
|
*
|
||||||
* @param key The unique image cache key
|
* @param key The unique image cache key
|
||||||
|
* @param completion An block that should be executed after the image has been removed (optional)
|
||||||
|
*/
|
||||||
|
- (void)removeImageForKey:(NSString *)key withCompletion:(SDWebImageNoParamsBlock)completion;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the image from memory and optionally disk cache asynchronously
|
||||||
|
*
|
||||||
|
* @param key The unique image cache key
|
||||||
* @param fromDisk Also remove cache entry from disk if YES
|
* @param fromDisk Also remove cache entry from disk if YES
|
||||||
*/
|
*/
|
||||||
- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk;
|
- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the image from memory and optionally disk cache asynchronously
|
||||||
|
*
|
||||||
|
* @param key The unique image cache key
|
||||||
|
* @param fromDisk Also remove cache entry from disk if YES
|
||||||
|
* @param completion An block that should be executed after the image has been removed (optional)
|
||||||
|
*/
|
||||||
|
- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk withCompletion:(SDWebImageNoParamsBlock)completion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear all memory cached images
|
* Clear all memory cached images
|
||||||
*/
|
*/
|
||||||
- (void)clearMemory;
|
- (void)clearMemory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear all disk cached images. Non-blocking method - returns immediately.
|
||||||
|
* @param completion An block that should be executed after cache expiration completes (optional)
|
||||||
|
*/
|
||||||
|
- (void)clearDiskOnCompletion:(SDWebImageNoParamsBlock)completion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear all disk cached images
|
* Clear all disk cached images
|
||||||
|
* @see clearDiskOnCompletion:
|
||||||
*/
|
*/
|
||||||
- (void)clearDisk;
|
- (void)clearDisk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove all expired cached image from disk. Non-blocking method - returns immediately.
|
||||||
|
* @param completionBlock An block that should be executed after cache expiration completes (optional)
|
||||||
|
*/
|
||||||
|
- (void)cleanDiskWithCompletionBlock:(SDWebImageNoParamsBlock)completionBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove all expired cached image from disk
|
* Remove all expired cached image from disk
|
||||||
|
* @see cleanDiskWithCompletionBlock:
|
||||||
*/
|
*/
|
||||||
- (void)cleanDisk;
|
- (void)cleanDisk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the size used by the disk cache
|
* Get the size used by the disk cache
|
||||||
*/
|
*/
|
||||||
- (unsigned long long)getSize;
|
- (NSUInteger)getSize;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the number of images in the disk cache
|
* Get the number of images in the disk cache
|
||||||
*/
|
*/
|
||||||
- (int)getDiskCount;
|
- (NSUInteger)getDiskCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asynchronously calculate the disk cache's size.
|
||||||
|
*/
|
||||||
|
- (void)calculateSizeWithCompletionBlock:(SDWebImageCalculateSizeBlock)completionBlock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Async check if image exists in disk cache already (does not load the image)
|
||||||
|
*
|
||||||
|
* @param key the key describing the url
|
||||||
|
* @param completionBlock the block to be executed when the check is done.
|
||||||
|
* @note the completion block will be always executed on the main queue
|
||||||
|
*/
|
||||||
|
- (void)diskImageExistsWithKey:(NSString *)key completion:(SDWebImageCheckCacheCompletionBlock)completionBlock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if image exists in disk cache already (does not load the image)
|
||||||
|
*
|
||||||
|
* @param key the key describing the url
|
||||||
|
*
|
||||||
|
* @return YES if an image exists for the given key
|
||||||
|
*/
|
||||||
|
- (BOOL)diskImageExistsWithKey:(NSString *)key;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the cache path for a certain key (needs the cache path root folder)
|
||||||
|
*
|
||||||
|
* @param key the key (can be obtained from url using cacheKeyForURL)
|
||||||
|
* @param path the cache path root folder
|
||||||
|
*
|
||||||
|
* @return the cache path
|
||||||
|
*/
|
||||||
|
- (NSString *)cachePathForKey:(NSString *)key inPath:(NSString *)path;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the default cache path for a certain key
|
||||||
|
*
|
||||||
|
* @param key the key (can be obtained from url using cacheKeyForURL)
|
||||||
|
*
|
||||||
|
* @return the default cache path
|
||||||
|
*/
|
||||||
|
- (NSString *)defaultCachePathForKey:(NSString *)key;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,51 @@
|
||||||
#import "SDWebImageDecoder.h"
|
#import "SDWebImageDecoder.h"
|
||||||
#import "UIImage+MultiFormat.h"
|
#import "UIImage+MultiFormat.h"
|
||||||
#import <CommonCrypto/CommonDigest.h>
|
#import <CommonCrypto/CommonDigest.h>
|
||||||
#import <mach/mach.h>
|
|
||||||
#import <mach/mach_host.h>
|
// See https://github.com/rs/SDWebImage/pull/1141 for discussion
|
||||||
|
@interface AutoPurgeCache : NSCache
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation AutoPurgeCache
|
||||||
|
|
||||||
|
- (id)init
|
||||||
|
{
|
||||||
|
self = [super init];
|
||||||
|
if (self) {
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(removeAllObjects) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)dealloc
|
||||||
|
{
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
static const NSInteger kDefaultCacheMaxCacheAge = 60 * 60 * 24 * 7; // 1 week
|
static const NSInteger kDefaultCacheMaxCacheAge = 60 * 60 * 24 * 7; // 1 week
|
||||||
|
// PNG signature bytes and data (below)
|
||||||
|
static unsigned char kPNGSignatureBytes[8] = {0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A};
|
||||||
|
static NSData *kPNGSignatureData = nil;
|
||||||
|
|
||||||
|
BOOL ImageDataHasPNGPreffix(NSData *data);
|
||||||
|
|
||||||
|
BOOL ImageDataHasPNGPreffix(NSData *data) {
|
||||||
|
NSUInteger pngSignatureLength = [kPNGSignatureData length];
|
||||||
|
if ([data length] >= pngSignatureLength) {
|
||||||
|
if ([[data subdataWithRange:NSMakeRange(0, pngSignatureLength)] isEqualToData:kPNGSignatureData]) {
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
|
return image.size.height * image.size.width * image.scale * image.scale;
|
||||||
|
}
|
||||||
|
|
||||||
@interface SDImageCache ()
|
@interface SDImageCache ()
|
||||||
|
|
||||||
|
|
@ -25,27 +66,35 @@ static const NSInteger kDefaultCacheMaxCacheAge = 60 * 60 * 24 * 7; // 1 week
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
@implementation SDImageCache
|
@implementation SDImageCache {
|
||||||
|
NSFileManager *_fileManager;
|
||||||
|
}
|
||||||
|
|
||||||
+ (SDImageCache *)sharedImageCache
|
+ (SDImageCache *)sharedImageCache {
|
||||||
{
|
|
||||||
static dispatch_once_t once;
|
static dispatch_once_t once;
|
||||||
static id instance;
|
static id instance;
|
||||||
dispatch_once(&once, ^{instance = self.new;});
|
dispatch_once(&once, ^{
|
||||||
|
instance = [self new];
|
||||||
|
});
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)init
|
- (id)init {
|
||||||
{
|
|
||||||
return [self initWithNamespace:@"default"];
|
return [self initWithNamespace:@"default"];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithNamespace:(NSString *)ns
|
- (id)initWithNamespace:(NSString *)ns {
|
||||||
{
|
NSString *path = [self makeDiskCachePath:ns];
|
||||||
if ((self = [super init]))
|
return [self initWithNamespace:ns diskCacheDirectory:path];
|
||||||
{
|
}
|
||||||
|
|
||||||
|
- (id)initWithNamespace:(NSString *)ns diskCacheDirectory:(NSString *)directory {
|
||||||
|
if ((self = [super init])) {
|
||||||
NSString *fullNamespace = [@"com.hackemist.SDWebImageCache." stringByAppendingString:ns];
|
NSString *fullNamespace = [@"com.hackemist.SDWebImageCache." stringByAppendingString:ns];
|
||||||
|
|
||||||
|
// initialise PNG signature data
|
||||||
|
kPNGSignatureData = [NSData dataWithBytes:kPNGSignatureBytes length:8];
|
||||||
|
|
||||||
// Create IO serial queue
|
// Create IO serial queue
|
||||||
_ioQueue = dispatch_queue_create("com.hackemist.SDWebImageCache", DISPATCH_QUEUE_SERIAL);
|
_ioQueue = dispatch_queue_create("com.hackemist.SDWebImageCache", DISPATCH_QUEUE_SERIAL);
|
||||||
|
|
||||||
|
|
@ -53,14 +102,31 @@ static const NSInteger kDefaultCacheMaxCacheAge = 60 * 60 * 24 * 7; // 1 week
|
||||||
_maxCacheAge = kDefaultCacheMaxCacheAge;
|
_maxCacheAge = kDefaultCacheMaxCacheAge;
|
||||||
|
|
||||||
// Init the memory cache
|
// Init the memory cache
|
||||||
_memCache = [[NSCache alloc] init];
|
_memCache = [[AutoPurgeCache alloc] init];
|
||||||
_memCache.name = fullNamespace;
|
_memCache.name = fullNamespace;
|
||||||
|
|
||||||
// Init the disk cache
|
// Init the disk cache
|
||||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
if (directory != nil) {
|
||||||
_diskCachePath = [paths[0] stringByAppendingPathComponent:fullNamespace];
|
_diskCachePath = [directory stringByAppendingPathComponent:fullNamespace];
|
||||||
|
} else {
|
||||||
|
NSString *path = [self makeDiskCachePath:ns];
|
||||||
|
_diskCachePath = path;
|
||||||
|
}
|
||||||
|
|
||||||
#if TARGET_OS_IPHONE
|
// Set decompression to YES
|
||||||
|
_shouldDecompressImages = YES;
|
||||||
|
|
||||||
|
// memory cache enabled
|
||||||
|
_shouldCacheImagesInMemory = YES;
|
||||||
|
|
||||||
|
// Disable iCloud
|
||||||
|
_shouldDisableiCloud = YES;
|
||||||
|
|
||||||
|
dispatch_sync(_ioQueue, ^{
|
||||||
|
_fileManager = [NSFileManager new];
|
||||||
|
});
|
||||||
|
|
||||||
|
#if TARGET_OS_IOS
|
||||||
// Subscribe to app events
|
// Subscribe to app events
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
selector:@selector(clearMemory)
|
selector:@selector(clearMemory)
|
||||||
|
|
@ -71,356 +137,521 @@ static const NSInteger kDefaultCacheMaxCacheAge = 60 * 60 * 24 * 7; // 1 week
|
||||||
selector:@selector(cleanDisk)
|
selector:@selector(cleanDisk)
|
||||||
name:UIApplicationWillTerminateNotification
|
name:UIApplicationWillTerminateNotification
|
||||||
object:nil];
|
object:nil];
|
||||||
|
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
|
selector:@selector(backgroundCleanDisk)
|
||||||
|
name:UIApplicationDidEnterBackgroundNotification
|
||||||
|
object:nil];
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc {
|
||||||
{
|
|
||||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||||
SDDispatchQueueRelease(_ioQueue);
|
SDDispatchQueueRelease(_ioQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)addReadOnlyCachePath:(NSString *)path
|
- (void)addReadOnlyCachePath:(NSString *)path {
|
||||||
{
|
if (!self.customPaths) {
|
||||||
if (!self.customPaths)
|
self.customPaths = [NSMutableArray new];
|
||||||
{
|
|
||||||
self.customPaths = NSMutableArray.new;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (![self.customPaths containsObject:path])
|
if (![self.customPaths containsObject:path]) {
|
||||||
{
|
|
||||||
[self.customPaths addObject:path];
|
[self.customPaths addObject:path];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark SDImageCache (private)
|
- (NSString *)cachePathForKey:(NSString *)key inPath:(NSString *)path {
|
||||||
|
|
||||||
- (NSString *)cachePathForKey:(NSString *)key inPath:(NSString *)path
|
|
||||||
{
|
|
||||||
NSString *filename = [self cachedFileNameForKey:key];
|
NSString *filename = [self cachedFileNameForKey:key];
|
||||||
return [path stringByAppendingPathComponent:filename];
|
return [path stringByAppendingPathComponent:filename];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *)defaultCachePathForKey:(NSString *)key
|
- (NSString *)defaultCachePathForKey:(NSString *)key {
|
||||||
{
|
|
||||||
return [self cachePathForKey:key inPath:self.diskCachePath];
|
return [self cachePathForKey:key inPath:self.diskCachePath];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *)cachedFileNameForKey:(NSString *)key
|
#pragma mark SDImageCache (private)
|
||||||
{
|
|
||||||
|
- (NSString *)cachedFileNameForKey:(NSString *)key {
|
||||||
const char *str = [key UTF8String];
|
const char *str = [key UTF8String];
|
||||||
|
if (str == NULL) {
|
||||||
|
str = "";
|
||||||
|
}
|
||||||
unsigned char r[CC_MD5_DIGEST_LENGTH];
|
unsigned char r[CC_MD5_DIGEST_LENGTH];
|
||||||
CC_MD5(str, (CC_LONG)strlen(str), r);
|
CC_MD5(str, (CC_LONG)strlen(str), r);
|
||||||
NSString *filename = [NSString stringWithFormat:@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
|
NSString *filename = [NSString stringWithFormat:@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%@",
|
||||||
r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8], r[9], r[10], r[11], r[12], r[13], r[14], r[15]];
|
r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8], r[9], r[10],
|
||||||
|
r[11], r[12], r[13], r[14], r[15], [[key pathExtension] isEqualToString:@""] ? @"" : [NSString stringWithFormat:@".%@", [key pathExtension]]];
|
||||||
|
|
||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark ImageCache
|
#pragma mark ImageCache
|
||||||
|
|
||||||
- (void)storeImage:(UIImage *)image imageData:(NSData *)imageData forKey:(NSString *)key toDisk:(BOOL)toDisk
|
// Init the disk cache
|
||||||
{
|
-(NSString *)makeDiskCachePath:(NSString*)fullNamespace{
|
||||||
if (!image || !key)
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
||||||
{
|
return [paths[0] stringByAppendingPathComponent:fullNamespace];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)storeImage:(UIImage *)image recalculateFromImage:(BOOL)recalculate imageData:(NSData *)imageData forKey:(NSString *)key toDisk:(BOOL)toDisk {
|
||||||
|
if (!image || !key) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// if memory cache is enabled
|
||||||
|
if (self.shouldCacheImagesInMemory) {
|
||||||
|
NSUInteger cost = SDCacheCostForImage(image);
|
||||||
|
[self.memCache setObject:image forKey:key cost:cost];
|
||||||
|
}
|
||||||
|
|
||||||
[self.memCache setObject:image forKey:key cost:image.size.height * image.size.width * image.scale];
|
if (toDisk) {
|
||||||
|
dispatch_async(self.ioQueue, ^{
|
||||||
if (toDisk)
|
|
||||||
{
|
|
||||||
dispatch_async(self.ioQueue, ^
|
|
||||||
{
|
|
||||||
NSData *data = imageData;
|
NSData *data = imageData;
|
||||||
|
|
||||||
if (!data)
|
if (image && (recalculate || !data)) {
|
||||||
{
|
|
||||||
if (image)
|
|
||||||
{
|
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
|
// We need to determine if the image is a PNG or a JPEG
|
||||||
|
// PNGs are easier to detect because they have a unique signature (http://www.w3.org/TR/PNG-Structure.html)
|
||||||
|
// The first eight bytes of a PNG file always contain the following (decimal) values:
|
||||||
|
// 137 80 78 71 13 10 26 10
|
||||||
|
|
||||||
|
// If the imageData is nil (i.e. if trying to save a UIImage directly or the image was transformed on download)
|
||||||
|
// and the image has an alpha channel, we will consider it PNG to avoid losing the transparency
|
||||||
|
int alphaInfo = CGImageGetAlphaInfo(image.CGImage);
|
||||||
|
BOOL hasAlpha = !(alphaInfo == kCGImageAlphaNone ||
|
||||||
|
alphaInfo == kCGImageAlphaNoneSkipFirst ||
|
||||||
|
alphaInfo == kCGImageAlphaNoneSkipLast);
|
||||||
|
BOOL imageIsPng = hasAlpha;
|
||||||
|
|
||||||
|
// But if we have an image data, we will look at the preffix
|
||||||
|
if ([imageData length] >= [kPNGSignatureData length]) {
|
||||||
|
imageIsPng = ImageDataHasPNGPreffix(imageData);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (imageIsPng) {
|
||||||
|
data = UIImagePNGRepresentation(image);
|
||||||
|
}
|
||||||
|
else {
|
||||||
data = UIImageJPEGRepresentation(image, (CGFloat)1.0);
|
data = UIImageJPEGRepresentation(image, (CGFloat)1.0);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
data = [NSBitmapImageRep representationOfImageRepsInArray:image.representations usingType: NSJPEGFileType properties:nil];
|
data = [NSBitmapImageRep representationOfImageRepsInArray:image.representations usingType: NSJPEGFileType properties:nil];
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data)
|
[self storeImageDataToDisk:data forKey:key];
|
||||||
{
|
|
||||||
// Can't use defaultManager another thread
|
|
||||||
NSFileManager *fileManager = NSFileManager.new;
|
|
||||||
|
|
||||||
if (![fileManager fileExistsAtPath:_diskCachePath])
|
|
||||||
{
|
|
||||||
[fileManager createDirectoryAtPath:_diskCachePath withIntermediateDirectories:YES attributes:nil error:NULL];
|
|
||||||
}
|
|
||||||
|
|
||||||
[fileManager createFileAtPath:[self defaultCachePathForKey:key] contents:data attributes:nil];
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)storeImage:(UIImage *)image forKey:(NSString *)key
|
- (void)storeImage:(UIImage *)image forKey:(NSString *)key {
|
||||||
{
|
[self storeImage:image recalculateFromImage:YES imageData:nil forKey:key toDisk:YES];
|
||||||
[self storeImage:image imageData:nil forKey:key toDisk:YES];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)storeImage:(UIImage *)image forKey:(NSString *)key toDisk:(BOOL)toDisk
|
- (void)storeImage:(UIImage *)image forKey:(NSString *)key toDisk:(BOOL)toDisk {
|
||||||
{
|
[self storeImage:image recalculateFromImage:YES imageData:nil forKey:key toDisk:toDisk];
|
||||||
[self storeImage:image imageData:nil forKey:key toDisk:toDisk];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (UIImage *)imageFromMemoryCacheForKey:(NSString *)key
|
- (void)storeImageDataToDisk:(NSData *)imageData forKey:(NSString *)key {
|
||||||
{
|
|
||||||
|
if (!imageData) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (![_fileManager fileExistsAtPath:_diskCachePath]) {
|
||||||
|
[_fileManager createDirectoryAtPath:_diskCachePath withIntermediateDirectories:YES attributes:nil error:NULL];
|
||||||
|
}
|
||||||
|
|
||||||
|
// get cache Path for image key
|
||||||
|
NSString *cachePathForKey = [self defaultCachePathForKey:key];
|
||||||
|
// transform to NSUrl
|
||||||
|
NSURL *fileURL = [NSURL fileURLWithPath:cachePathForKey];
|
||||||
|
|
||||||
|
[_fileManager createFileAtPath:cachePathForKey contents:imageData attributes:nil];
|
||||||
|
|
||||||
|
// disable iCloud backup
|
||||||
|
if (self.shouldDisableiCloud) {
|
||||||
|
[fileURL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)diskImageExistsWithKey:(NSString *)key {
|
||||||
|
BOOL exists = NO;
|
||||||
|
|
||||||
|
// this is an exception to access the filemanager on another queue than ioQueue, but we are using the shared instance
|
||||||
|
// from apple docs on NSFileManager: The methods of the shared NSFileManager object can be called from multiple threads safely.
|
||||||
|
exists = [[NSFileManager defaultManager] fileExistsAtPath:[self defaultCachePathForKey:key]];
|
||||||
|
|
||||||
|
// fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name
|
||||||
|
// checking the key with and without the extension
|
||||||
|
if (!exists) {
|
||||||
|
exists = [[NSFileManager defaultManager] fileExistsAtPath:[[self defaultCachePathForKey:key] stringByDeletingPathExtension]];
|
||||||
|
}
|
||||||
|
|
||||||
|
return exists;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)diskImageExistsWithKey:(NSString *)key completion:(SDWebImageCheckCacheCompletionBlock)completionBlock {
|
||||||
|
dispatch_async(_ioQueue, ^{
|
||||||
|
BOOL exists = [_fileManager fileExistsAtPath:[self defaultCachePathForKey:key]];
|
||||||
|
|
||||||
|
// fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name
|
||||||
|
// checking the key with and without the extension
|
||||||
|
if (!exists) {
|
||||||
|
exists = [_fileManager fileExistsAtPath:[[self defaultCachePathForKey:key] stringByDeletingPathExtension]];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (completionBlock) {
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
completionBlock(exists);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
- (UIImage *)imageFromMemoryCacheForKey:(NSString *)key {
|
||||||
return [self.memCache objectForKey:key];
|
return [self.memCache objectForKey:key];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (UIImage *)imageFromDiskCacheForKey:(NSString *)key
|
- (UIImage *)imageFromDiskCacheForKey:(NSString *)key {
|
||||||
{
|
|
||||||
// First check the in-memory cache...
|
// First check the in-memory cache...
|
||||||
UIImage *image = [self imageFromMemoryCacheForKey:key];
|
UIImage *image = [self imageFromMemoryCacheForKey:key];
|
||||||
if (image)
|
if (image) {
|
||||||
{
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Second check the disk cache...
|
// Second check the disk cache...
|
||||||
UIImage *diskImage = [self diskImageForKey:key];
|
UIImage *diskImage = [self diskImageForKey:key];
|
||||||
if (diskImage)
|
if (diskImage && self.shouldCacheImagesInMemory) {
|
||||||
{
|
NSUInteger cost = SDCacheCostForImage(diskImage);
|
||||||
CGFloat cost = diskImage.size.height * diskImage.size.width * diskImage.scale;
|
|
||||||
[self.memCache setObject:diskImage forKey:key cost:cost];
|
[self.memCache setObject:diskImage forKey:key cost:cost];
|
||||||
}
|
}
|
||||||
|
|
||||||
return diskImage;
|
return diskImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSData *)diskImageDataBySearchingAllPathsForKey:(NSString *)key
|
- (NSData *)diskImageDataBySearchingAllPathsForKey:(NSString *)key {
|
||||||
{
|
|
||||||
NSString *defaultPath = [self defaultCachePathForKey:key];
|
NSString *defaultPath = [self defaultCachePathForKey:key];
|
||||||
NSData *data = [NSData dataWithContentsOfFile:defaultPath];
|
NSData *data = [NSData dataWithContentsOfFile:defaultPath];
|
||||||
if (data)
|
if (data) {
|
||||||
{
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (NSString *path in self.customPaths)
|
// fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name
|
||||||
{
|
// checking the key with and without the extension
|
||||||
|
data = [NSData dataWithContentsOfFile:[defaultPath stringByDeletingPathExtension]];
|
||||||
|
if (data) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSArray *customPaths = [self.customPaths copy];
|
||||||
|
for (NSString *path in customPaths) {
|
||||||
NSString *filePath = [self cachePathForKey:key inPath:path];
|
NSString *filePath = [self cachePathForKey:key inPath:path];
|
||||||
NSData *imageData = [NSData dataWithContentsOfFile:filePath];
|
NSData *imageData = [NSData dataWithContentsOfFile:filePath];
|
||||||
if (imageData) {
|
if (imageData) {
|
||||||
return imageData;
|
return imageData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name
|
||||||
|
// checking the key with and without the extension
|
||||||
|
imageData = [NSData dataWithContentsOfFile:[filePath stringByDeletingPathExtension]];
|
||||||
|
if (imageData) {
|
||||||
|
return imageData;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (UIImage *)diskImageForKey:(NSString *)key
|
- (UIImage *)diskImageForKey:(NSString *)key {
|
||||||
{
|
|
||||||
NSData *data = [self diskImageDataBySearchingAllPathsForKey:key];
|
NSData *data = [self diskImageDataBySearchingAllPathsForKey:key];
|
||||||
if (data)
|
if (data) {
|
||||||
{
|
|
||||||
UIImage *image = [UIImage sd_imageWithData:data];
|
UIImage *image = [UIImage sd_imageWithData:data];
|
||||||
image = [self scaledImageForKey:key image:image];
|
image = [self scaledImageForKey:key image:image];
|
||||||
image = [UIImage decodedImageWithImage:image];
|
if (self.shouldDecompressImages) {
|
||||||
|
image = [UIImage decodedImageWithImage:image];
|
||||||
|
}
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (UIImage *)scaledImageForKey:(NSString *)key image:(UIImage *)image
|
- (UIImage *)scaledImageForKey:(NSString *)key image:(UIImage *)image {
|
||||||
{
|
|
||||||
return SDScaledImageForKey(key, image);
|
return SDScaledImageForKey(key, image);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)queryDiskCacheForKey:(NSString *)key done:(void (^)(UIImage *image, SDImageCacheType cacheType))doneBlock
|
- (NSOperation *)queryDiskCacheForKey:(NSString *)key done:(SDWebImageQueryCompletedBlock)doneBlock {
|
||||||
{
|
if (!doneBlock) {
|
||||||
if (!doneBlock) return;
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
if (!key)
|
if (!key) {
|
||||||
{
|
|
||||||
doneBlock(nil, SDImageCacheTypeNone);
|
doneBlock(nil, SDImageCacheTypeNone);
|
||||||
return;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
// First check the in-memory cache...
|
// First check the in-memory cache...
|
||||||
UIImage *image = [self imageFromMemoryCacheForKey:key];
|
UIImage *image = [self imageFromMemoryCacheForKey:key];
|
||||||
if (image)
|
if (image) {
|
||||||
{
|
|
||||||
doneBlock(image, SDImageCacheTypeMemory);
|
doneBlock(image, SDImageCacheTypeMemory);
|
||||||
return;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch_async(self.ioQueue, ^
|
NSOperation *operation = [NSOperation new];
|
||||||
{
|
dispatch_async(self.ioQueue, ^{
|
||||||
@autoreleasepool
|
if (operation.isCancelled) {
|
||||||
{
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@autoreleasepool {
|
||||||
UIImage *diskImage = [self diskImageForKey:key];
|
UIImage *diskImage = [self diskImageForKey:key];
|
||||||
if (diskImage)
|
if (diskImage && self.shouldCacheImagesInMemory) {
|
||||||
{
|
NSUInteger cost = SDCacheCostForImage(diskImage);
|
||||||
CGFloat cost = diskImage.size.height * diskImage.size.width * diskImage.scale;
|
|
||||||
[self.memCache setObject:diskImage forKey:key cost:cost];
|
[self.memCache setObject:diskImage forKey:key cost:cost];
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
{
|
|
||||||
doneBlock(diskImage, SDImageCacheTypeDisk);
|
doneBlock(diskImage, SDImageCacheTypeDisk);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)removeImageForKey:(NSString *)key {
|
||||||
|
[self removeImageForKey:key withCompletion:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)removeImageForKey:(NSString *)key withCompletion:(SDWebImageNoParamsBlock)completion {
|
||||||
|
[self removeImageForKey:key fromDisk:YES withCompletion:completion];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk {
|
||||||
|
[self removeImageForKey:key fromDisk:fromDisk withCompletion:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk withCompletion:(SDWebImageNoParamsBlock)completion {
|
||||||
|
|
||||||
|
if (key == nil) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self.shouldCacheImagesInMemory) {
|
||||||
|
[self.memCache removeObjectForKey:key];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fromDisk) {
|
||||||
|
dispatch_async(self.ioQueue, ^{
|
||||||
|
[_fileManager removeItemAtPath:[self defaultCachePathForKey:key] error:nil];
|
||||||
|
|
||||||
|
if (completion) {
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
completion();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else if (completion){
|
||||||
|
completion();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setMaxMemoryCost:(NSUInteger)maxMemoryCost {
|
||||||
|
self.memCache.totalCostLimit = maxMemoryCost;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSUInteger)maxMemoryCost {
|
||||||
|
return self.memCache.totalCostLimit;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSUInteger)maxMemoryCountLimit {
|
||||||
|
return self.memCache.countLimit;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setMaxMemoryCountLimit:(NSUInteger)maxCountLimit {
|
||||||
|
self.memCache.countLimit = maxCountLimit;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)clearMemory {
|
||||||
|
[self.memCache removeAllObjects];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)clearDisk {
|
||||||
|
[self clearDiskOnCompletion:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)clearDiskOnCompletion:(SDWebImageNoParamsBlock)completion
|
||||||
|
{
|
||||||
|
dispatch_async(self.ioQueue, ^{
|
||||||
|
[_fileManager removeItemAtPath:self.diskCachePath error:nil];
|
||||||
|
[_fileManager createDirectoryAtPath:self.diskCachePath
|
||||||
|
withIntermediateDirectories:YES
|
||||||
|
attributes:nil
|
||||||
|
error:NULL];
|
||||||
|
|
||||||
|
if (completion) {
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
completion();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)removeImageForKey:(NSString *)key
|
- (void)cleanDisk {
|
||||||
{
|
[self cleanDiskWithCompletionBlock:nil];
|
||||||
[self removeImageForKey:key fromDisk:YES];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk
|
- (void)cleanDiskWithCompletionBlock:(SDWebImageNoParamsBlock)completionBlock {
|
||||||
{
|
dispatch_async(self.ioQueue, ^{
|
||||||
if (key == nil)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
[self.memCache removeObjectForKey:key];
|
|
||||||
|
|
||||||
if (fromDisk)
|
|
||||||
{
|
|
||||||
dispatch_async(self.ioQueue, ^
|
|
||||||
{
|
|
||||||
[[NSFileManager defaultManager] removeItemAtPath:[self defaultCachePathForKey:key] error:nil];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)clearMemory
|
|
||||||
{
|
|
||||||
[self.memCache removeAllObjects];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)clearDisk
|
|
||||||
{
|
|
||||||
dispatch_async(self.ioQueue, ^
|
|
||||||
{
|
|
||||||
[[NSFileManager defaultManager] removeItemAtPath:self.diskCachePath error:nil];
|
|
||||||
[[NSFileManager defaultManager] createDirectoryAtPath:self.diskCachePath
|
|
||||||
withIntermediateDirectories:YES
|
|
||||||
attributes:nil
|
|
||||||
error:NULL];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)cleanDisk
|
|
||||||
{
|
|
||||||
dispatch_async(self.ioQueue, ^
|
|
||||||
{
|
|
||||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
||||||
NSURL *diskCacheURL = [NSURL fileURLWithPath:self.diskCachePath isDirectory:YES];
|
NSURL *diskCacheURL = [NSURL fileURLWithPath:self.diskCachePath isDirectory:YES];
|
||||||
NSArray *resourceKeys = @[ NSURLIsDirectoryKey, NSURLContentModificationDateKey, NSURLTotalFileAllocatedSizeKey ];
|
NSArray *resourceKeys = @[NSURLIsDirectoryKey, NSURLContentModificationDateKey, NSURLTotalFileAllocatedSizeKey];
|
||||||
|
|
||||||
// This enumerator prefetches useful properties for our cache files.
|
// This enumerator prefetches useful properties for our cache files.
|
||||||
NSDirectoryEnumerator *fileEnumerator = [fileManager enumeratorAtURL:diskCacheURL
|
NSDirectoryEnumerator *fileEnumerator = [_fileManager enumeratorAtURL:diskCacheURL
|
||||||
includingPropertiesForKeys:resourceKeys
|
includingPropertiesForKeys:resourceKeys
|
||||||
options:NSDirectoryEnumerationSkipsHiddenFiles
|
options:NSDirectoryEnumerationSkipsHiddenFiles
|
||||||
errorHandler:NULL];
|
errorHandler:NULL];
|
||||||
|
|
||||||
NSDate *expirationDate = [NSDate dateWithTimeIntervalSinceNow:-self.maxCacheAge];
|
NSDate *expirationDate = [NSDate dateWithTimeIntervalSinceNow:-self.maxCacheAge];
|
||||||
NSMutableDictionary *cacheFiles = [NSMutableDictionary dictionary];
|
NSMutableDictionary *cacheFiles = [NSMutableDictionary dictionary];
|
||||||
unsigned long long currentCacheSize = 0;
|
NSUInteger currentCacheSize = 0;
|
||||||
|
|
||||||
// Enumerate all of the files in the cache directory. This loop has two purposes:
|
// Enumerate all of the files in the cache directory. This loop has two purposes:
|
||||||
//
|
//
|
||||||
// 1. Removing files that are older than the expiration date.
|
// 1. Removing files that are older than the expiration date.
|
||||||
// 2. Storing file attributes for the size-based cleanup pass.
|
// 2. Storing file attributes for the size-based cleanup pass.
|
||||||
for (NSURL *fileURL in fileEnumerator)
|
NSMutableArray *urlsToDelete = [[NSMutableArray alloc] init];
|
||||||
{
|
for (NSURL *fileURL in fileEnumerator) {
|
||||||
NSDictionary *resourceValues = [fileURL resourceValuesForKeys:resourceKeys error:NULL];
|
NSDictionary *resourceValues = [fileURL resourceValuesForKeys:resourceKeys error:NULL];
|
||||||
|
|
||||||
// Skip directories.
|
// Skip nil or directories.
|
||||||
if ([resourceValues[NSURLIsDirectoryKey] boolValue])
|
if (!resourceValues || [resourceValues[NSURLIsDirectoryKey] boolValue]) {
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove files that are older than the expiration date;
|
// Remove files that are older than the expiration date;
|
||||||
NSDate *modificationDate = resourceValues[NSURLContentModificationDateKey];
|
NSDate *modificationDate = resourceValues[NSURLContentModificationDateKey];
|
||||||
if ([[modificationDate laterDate:expirationDate] isEqualToDate:expirationDate])
|
if ([[modificationDate laterDate:expirationDate] isEqualToDate:expirationDate]) {
|
||||||
{
|
[urlsToDelete addObject:fileURL];
|
||||||
[fileManager removeItemAtURL:fileURL error:nil];
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store a reference to this file and account for its total size.
|
// Store a reference to this file and account for its total size.
|
||||||
NSNumber *totalAllocatedSize = resourceValues[NSURLTotalFileAllocatedSizeKey];
|
NSNumber *totalAllocatedSize = resourceValues[NSURLTotalFileAllocatedSizeKey];
|
||||||
currentCacheSize += [totalAllocatedSize unsignedLongLongValue];
|
currentCacheSize += [totalAllocatedSize unsignedIntegerValue];
|
||||||
[cacheFiles setObject:resourceValues forKey:fileURL];
|
[cacheFiles setObject:resourceValues forKey:fileURL];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (NSURL *fileURL in urlsToDelete) {
|
||||||
|
[_fileManager removeItemAtURL:fileURL error:nil];
|
||||||
|
}
|
||||||
|
|
||||||
// If our remaining disk cache exceeds a configured maximum size, perform a second
|
// If our remaining disk cache exceeds a configured maximum size, perform a second
|
||||||
// size-based cleanup pass. We delete the oldest files first.
|
// size-based cleanup pass. We delete the oldest files first.
|
||||||
if (self.maxCacheSize > 0 && currentCacheSize > self.maxCacheSize)
|
if (self.maxCacheSize > 0 && currentCacheSize > self.maxCacheSize) {
|
||||||
{
|
|
||||||
// Target half of our maximum cache size for this cleanup pass.
|
// Target half of our maximum cache size for this cleanup pass.
|
||||||
const unsigned long long desiredCacheSize = self.maxCacheSize / 2;
|
const NSUInteger desiredCacheSize = self.maxCacheSize / 2;
|
||||||
|
|
||||||
// Sort the remaining cache files by their last modification time (oldest first).
|
// Sort the remaining cache files by their last modification time (oldest first).
|
||||||
NSArray *sortedFiles = [cacheFiles keysSortedByValueWithOptions:NSSortConcurrent
|
NSArray *sortedFiles = [cacheFiles keysSortedByValueWithOptions:NSSortConcurrent
|
||||||
usingComparator:^NSComparisonResult(id obj1, id obj2)
|
usingComparator:^NSComparisonResult(id obj1, id obj2) {
|
||||||
{
|
return [obj1[NSURLContentModificationDateKey] compare:obj2[NSURLContentModificationDateKey]];
|
||||||
return [obj1[NSURLContentModificationDateKey] compare:obj2[NSURLContentModificationDateKey]];
|
}];
|
||||||
}];
|
|
||||||
|
|
||||||
// Delete files until we fall below our desired cache size.
|
// Delete files until we fall below our desired cache size.
|
||||||
for (NSURL *fileURL in sortedFiles)
|
for (NSURL *fileURL in sortedFiles) {
|
||||||
{
|
if ([_fileManager removeItemAtURL:fileURL error:nil]) {
|
||||||
if ([fileManager removeItemAtURL:fileURL error:nil])
|
|
||||||
{
|
|
||||||
NSDictionary *resourceValues = cacheFiles[fileURL];
|
NSDictionary *resourceValues = cacheFiles[fileURL];
|
||||||
NSNumber *totalAllocatedSize = resourceValues[NSURLTotalFileAllocatedSizeKey];
|
NSNumber *totalAllocatedSize = resourceValues[NSURLTotalFileAllocatedSizeKey];
|
||||||
currentCacheSize -= [totalAllocatedSize unsignedLongLongValue];
|
currentCacheSize -= [totalAllocatedSize unsignedIntegerValue];
|
||||||
|
|
||||||
if (currentCacheSize < desiredCacheSize)
|
if (currentCacheSize < desiredCacheSize) {
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (completionBlock) {
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
completionBlock();
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
-(unsigned long long)getSize
|
- (void)backgroundCleanDisk {
|
||||||
{
|
Class UIApplicationClass = NSClassFromString(@"UIApplication");
|
||||||
unsigned long long size = 0;
|
if(!UIApplicationClass || ![UIApplicationClass respondsToSelector:@selector(sharedApplication)]) {
|
||||||
NSDirectoryEnumerator *fileEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:self.diskCachePath];
|
return;
|
||||||
for (NSString *fileName in fileEnumerator)
|
|
||||||
{
|
|
||||||
NSString *filePath = [self.diskCachePath stringByAppendingPathComponent:fileName];
|
|
||||||
NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
|
|
||||||
size += [attrs fileSize];
|
|
||||||
}
|
}
|
||||||
|
UIApplication *application = [UIApplication performSelector:@selector(sharedApplication)];
|
||||||
|
__block UIBackgroundTaskIdentifier bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
|
||||||
|
// Clean up any unfinished task business by marking where you
|
||||||
|
// stopped or ending the task outright.
|
||||||
|
[application endBackgroundTask:bgTask];
|
||||||
|
bgTask = UIBackgroundTaskInvalid;
|
||||||
|
}];
|
||||||
|
|
||||||
|
// Start the long-running task and return immediately.
|
||||||
|
[self cleanDiskWithCompletionBlock:^{
|
||||||
|
[application endBackgroundTask:bgTask];
|
||||||
|
bgTask = UIBackgroundTaskInvalid;
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSUInteger)getSize {
|
||||||
|
__block NSUInteger size = 0;
|
||||||
|
dispatch_sync(self.ioQueue, ^{
|
||||||
|
NSDirectoryEnumerator *fileEnumerator = [_fileManager enumeratorAtPath:self.diskCachePath];
|
||||||
|
for (NSString *fileName in fileEnumerator) {
|
||||||
|
NSString *filePath = [self.diskCachePath stringByAppendingPathComponent:fileName];
|
||||||
|
NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
|
||||||
|
size += [attrs fileSize];
|
||||||
|
}
|
||||||
|
});
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)getDiskCount
|
- (NSUInteger)getDiskCount {
|
||||||
{
|
__block NSUInteger count = 0;
|
||||||
int count = 0;
|
dispatch_sync(self.ioQueue, ^{
|
||||||
NSDirectoryEnumerator *fileEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:self.diskCachePath];
|
NSDirectoryEnumerator *fileEnumerator = [_fileManager enumeratorAtPath:self.diskCachePath];
|
||||||
for (NSString *fileName in fileEnumerator)
|
count = [[fileEnumerator allObjects] count];
|
||||||
{
|
});
|
||||||
count += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)calculateSizeWithCompletionBlock:(SDWebImageCalculateSizeBlock)completionBlock {
|
||||||
|
NSURL *diskCacheURL = [NSURL fileURLWithPath:self.diskCachePath isDirectory:YES];
|
||||||
|
|
||||||
|
dispatch_async(self.ioQueue, ^{
|
||||||
|
NSUInteger fileCount = 0;
|
||||||
|
NSUInteger totalSize = 0;
|
||||||
|
|
||||||
|
NSDirectoryEnumerator *fileEnumerator = [_fileManager enumeratorAtURL:diskCacheURL
|
||||||
|
includingPropertiesForKeys:@[NSFileSize]
|
||||||
|
options:NSDirectoryEnumerationSkipsHiddenFiles
|
||||||
|
errorHandler:NULL];
|
||||||
|
|
||||||
|
for (NSURL *fileURL in fileEnumerator) {
|
||||||
|
NSNumber *fileSize;
|
||||||
|
[fileURL getResourceValue:&fileSize forKey:NSURLFileSizeKey error:NULL];
|
||||||
|
totalSize += [fileSize unsignedIntegerValue];
|
||||||
|
fileCount += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (completionBlock) {
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
completionBlock(fileCount, totalSize);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,8 @@
|
||||||
#error SDWebImage does not support Objective-C Garbage Collection
|
#error SDWebImage does not support Objective-C Garbage Collection
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_5_0
|
#if __IPHONE_OS_VERSION_MIN_REQUIRED != 20000 && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_5_0
|
||||||
#error SDWebImage doesn't support Deployement Target version < 5.0
|
#error SDWebImage doesn't support Deployment Target version < 5.0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !TARGET_OS_IPHONE
|
#if !TARGET_OS_IPHONE
|
||||||
|
|
@ -26,7 +26,17 @@
|
||||||
#define UIImageView NSImageView
|
#define UIImageView NSImageView
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef NS_ENUM
|
||||||
|
#define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef NS_OPTIONS
|
||||||
|
#define NS_OPTIONS(_type, _name) enum _name : _type _name; enum _name : _type
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if OS_OBJECT_USE_OBJC
|
#if OS_OBJECT_USE_OBJC
|
||||||
|
|
@ -35,10 +45,28 @@
|
||||||
#define SDDispatchQueueRelease(q)
|
#define SDDispatchQueueRelease(q)
|
||||||
#define SDDispatchQueueSetterSementics strong
|
#define SDDispatchQueueSetterSementics strong
|
||||||
#else
|
#else
|
||||||
#undef SDDispatchQueueRelease
|
#undef SDDispatchQueueRelease
|
||||||
#undef SDDispatchQueueSetterSementics
|
#undef SDDispatchQueueSetterSementics
|
||||||
#define SDDispatchQueueRelease(q) (dispatch_release(q))
|
#define SDDispatchQueueRelease(q) (dispatch_release(q))
|
||||||
#define SDDispatchQueueSetterSementics assign
|
#define SDDispatchQueueSetterSementics assign
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern inline UIImage *SDScaledImageForKey(NSString *key, UIImage *image);
|
extern UIImage *SDScaledImageForKey(NSString *key, UIImage *image);
|
||||||
|
|
||||||
|
typedef void(^SDWebImageNoParamsBlock)();
|
||||||
|
|
||||||
|
extern NSString *const SDWebImageErrorDomain;
|
||||||
|
|
||||||
|
#define dispatch_main_sync_safe(block)\
|
||||||
|
if ([NSThread isMainThread]) {\
|
||||||
|
block();\
|
||||||
|
} else {\
|
||||||
|
dispatch_sync(dispatch_get_main_queue(), block);\
|
||||||
|
}
|
||||||
|
|
||||||
|
#define dispatch_main_async_safe(block)\
|
||||||
|
if ([NSThread isMainThread]) {\
|
||||||
|
block();\
|
||||||
|
} else {\
|
||||||
|
dispatch_async(dispatch_get_main_queue(), block);\
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,32 +12,33 @@
|
||||||
#error SDWebImage is ARC only. Either turn on ARC for the project or use -fobjc-arc flag
|
#error SDWebImage is ARC only. Either turn on ARC for the project or use -fobjc-arc flag
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
inline UIImage *SDScaledImageForKey(NSString *key, UIImage *image)
|
inline UIImage *SDScaledImageForKey(NSString *key, UIImage *image) {
|
||||||
{
|
if (!image) {
|
||||||
if ([image.images count] > 0)
|
return nil;
|
||||||
{
|
}
|
||||||
|
|
||||||
|
if ([image.images count] > 0) {
|
||||||
NSMutableArray *scaledImages = [NSMutableArray array];
|
NSMutableArray *scaledImages = [NSMutableArray array];
|
||||||
|
|
||||||
for (UIImage *tempImage in image.images)
|
for (UIImage *tempImage in image.images) {
|
||||||
{
|
|
||||||
[scaledImages addObject:SDScaledImageForKey(key, tempImage)];
|
[scaledImages addObject:SDScaledImageForKey(key, tempImage)];
|
||||||
}
|
}
|
||||||
|
|
||||||
return [UIImage animatedImageWithImages:scaledImages duration:image.duration];
|
return [UIImage animatedImageWithImages:scaledImages duration:image.duration];
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
|
||||||
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
|
CGFloat scale = 1;
|
||||||
{
|
if (key.length >= 8) {
|
||||||
CGFloat scale = 1.0;
|
NSRange range = [key rangeOfString:@"@2x."];
|
||||||
if (key.length >= 8)
|
if (range.location != NSNotFound) {
|
||||||
{
|
|
||||||
// Search @2x. at the end of the string, before a 3 to 4 extension length (only if key len is 8 or more @2x. + 4 len ext)
|
|
||||||
NSRange range = [key rangeOfString:@"@2x." options:0 range:NSMakeRange(key.length - 8, 5)];
|
|
||||||
if (range.location != NSNotFound)
|
|
||||||
{
|
|
||||||
scale = 2.0;
|
scale = 2.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
range = [key rangeOfString:@"@3x."];
|
||||||
|
if (range.location != NSNotFound) {
|
||||||
|
scale = 3.0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UIImage *scaledImage = [[UIImage alloc] initWithCGImage:image.CGImage scale:scale orientation:image.imageOrientation];
|
UIImage *scaledImage = [[UIImage alloc] initWithCGImage:image.CGImage scale:scale orientation:image.imageOrientation];
|
||||||
|
|
@ -46,3 +47,5 @@ inline UIImage *SDScaledImageForKey(NSString *key, UIImage *image)
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NSString *const SDWebImageErrorDomain = @"SDWebImageErrorDomain";
|
||||||
|
|
|
||||||
|
|
@ -12,65 +12,81 @@
|
||||||
|
|
||||||
@implementation UIImage (ForceDecode)
|
@implementation UIImage (ForceDecode)
|
||||||
|
|
||||||
+ (UIImage *)decodedImageWithImage:(UIImage *)image
|
+ (UIImage *)decodedImageWithImage:(UIImage *)image {
|
||||||
{
|
// while downloading huge amount of images
|
||||||
if (image.images)
|
// autorelease the bitmap context
|
||||||
{
|
// and all vars to help system to free memory
|
||||||
// Do not decode animated images
|
// when there are memory warning.
|
||||||
return image;
|
// on iOS7, do not forget to call
|
||||||
|
// [[SDImageCache sharedImageCache] clearMemory];
|
||||||
|
|
||||||
|
if (image == nil) { // Prevent "CGBitmapContextCreateImage: invalid context 0x0" error
|
||||||
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
CGImageRef imageRef = image.CGImage;
|
@autoreleasepool{
|
||||||
CGSize imageSize = CGSizeMake(CGImageGetWidth(imageRef), CGImageGetHeight(imageRef));
|
// do not decode animated images
|
||||||
CGRect imageRect = (CGRect){.origin = CGPointZero, .size = imageSize};
|
if (image.images != nil) {
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
CGImageRef imageRef = image.CGImage;
|
||||||
CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef);
|
|
||||||
|
|
||||||
int infoMask = (bitmapInfo & kCGBitmapAlphaInfoMask);
|
CGImageAlphaInfo alpha = CGImageGetAlphaInfo(imageRef);
|
||||||
BOOL anyNonAlpha = (infoMask == kCGImageAlphaNone ||
|
BOOL anyAlpha = (alpha == kCGImageAlphaFirst ||
|
||||||
infoMask == kCGImageAlphaNoneSkipFirst ||
|
alpha == kCGImageAlphaLast ||
|
||||||
infoMask == kCGImageAlphaNoneSkipLast);
|
alpha == kCGImageAlphaPremultipliedFirst ||
|
||||||
|
alpha == kCGImageAlphaPremultipliedLast);
|
||||||
|
if (anyAlpha) {
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
// CGBitmapContextCreate doesn't support kCGImageAlphaNone with RGB.
|
// current
|
||||||
// https://developer.apple.com/library/mac/#qa/qa1037/_index.html
|
CGColorSpaceModel imageColorSpaceModel = CGColorSpaceGetModel(CGImageGetColorSpace(imageRef));
|
||||||
if (infoMask == kCGImageAlphaNone && CGColorSpaceGetNumberOfComponents(colorSpace) > 1)
|
CGColorSpaceRef colorspaceRef = CGImageGetColorSpace(imageRef);
|
||||||
{
|
|
||||||
// Unset the old alpha info.
|
|
||||||
bitmapInfo &= ~kCGBitmapAlphaInfoMask;
|
|
||||||
|
|
||||||
// Set noneSkipFirst.
|
BOOL unsupportedColorSpace = (imageColorSpaceModel == kCGColorSpaceModelUnknown ||
|
||||||
bitmapInfo |= kCGImageAlphaNoneSkipFirst;
|
imageColorSpaceModel == kCGColorSpaceModelMonochrome ||
|
||||||
|
imageColorSpaceModel == kCGColorSpaceModelCMYK ||
|
||||||
|
imageColorSpaceModel == kCGColorSpaceModelIndexed);
|
||||||
|
if (unsupportedColorSpace) {
|
||||||
|
colorspaceRef = CGColorSpaceCreateDeviceRGB();
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t width = CGImageGetWidth(imageRef);
|
||||||
|
size_t height = CGImageGetHeight(imageRef);
|
||||||
|
NSUInteger bytesPerPixel = 4;
|
||||||
|
NSUInteger bytesPerRow = bytesPerPixel * width;
|
||||||
|
NSUInteger bitsPerComponent = 8;
|
||||||
|
|
||||||
|
|
||||||
|
// kCGImageAlphaNone is not supported in CGBitmapContextCreate.
|
||||||
|
// Since the original image here has no alpha info, use kCGImageAlphaNoneSkipLast
|
||||||
|
// to create bitmap graphics contexts without alpha info.
|
||||||
|
CGContextRef context = CGBitmapContextCreate(NULL,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
bitsPerComponent,
|
||||||
|
bytesPerRow,
|
||||||
|
colorspaceRef,
|
||||||
|
kCGBitmapByteOrderDefault|kCGImageAlphaNoneSkipLast);
|
||||||
|
|
||||||
|
// Draw the image into the context and retrieve the new bitmap image without alpha
|
||||||
|
CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef);
|
||||||
|
CGImageRef imageRefWithoutAlpha = CGBitmapContextCreateImage(context);
|
||||||
|
UIImage *imageWithoutAlpha = [UIImage imageWithCGImage:imageRefWithoutAlpha
|
||||||
|
scale:image.scale
|
||||||
|
orientation:image.imageOrientation];
|
||||||
|
|
||||||
|
if (unsupportedColorSpace) {
|
||||||
|
CGColorSpaceRelease(colorspaceRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
CGContextRelease(context);
|
||||||
|
CGImageRelease(imageRefWithoutAlpha);
|
||||||
|
|
||||||
|
return imageWithoutAlpha;
|
||||||
}
|
}
|
||||||
// Some PNGs tell us they have alpha but only 3 components. Odd.
|
|
||||||
else if (!anyNonAlpha && CGColorSpaceGetNumberOfComponents(colorSpace) == 3)
|
|
||||||
{
|
|
||||||
// Unset the old alpha info.
|
|
||||||
bitmapInfo &= ~kCGBitmapAlphaInfoMask;
|
|
||||||
bitmapInfo |= kCGImageAlphaPremultipliedFirst;
|
|
||||||
}
|
|
||||||
|
|
||||||
// It calculates the bytes-per-row based on the bitsPerComponent and width arguments.
|
|
||||||
CGContextRef context = CGBitmapContextCreate(NULL,
|
|
||||||
imageSize.width,
|
|
||||||
imageSize.height,
|
|
||||||
CGImageGetBitsPerComponent(imageRef),
|
|
||||||
0,
|
|
||||||
colorSpace,
|
|
||||||
bitmapInfo);
|
|
||||||
CGColorSpaceRelease(colorSpace);
|
|
||||||
|
|
||||||
// If failed, return undecompressed image
|
|
||||||
if (!context) return image;
|
|
||||||
|
|
||||||
CGContextDrawImage(context, imageRect, imageRef);
|
|
||||||
CGImageRef decompressedImageRef = CGBitmapContextCreateImage(context);
|
|
||||||
|
|
||||||
CGContextRelease(context);
|
|
||||||
|
|
||||||
UIImage *decompressedImage = [UIImage imageWithCGImage:decompressedImageRef scale:image.scale orientation:image.imageOrientation];
|
|
||||||
CGImageRelease(decompressedImageRef);
|
|
||||||
return decompressedImage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -10,54 +10,128 @@
|
||||||
#import "SDWebImageCompat.h"
|
#import "SDWebImageCompat.h"
|
||||||
#import "SDWebImageOperation.h"
|
#import "SDWebImageOperation.h"
|
||||||
|
|
||||||
typedef enum
|
typedef NS_OPTIONS(NSUInteger, SDWebImageDownloaderOptions) {
|
||||||
{
|
|
||||||
SDWebImageDownloaderLowPriority = 1 << 0,
|
SDWebImageDownloaderLowPriority = 1 << 0,
|
||||||
SDWebImageDownloaderProgressiveDownload = 1 << 1,
|
SDWebImageDownloaderProgressiveDownload = 1 << 1,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* By default, request prevent the of NSURLCache. With this flag, NSURLCache
|
* By default, request prevent the use of NSURLCache. With this flag, NSURLCache
|
||||||
* is used with default policies.
|
* is used with default policies.
|
||||||
*/
|
*/
|
||||||
SDWebImageDownloaderUseNSURLCache = 1 << 2,
|
SDWebImageDownloaderUseNSURLCache = 1 << 2,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call completion block with nil image/imageData if the image was read from NSURLCache
|
* Call completion block with nil image/imageData if the image was read from NSURLCache
|
||||||
* (to be combined with `SDWebImageDownloaderUseNSURLCache`).
|
* (to be combined with `SDWebImageDownloaderUseNSURLCache`).
|
||||||
*/
|
*/
|
||||||
SDWebImageDownloaderIgnoreCachedResponse = 1 << 3
|
|
||||||
} SDWebImageDownloaderOptions;
|
|
||||||
|
|
||||||
typedef enum
|
SDWebImageDownloaderIgnoreCachedResponse = 1 << 3,
|
||||||
{
|
/**
|
||||||
SDWebImageDownloaderFIFOExecutionOrder,
|
* In iOS 4+, continue the download of the image if the app goes to background. This is achieved by asking the system for
|
||||||
|
* extra time in background to let the request finish. If the background task expires the operation will be cancelled.
|
||||||
|
*/
|
||||||
|
|
||||||
|
SDWebImageDownloaderContinueInBackground = 1 << 4,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles cookies stored in NSHTTPCookieStore by setting
|
||||||
|
* NSMutableURLRequest.HTTPShouldHandleCookies = YES;
|
||||||
|
*/
|
||||||
|
SDWebImageDownloaderHandleCookies = 1 << 5,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable to allow untrusted SSL certificates.
|
||||||
|
* Useful for testing purposes. Use with caution in production.
|
||||||
|
*/
|
||||||
|
SDWebImageDownloaderAllowInvalidSSLCertificates = 1 << 6,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put the image in the high priority queue.
|
||||||
|
*/
|
||||||
|
SDWebImageDownloaderHighPriority = 1 << 7,
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef NS_ENUM(NSInteger, SDWebImageDownloaderExecutionOrder) {
|
||||||
/**
|
/**
|
||||||
* Default value. All download operations will execute in queue style (first-in-first-out).
|
* Default value. All download operations will execute in queue style (first-in-first-out).
|
||||||
*/
|
*/
|
||||||
SDWebImageDownloaderLIFOExecutionOrder
|
SDWebImageDownloaderFIFOExecutionOrder,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All download operations will execute in stack style (last-in-first-out).
|
* All download operations will execute in stack style (last-in-first-out).
|
||||||
*/
|
*/
|
||||||
} SDWebImageDownloaderExecutionOrder;
|
SDWebImageDownloaderLIFOExecutionOrder
|
||||||
|
};
|
||||||
|
|
||||||
extern NSString *const SDWebImageDownloadStartNotification;
|
extern NSString *const SDWebImageDownloadStartNotification;
|
||||||
extern NSString *const SDWebImageDownloadStopNotification;
|
extern NSString *const SDWebImageDownloadStopNotification;
|
||||||
|
|
||||||
typedef void(^SDWebImageDownloaderProgressBlock)(NSUInteger receivedSize, long long expectedSize);
|
typedef void(^SDWebImageDownloaderProgressBlock)(NSInteger receivedSize, NSInteger expectedSize);
|
||||||
|
|
||||||
typedef void(^SDWebImageDownloaderCompletedBlock)(UIImage *image, NSData *data, NSError *error, BOOL finished);
|
typedef void(^SDWebImageDownloaderCompletedBlock)(UIImage *image, NSData *data, NSError *error, BOOL finished);
|
||||||
|
|
||||||
|
typedef NSDictionary *(^SDWebImageDownloaderHeadersFilterBlock)(NSURL *url, NSDictionary *headers);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asynchronous downloader dedicated and optimized for image loading.
|
* Asynchronous downloader dedicated and optimized for image loading.
|
||||||
*/
|
*/
|
||||||
@interface SDWebImageDownloader : NSObject
|
@interface SDWebImageDownloader : NSObject
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decompressing images that are downloaded and cached can improve performance but can consume lot of memory.
|
||||||
|
* Defaults to YES. Set this to NO if you are experiencing a crash due to excessive memory consumption.
|
||||||
|
*/
|
||||||
|
@property (assign, nonatomic) BOOL shouldDecompressImages;
|
||||||
|
|
||||||
@property (assign, nonatomic) NSInteger maxConcurrentDownloads;
|
@property (assign, nonatomic) NSInteger maxConcurrentDownloads;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows the current amount of downloads that still need to be downloaded
|
||||||
|
*/
|
||||||
|
@property (readonly, nonatomic) NSUInteger currentDownloadCount;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The timeout value (in seconds) for the download operation. Default: 15.0.
|
||||||
|
*/
|
||||||
|
@property (assign, nonatomic) NSTimeInterval downloadTimeout;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Changes download operations execution order. Default value is `SDWebImageDownloaderFIFOExecutionOrder`.
|
* Changes download operations execution order. Default value is `SDWebImageDownloaderFIFOExecutionOrder`.
|
||||||
*/
|
*/
|
||||||
@property (assign, nonatomic) SDWebImageDownloaderExecutionOrder executionOrder;
|
@property (assign, nonatomic) SDWebImageDownloaderExecutionOrder executionOrder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Singleton method, returns the shared instance
|
||||||
|
*
|
||||||
|
* @return global shared instance of downloader class
|
||||||
|
*/
|
||||||
+ (SDWebImageDownloader *)sharedDownloader;
|
+ (SDWebImageDownloader *)sharedDownloader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the default URL credential to be set for request operations.
|
||||||
|
*/
|
||||||
|
@property (strong, nonatomic) NSURLCredential *urlCredential;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set username
|
||||||
|
*/
|
||||||
|
@property (strong, nonatomic) NSString *username;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set password
|
||||||
|
*/
|
||||||
|
@property (strong, nonatomic) NSString *password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set filter to pick headers for downloading image HTTP request.
|
||||||
|
*
|
||||||
|
* This block will be invoked for each downloading image request, returned
|
||||||
|
* NSDictionary will be used as headers in corresponding HTTP request.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, copy) SDWebImageDownloaderHeadersFilterBlock headersFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a value for a HTTP header to be appended to each download HTTP request.
|
* Set a value for a HTTP header to be appended to each download HTTP request.
|
||||||
*
|
*
|
||||||
|
|
@ -73,6 +147,16 @@ typedef void(^SDWebImageDownloaderCompletedBlock)(UIImage *image, NSData *data,
|
||||||
*/
|
*/
|
||||||
- (NSString *)valueForHTTPHeaderField:(NSString *)field;
|
- (NSString *)valueForHTTPHeaderField:(NSString *)field;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a subclass of `SDWebImageDownloaderOperation` as the default
|
||||||
|
* `NSOperation` to be used each time SDWebImage constructs a request
|
||||||
|
* operation to download an image.
|
||||||
|
*
|
||||||
|
* @param operationClass The subclass of `SDWebImageDownloaderOperation` to set
|
||||||
|
* as default. Passing `nil` will revert to `SDWebImageDownloaderOperation`.
|
||||||
|
*/
|
||||||
|
- (void)setOperationClass:(Class)operationClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a SDWebImageDownloader async downloader instance with a given URL
|
* Creates a SDWebImageDownloader async downloader instance with a given URL
|
||||||
*
|
*
|
||||||
|
|
@ -80,23 +164,33 @@ typedef void(^SDWebImageDownloaderCompletedBlock)(UIImage *image, NSData *data,
|
||||||
*
|
*
|
||||||
* @see SDWebImageDownloaderDelegate
|
* @see SDWebImageDownloaderDelegate
|
||||||
*
|
*
|
||||||
* @param url The URL to the image to download
|
* @param url The URL to the image to download
|
||||||
* @param options The options to be used for this download
|
* @param options The options to be used for this download
|
||||||
* @param progressBlock A block called repeatedly while the image is downloading
|
* @param progressBlock A block called repeatedly while the image is downloading
|
||||||
* @param completedBlock A block called once the download is completed.
|
* @param completedBlock A block called once the download is completed.
|
||||||
* If the download succeeded, the image parameter is set, in case of error,
|
* If the download succeeded, the image parameter is set, in case of error,
|
||||||
* error parameter is set with the error. The last parameter is always YES
|
* error parameter is set with the error. The last parameter is always YES
|
||||||
* if SDWebImageDownloaderProgressiveDownload isn't use. With the
|
* if SDWebImageDownloaderProgressiveDownload isn't use. With the
|
||||||
* SDWebImageDownloaderProgressiveDownload option, this block is called
|
* SDWebImageDownloaderProgressiveDownload option, this block is called
|
||||||
* repeatedly with the partial image object and the finished argument set to NO
|
* repeatedly with the partial image object and the finished argument set to NO
|
||||||
* before to be called a last time with the full image and finished argument
|
* before to be called a last time with the full image and finished argument
|
||||||
* set to YES. In case of error, the finished argument is always YES.
|
* set to YES. In case of error, the finished argument is always YES.
|
||||||
*
|
*
|
||||||
* @return A cancellable SDWebImageOperation
|
* @return A cancellable SDWebImageOperation
|
||||||
*/
|
*/
|
||||||
- (id<SDWebImageOperation>)downloadImageWithURL:(NSURL *)url
|
- (id <SDWebImageOperation>)downloadImageWithURL:(NSURL *)url
|
||||||
options:(SDWebImageDownloaderOptions)options
|
options:(SDWebImageDownloaderOptions)options
|
||||||
progress:(SDWebImageDownloaderProgressBlock)progressBlock
|
progress:(SDWebImageDownloaderProgressBlock)progressBlock
|
||||||
completed:(SDWebImageDownloaderCompletedBlock)completedBlock;
|
completed:(SDWebImageDownloaderCompletedBlock)completedBlock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the download queue suspension state
|
||||||
|
*/
|
||||||
|
- (void)setSuspended:(BOOL)suspended;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancels all download operations in the queue
|
||||||
|
*/
|
||||||
|
- (void)cancelAllDownloads;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -10,31 +10,30 @@
|
||||||
#import "SDWebImageDownloaderOperation.h"
|
#import "SDWebImageDownloaderOperation.h"
|
||||||
#import <ImageIO/ImageIO.h>
|
#import <ImageIO/ImageIO.h>
|
||||||
|
|
||||||
NSString *const SDWebImageDownloadStartNotification = @"SDWebImageDownloadStartNotification";
|
|
||||||
NSString *const SDWebImageDownloadStopNotification = @"SDWebImageDownloadStopNotification";
|
|
||||||
|
|
||||||
static NSString *const kProgressCallbackKey = @"progress";
|
static NSString *const kProgressCallbackKey = @"progress";
|
||||||
static NSString *const kCompletedCallbackKey = @"completed";
|
static NSString *const kCompletedCallbackKey = @"completed";
|
||||||
|
|
||||||
@interface SDWebImageDownloader ()
|
@interface SDWebImageDownloader () <NSURLSessionTaskDelegate, NSURLSessionDataDelegate>
|
||||||
|
|
||||||
@property (strong, nonatomic) NSOperationQueue *downloadQueue;
|
@property (strong, nonatomic) NSOperationQueue *downloadQueue;
|
||||||
@property (weak, nonatomic) NSOperation *lastAddedOperation;
|
@property (weak, nonatomic) NSOperation *lastAddedOperation;
|
||||||
|
@property (assign, nonatomic) Class operationClass;
|
||||||
@property (strong, nonatomic) NSMutableDictionary *URLCallbacks;
|
@property (strong, nonatomic) NSMutableDictionary *URLCallbacks;
|
||||||
@property (strong, nonatomic) NSMutableDictionary *HTTPHeaders;
|
@property (strong, nonatomic) NSMutableDictionary *HTTPHeaders;
|
||||||
// This queue is used to serialize the handling of the network responses of all the download operation in a single queue
|
// This queue is used to serialize the handling of the network responses of all the download operation in a single queue
|
||||||
@property (SDDispatchQueueSetterSementics, nonatomic) dispatch_queue_t barrierQueue;
|
@property (SDDispatchQueueSetterSementics, nonatomic) dispatch_queue_t barrierQueue;
|
||||||
|
|
||||||
|
// The session in which data tasks will run
|
||||||
|
@property (strong, nonatomic) NSURLSession *session;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation SDWebImageDownloader
|
@implementation SDWebImageDownloader
|
||||||
|
|
||||||
+ (void)initialize
|
+ (void)initialize {
|
||||||
{
|
|
||||||
// Bind SDNetworkActivityIndicator if available (download it here: http://github.com/rs/SDNetworkActivityIndicator )
|
// Bind SDNetworkActivityIndicator if available (download it here: http://github.com/rs/SDNetworkActivityIndicator )
|
||||||
// To use it, just add #import "SDNetworkActivityIndicator.h" in addition to the SDWebImage import
|
// To use it, just add #import "SDNetworkActivityIndicator.h" in addition to the SDWebImage import
|
||||||
if (NSClassFromString(@"SDNetworkActivityIndicator"))
|
if (NSClassFromString(@"SDNetworkActivityIndicator")) {
|
||||||
{
|
|
||||||
|
|
||||||
#pragma clang diagnostic push
|
#pragma clang diagnostic push
|
||||||
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
|
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
|
||||||
|
|
@ -54,109 +53,158 @@ static NSString *const kCompletedCallbackKey = @"completed";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (SDWebImageDownloader *)sharedDownloader
|
+ (SDWebImageDownloader *)sharedDownloader {
|
||||||
{
|
|
||||||
static dispatch_once_t once;
|
static dispatch_once_t once;
|
||||||
static id instance;
|
static id instance;
|
||||||
dispatch_once(&once, ^{instance = self.new;});
|
dispatch_once(&once, ^{
|
||||||
|
instance = [self new];
|
||||||
|
});
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)init
|
- (id)init {
|
||||||
{
|
if ((self = [super init])) {
|
||||||
if ((self = [super init]))
|
_operationClass = [SDWebImageDownloaderOperation class];
|
||||||
{
|
_shouldDecompressImages = YES;
|
||||||
_executionOrder = SDWebImageDownloaderFIFOExecutionOrder;
|
_executionOrder = SDWebImageDownloaderFIFOExecutionOrder;
|
||||||
_downloadQueue = NSOperationQueue.new;
|
_downloadQueue = [NSOperationQueue new];
|
||||||
_downloadQueue.maxConcurrentOperationCount = 2;
|
_downloadQueue.maxConcurrentOperationCount = 6;
|
||||||
_URLCallbacks = NSMutableDictionary.new;
|
_URLCallbacks = [NSMutableDictionary new];
|
||||||
_HTTPHeaders = [NSMutableDictionary dictionaryWithObject:@"image/webp,image/*;q=0.8" forKey:@"Accept"];
|
#ifdef SD_WEBP
|
||||||
|
_HTTPHeaders = [@{@"Accept": @"image/webp,image/*;q=0.8"} mutableCopy];
|
||||||
|
#else
|
||||||
|
_HTTPHeaders = [@{@"Accept": @"image/*;q=0.8"} mutableCopy];
|
||||||
|
#endif
|
||||||
_barrierQueue = dispatch_queue_create("com.hackemist.SDWebImageDownloaderBarrierQueue", DISPATCH_QUEUE_CONCURRENT);
|
_barrierQueue = dispatch_queue_create("com.hackemist.SDWebImageDownloaderBarrierQueue", DISPATCH_QUEUE_CONCURRENT);
|
||||||
|
_downloadTimeout = 15.0;
|
||||||
|
|
||||||
|
NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration];
|
||||||
|
sessionConfig.timeoutIntervalForRequest = _downloadTimeout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the session for this task
|
||||||
|
* We send nil as delegate queue so that the session creates a serial operation queue for performing all delegate
|
||||||
|
* method calls and completion handler calls.
|
||||||
|
*/
|
||||||
|
self.session = [NSURLSession sessionWithConfiguration:sessionConfig
|
||||||
|
delegate:self
|
||||||
|
delegateQueue:nil];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc {
|
||||||
{
|
[self.session invalidateAndCancel];
|
||||||
|
self.session = nil;
|
||||||
|
|
||||||
[self.downloadQueue cancelAllOperations];
|
[self.downloadQueue cancelAllOperations];
|
||||||
SDDispatchQueueRelease(_barrierQueue);
|
SDDispatchQueueRelease(_barrierQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field
|
- (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field {
|
||||||
{
|
if (value) {
|
||||||
if (value)
|
|
||||||
{
|
|
||||||
self.HTTPHeaders[field] = value;
|
self.HTTPHeaders[field] = value;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
[self.HTTPHeaders removeObjectForKey:field];
|
[self.HTTPHeaders removeObjectForKey:field];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *)valueForHTTPHeaderField:(NSString *)field
|
- (NSString *)valueForHTTPHeaderField:(NSString *)field {
|
||||||
{
|
|
||||||
return self.HTTPHeaders[field];
|
return self.HTTPHeaders[field];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setMaxConcurrentDownloads:(NSInteger)maxConcurrentDownloads
|
- (void)setMaxConcurrentDownloads:(NSInteger)maxConcurrentDownloads {
|
||||||
{
|
|
||||||
_downloadQueue.maxConcurrentOperationCount = maxConcurrentDownloads;
|
_downloadQueue.maxConcurrentOperationCount = maxConcurrentDownloads;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSInteger)maxConcurrentDownloads
|
- (NSUInteger)currentDownloadCount {
|
||||||
{
|
return _downloadQueue.operationCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSInteger)maxConcurrentDownloads {
|
||||||
return _downloadQueue.maxConcurrentOperationCount;
|
return _downloadQueue.maxConcurrentOperationCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id<SDWebImageOperation>)downloadImageWithURL:(NSURL *)url options:(SDWebImageDownloaderOptions)options progress:(void (^)(NSUInteger, long long))progressBlock completed:(void (^)(UIImage *, NSData *, NSError *, BOOL))completedBlock
|
- (void)setOperationClass:(Class)operationClass {
|
||||||
{
|
_operationClass = operationClass ?: [SDWebImageDownloaderOperation class];
|
||||||
__block SDWebImageDownloaderOperation *operation;
|
}
|
||||||
__weak SDWebImageDownloader *wself = self;
|
|
||||||
|
- (id <SDWebImageOperation>)downloadImageWithURL:(NSURL *)url options:(SDWebImageDownloaderOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageDownloaderCompletedBlock)completedBlock {
|
||||||
|
__block SDWebImageDownloaderOperation *operation;
|
||||||
|
__weak __typeof(self)wself = self;
|
||||||
|
|
||||||
|
[self addProgressCallback:progressBlock completedBlock:completedBlock forURL:url createCallback:^{
|
||||||
|
NSTimeInterval timeoutInterval = wself.downloadTimeout;
|
||||||
|
if (timeoutInterval == 0.0) {
|
||||||
|
timeoutInterval = 15.0;
|
||||||
|
}
|
||||||
|
|
||||||
[self addProgressCallback:progressBlock andCompletedBlock:completedBlock forURL:url createCallback:^
|
|
||||||
{
|
|
||||||
// In order to prevent from potential duplicate caching (NSURLCache + SDImageCache) we disable the cache for image requests if told otherwise
|
// In order to prevent from potential duplicate caching (NSURLCache + SDImageCache) we disable the cache for image requests if told otherwise
|
||||||
NSMutableURLRequest *request = [NSMutableURLRequest.alloc initWithURL:url cachePolicy:(options & SDWebImageDownloaderUseNSURLCache ? NSURLRequestUseProtocolCachePolicy : NSURLRequestReloadIgnoringLocalCacheData) timeoutInterval:15];
|
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:(options & SDWebImageDownloaderUseNSURLCache ? NSURLRequestUseProtocolCachePolicy : NSURLRequestReloadIgnoringLocalCacheData) timeoutInterval:timeoutInterval];
|
||||||
request.HTTPShouldHandleCookies = NO;
|
request.HTTPShouldHandleCookies = (options & SDWebImageDownloaderHandleCookies);
|
||||||
request.HTTPShouldUsePipelining = YES;
|
request.HTTPShouldUsePipelining = YES;
|
||||||
request.allHTTPHeaderFields = wself.HTTPHeaders;
|
if (wself.headersFilter) {
|
||||||
operation = [SDWebImageDownloaderOperation.alloc initWithRequest:request options:options progress:^(NSUInteger receivedSize, long long expectedSize)
|
request.allHTTPHeaderFields = wself.headersFilter(url, [wself.HTTPHeaders copy]);
|
||||||
{
|
|
||||||
if (!wself) return;
|
|
||||||
SDWebImageDownloader *sself = wself;
|
|
||||||
NSArray *callbacksForURL = [sself callbacksForURL:url];
|
|
||||||
for (NSDictionary *callbacks in callbacksForURL)
|
|
||||||
{
|
|
||||||
SDWebImageDownloaderProgressBlock callback = callbacks[kProgressCallbackKey];
|
|
||||||
if (callback) callback(receivedSize, expectedSize);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished)
|
else {
|
||||||
{
|
request.allHTTPHeaderFields = wself.HTTPHeaders;
|
||||||
if (!wself) return;
|
|
||||||
SDWebImageDownloader *sself = wself;
|
|
||||||
NSArray *callbacksForURL = [sself callbacksForURL:url];
|
|
||||||
if (finished)
|
|
||||||
{
|
|
||||||
[sself removeCallbacksForURL:url];
|
|
||||||
}
|
|
||||||
for (NSDictionary *callbacks in callbacksForURL)
|
|
||||||
{
|
|
||||||
SDWebImageDownloaderCompletedBlock callback = callbacks[kCompletedCallbackKey];
|
|
||||||
if (callback) callback(image, data, error, finished);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
cancelled:^
|
operation = [[wself.operationClass alloc] initWithRequest:request
|
||||||
{
|
inSession:self.session
|
||||||
if (!wself) return;
|
options:options
|
||||||
SDWebImageDownloader *sself = wself;
|
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
|
||||||
[sself callbacksForURL:url];
|
SDWebImageDownloader *sself = wself;
|
||||||
[sself removeCallbacksForURL:url];
|
if (!sself) return;
|
||||||
}];
|
__block NSArray *callbacksForURL;
|
||||||
|
dispatch_sync(sself.barrierQueue, ^{
|
||||||
|
callbacksForURL = [sself.URLCallbacks[url] copy];
|
||||||
|
});
|
||||||
|
for (NSDictionary *callbacks in callbacksForURL) {
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
SDWebImageDownloaderProgressBlock callback = callbacks[kProgressCallbackKey];
|
||||||
|
if (callback) callback(receivedSize, expectedSize);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
|
||||||
|
SDWebImageDownloader *sself = wself;
|
||||||
|
if (!sself) return;
|
||||||
|
__block NSArray *callbacksForURL;
|
||||||
|
dispatch_barrier_sync(sself.barrierQueue, ^{
|
||||||
|
callbacksForURL = [sself.URLCallbacks[url] copy];
|
||||||
|
if (finished) {
|
||||||
|
[sself.URLCallbacks removeObjectForKey:url];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
for (NSDictionary *callbacks in callbacksForURL) {
|
||||||
|
SDWebImageDownloaderCompletedBlock callback = callbacks[kCompletedCallbackKey];
|
||||||
|
if (callback) callback(image, data, error, finished);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cancelled:^{
|
||||||
|
SDWebImageDownloader *sself = wself;
|
||||||
|
if (!sself) return;
|
||||||
|
dispatch_barrier_async(sself.barrierQueue, ^{
|
||||||
|
[sself.URLCallbacks removeObjectForKey:url];
|
||||||
|
});
|
||||||
|
}];
|
||||||
|
operation.shouldDecompressImages = wself.shouldDecompressImages;
|
||||||
|
|
||||||
|
if (wself.urlCredential) {
|
||||||
|
operation.credential = wself.urlCredential;
|
||||||
|
} else if (wself.username && wself.password) {
|
||||||
|
operation.credential = [NSURLCredential credentialWithUser:wself.username password:wself.password persistence:NSURLCredentialPersistenceForSession];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options & SDWebImageDownloaderHighPriority) {
|
||||||
|
operation.queuePriority = NSOperationQueuePriorityHigh;
|
||||||
|
} else if (options & SDWebImageDownloaderLowPriority) {
|
||||||
|
operation.queuePriority = NSOperationQueuePriorityLow;
|
||||||
|
}
|
||||||
|
|
||||||
[wself.downloadQueue addOperation:operation];
|
[wself.downloadQueue addOperation:operation];
|
||||||
if (wself.executionOrder == SDWebImageDownloaderLIFOExecutionOrder)
|
if (wself.executionOrder == SDWebImageDownloaderLIFOExecutionOrder) {
|
||||||
{
|
|
||||||
// Emulate LIFO execution order by systematically adding new operations as last operation's dependency
|
// Emulate LIFO execution order by systematically adding new operations as last operation's dependency
|
||||||
[wself.lastAddedOperation addDependency:operation];
|
[wself.lastAddedOperation addDependency:operation];
|
||||||
wself.lastAddedOperation = operation;
|
wself.lastAddedOperation = operation;
|
||||||
|
|
@ -166,58 +214,104 @@ static NSString *const kCompletedCallbackKey = @"completed";
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)addProgressCallback:(void (^)(NSUInteger, long long))progressBlock andCompletedBlock:(void (^)(UIImage *, NSData *data, NSError *, BOOL))completedBlock forURL:(NSURL *)url createCallback:(void (^)())createCallback
|
- (void)addProgressCallback:(SDWebImageDownloaderProgressBlock)progressBlock completedBlock:(SDWebImageDownloaderCompletedBlock)completedBlock forURL:(NSURL *)url createCallback:(SDWebImageNoParamsBlock)createCallback {
|
||||||
{
|
|
||||||
// The URL will be used as the key to the callbacks dictionary so it cannot be nil. If it is nil immediately call the completed block with no image or data.
|
// The URL will be used as the key to the callbacks dictionary so it cannot be nil. If it is nil immediately call the completed block with no image or data.
|
||||||
if(url == nil)
|
if (url == nil) {
|
||||||
{
|
if (completedBlock != nil) {
|
||||||
if (completedBlock != nil)
|
|
||||||
{
|
|
||||||
completedBlock(nil, nil, nil, NO);
|
completedBlock(nil, nil, nil, NO);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch_barrier_sync(self.barrierQueue, ^
|
dispatch_barrier_sync(self.barrierQueue, ^{
|
||||||
{
|
|
||||||
BOOL first = NO;
|
BOOL first = NO;
|
||||||
if (!self.URLCallbacks[url])
|
if (!self.URLCallbacks[url]) {
|
||||||
{
|
self.URLCallbacks[url] = [NSMutableArray new];
|
||||||
self.URLCallbacks[url] = NSMutableArray.new;
|
|
||||||
first = YES;
|
first = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle single download of simultaneous download request for the same URL
|
// Handle single download of simultaneous download request for the same URL
|
||||||
NSMutableArray *callbacksForURL = self.URLCallbacks[url];
|
NSMutableArray *callbacksForURL = self.URLCallbacks[url];
|
||||||
NSMutableDictionary *callbacks = NSMutableDictionary.new;
|
NSMutableDictionary *callbacks = [NSMutableDictionary new];
|
||||||
if (progressBlock) callbacks[kProgressCallbackKey] = [progressBlock copy];
|
if (progressBlock) callbacks[kProgressCallbackKey] = [progressBlock copy];
|
||||||
if (completedBlock) callbacks[kCompletedCallbackKey] = [completedBlock copy];
|
if (completedBlock) callbacks[kCompletedCallbackKey] = [completedBlock copy];
|
||||||
[callbacksForURL addObject:callbacks];
|
[callbacksForURL addObject:callbacks];
|
||||||
self.URLCallbacks[url] = callbacksForURL;
|
self.URLCallbacks[url] = callbacksForURL;
|
||||||
|
|
||||||
if (first)
|
if (first) {
|
||||||
{
|
|
||||||
createCallback();
|
createCallback();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray *)callbacksForURL:(NSURL *)url
|
- (void)setSuspended:(BOOL)suspended {
|
||||||
{
|
[self.downloadQueue setSuspended:suspended];
|
||||||
__block NSArray *callbacksForURL;
|
|
||||||
dispatch_sync(self.barrierQueue, ^
|
|
||||||
{
|
|
||||||
callbacksForURL = self.URLCallbacks[url];
|
|
||||||
});
|
|
||||||
return callbacksForURL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)removeCallbacksForURL:(NSURL *)url
|
- (void)cancelAllDownloads {
|
||||||
{
|
[self.downloadQueue cancelAllOperations];
|
||||||
dispatch_barrier_async(self.barrierQueue, ^
|
}
|
||||||
{
|
|
||||||
[self.URLCallbacks removeObjectForKey:url];
|
#pragma mark Helper methods
|
||||||
});
|
|
||||||
|
- (SDWebImageDownloaderOperation *)operationWithTask:(NSURLSessionTask *)task {
|
||||||
|
SDWebImageDownloaderOperation *returnOperation = nil;
|
||||||
|
for (SDWebImageDownloaderOperation *operation in self.downloadQueue.operations) {
|
||||||
|
if (operation.dataTask.taskIdentifier == task.taskIdentifier) {
|
||||||
|
returnOperation = operation;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return returnOperation;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark NSURLSessionDataDelegate
|
||||||
|
|
||||||
|
- (void)URLSession:(NSURLSession *)session
|
||||||
|
dataTask:(NSURLSessionDataTask *)dataTask
|
||||||
|
didReceiveResponse:(NSURLResponse *)response
|
||||||
|
completionHandler:(void (^)(NSURLSessionResponseDisposition disposition))completionHandler {
|
||||||
|
|
||||||
|
// Identify the operation that runs this task and pass it the delegate method
|
||||||
|
SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:dataTask];
|
||||||
|
|
||||||
|
[dataOperation URLSession:session dataTask:dataTask didReceiveResponse:response completionHandler:completionHandler];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data {
|
||||||
|
|
||||||
|
// Identify the operation that runs this task and pass it the delegate method
|
||||||
|
SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:dataTask];
|
||||||
|
|
||||||
|
[dataOperation URLSession:session dataTask:dataTask didReceiveData:data];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)URLSession:(NSURLSession *)session
|
||||||
|
dataTask:(NSURLSessionDataTask *)dataTask
|
||||||
|
willCacheResponse:(NSCachedURLResponse *)proposedResponse
|
||||||
|
completionHandler:(void (^)(NSCachedURLResponse *cachedResponse))completionHandler {
|
||||||
|
|
||||||
|
// Identify the operation that runs this task and pass it the delegate method
|
||||||
|
SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:dataTask];
|
||||||
|
|
||||||
|
[dataOperation URLSession:session dataTask:dataTask willCacheResponse:proposedResponse completionHandler:completionHandler];
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark NSURLSessionTaskDelegate
|
||||||
|
|
||||||
|
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
|
||||||
|
// Identify the operation that runs this task and pass it the delegate method
|
||||||
|
SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:task];
|
||||||
|
|
||||||
|
[dataOperation URLSession:session task:task didCompleteWithError:error];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler {
|
||||||
|
|
||||||
|
// Identify the operation that runs this task and pass it the delegate method
|
||||||
|
SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:task];
|
||||||
|
|
||||||
|
[dataOperation URLSession:session task:task didReceiveChallenge:challenge completionHandler:completionHandler];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -10,15 +10,97 @@
|
||||||
#import "SDWebImageDownloader.h"
|
#import "SDWebImageDownloader.h"
|
||||||
#import "SDWebImageOperation.h"
|
#import "SDWebImageOperation.h"
|
||||||
|
|
||||||
@interface SDWebImageDownloaderOperation : NSOperation <SDWebImageOperation>
|
extern NSString *const SDWebImageDownloadStartNotification;
|
||||||
|
extern NSString *const SDWebImageDownloadReceiveResponseNotification;
|
||||||
|
extern NSString *const SDWebImageDownloadStopNotification;
|
||||||
|
extern NSString *const SDWebImageDownloadFinishNotification;
|
||||||
|
|
||||||
|
@interface SDWebImageDownloaderOperation : NSOperation <SDWebImageOperation, NSURLSessionTaskDelegate, NSURLSessionDataDelegate>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The request used by the operation's task.
|
||||||
|
*/
|
||||||
@property (strong, nonatomic, readonly) NSURLRequest *request;
|
@property (strong, nonatomic, readonly) NSURLRequest *request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The operation's task
|
||||||
|
*/
|
||||||
|
@property (strong, nonatomic, readonly) NSURLSessionTask *dataTask;
|
||||||
|
|
||||||
|
|
||||||
|
@property (assign, nonatomic) BOOL shouldDecompressImages;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Was used to determine whether the URL connection should consult the credential storage for authenticating the connection.
|
||||||
|
* @deprecated Not used for a couple of versions
|
||||||
|
*/
|
||||||
|
@property (nonatomic, assign) BOOL shouldUseCredentialStorage __deprecated_msg("Property deprecated. Does nothing. Kept only for backwards compatibility");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The credential used for authentication challenges in `-connection:didReceiveAuthenticationChallenge:`.
|
||||||
|
*
|
||||||
|
* This will be overridden by any shared credentials that exist for the username or password of the request URL, if present.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, strong) NSURLCredential *credential;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The SDWebImageDownloaderOptions for the receiver.
|
||||||
|
*/
|
||||||
@property (assign, nonatomic, readonly) SDWebImageDownloaderOptions options;
|
@property (assign, nonatomic, readonly) SDWebImageDownloaderOptions options;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The expected size of data.
|
||||||
|
*/
|
||||||
|
@property (assign, nonatomic) NSInteger expectedSize;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The response returned by the operation's connection.
|
||||||
|
*/
|
||||||
|
@property (strong, nonatomic) NSURLResponse *response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes a `SDWebImageDownloaderOperation` object
|
||||||
|
*
|
||||||
|
* @see SDWebImageDownloaderOperation
|
||||||
|
*
|
||||||
|
* @param request the URL request
|
||||||
|
* @param session the URL session in which this operation will run
|
||||||
|
* @param options downloader options
|
||||||
|
* @param progressBlock the block executed when a new chunk of data arrives.
|
||||||
|
* @note the progress block is executed on a background queue
|
||||||
|
* @param completedBlock the block executed when the download is done.
|
||||||
|
* @note the completed block is executed on the main queue for success. If errors are found, there is a chance the block will be executed on a background queue
|
||||||
|
* @param cancelBlock the block executed if the download (operation) is cancelled
|
||||||
|
*
|
||||||
|
* @return the initialized instance
|
||||||
|
*/
|
||||||
|
- (id)initWithRequest:(NSURLRequest *)request
|
||||||
|
inSession:(NSURLSession *)session
|
||||||
|
options:(SDWebImageDownloaderOptions)options
|
||||||
|
progress:(SDWebImageDownloaderProgressBlock)progressBlock
|
||||||
|
completed:(SDWebImageDownloaderCompletedBlock)completedBlock
|
||||||
|
cancelled:(SDWebImageNoParamsBlock)cancelBlock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes a `SDWebImageDownloaderOperation` object
|
||||||
|
*
|
||||||
|
* @see SDWebImageDownloaderOperation
|
||||||
|
*
|
||||||
|
* @param request the URL request
|
||||||
|
* @param options downloader options
|
||||||
|
* @param progressBlock the block executed when a new chunk of data arrives.
|
||||||
|
* @note the progress block is executed on a background queue
|
||||||
|
* @param completedBlock the block executed when the download is done.
|
||||||
|
* @note the completed block is executed on the main queue for success. If errors are found, there is a chance the block will be executed on a background queue
|
||||||
|
* @param cancelBlock the block executed if the download (operation) is cancelled
|
||||||
|
*
|
||||||
|
* @return the initialized instance. The operation will run in a separate session created for this operation
|
||||||
|
*/
|
||||||
- (id)initWithRequest:(NSURLRequest *)request
|
- (id)initWithRequest:(NSURLRequest *)request
|
||||||
options:(SDWebImageDownloaderOptions)options
|
options:(SDWebImageDownloaderOptions)options
|
||||||
progress:(SDWebImageDownloaderProgressBlock)progressBlock
|
progress:(SDWebImageDownloaderProgressBlock)progressBlock
|
||||||
completed:(SDWebImageDownloaderCompletedBlock)completedBlock
|
completed:(SDWebImageDownloaderCompletedBlock)completedBlock
|
||||||
cancelled:(void (^)())cancelBlock;
|
cancelled:(SDWebImageNoParamsBlock)cancelBlock
|
||||||
|
__deprecated_msg("Method deprecated. Use `initWithRequest:inSession:options:progress:completed:cancelled`");
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -10,32 +10,71 @@
|
||||||
#import "SDWebImageDecoder.h"
|
#import "SDWebImageDecoder.h"
|
||||||
#import "UIImage+MultiFormat.h"
|
#import "UIImage+MultiFormat.h"
|
||||||
#import <ImageIO/ImageIO.h>
|
#import <ImageIO/ImageIO.h>
|
||||||
|
#import "SDWebImageManager.h"
|
||||||
|
|
||||||
|
NSString *const SDWebImageDownloadStartNotification = @"SDWebImageDownloadStartNotification";
|
||||||
|
NSString *const SDWebImageDownloadReceiveResponseNotification = @"SDWebImageDownloadReceiveResponseNotification";
|
||||||
|
NSString *const SDWebImageDownloadStopNotification = @"SDWebImageDownloadStopNotification";
|
||||||
|
NSString *const SDWebImageDownloadFinishNotification = @"SDWebImageDownloadFinishNotification";
|
||||||
|
|
||||||
@interface SDWebImageDownloaderOperation ()
|
@interface SDWebImageDownloaderOperation ()
|
||||||
|
|
||||||
@property (copy, nonatomic) SDWebImageDownloaderProgressBlock progressBlock;
|
@property (copy, nonatomic) SDWebImageDownloaderProgressBlock progressBlock;
|
||||||
@property (copy, nonatomic) SDWebImageDownloaderCompletedBlock completedBlock;
|
@property (copy, nonatomic) SDWebImageDownloaderCompletedBlock completedBlock;
|
||||||
@property (copy, nonatomic) void (^cancelBlock)();
|
@property (copy, nonatomic) SDWebImageNoParamsBlock cancelBlock;
|
||||||
|
|
||||||
@property (assign, nonatomic, getter = isExecuting) BOOL executing;
|
@property (assign, nonatomic, getter = isExecuting) BOOL executing;
|
||||||
@property (assign, nonatomic, getter = isFinished) BOOL finished;
|
@property (assign, nonatomic, getter = isFinished) BOOL finished;
|
||||||
@property (assign, nonatomic) long long expectedSize;
|
|
||||||
@property (strong, nonatomic) NSMutableData *imageData;
|
@property (strong, nonatomic) NSMutableData *imageData;
|
||||||
@property (strong, nonatomic) NSURLConnection *connection;
|
|
||||||
|
// This is weak because it is injected by whoever manages this session. If this gets nil-ed out, we won't be able to run
|
||||||
|
// the task associated with this operation
|
||||||
|
@property (weak, nonatomic) NSURLSession *unownedSession;
|
||||||
|
// This is set if we're using not using an injected NSURLSession. We're responsible of invalidating this one
|
||||||
|
@property (strong, nonatomic) NSURLSession *ownedSession;
|
||||||
|
|
||||||
|
@property (strong, nonatomic, readwrite) NSURLSessionTask *dataTask;
|
||||||
|
|
||||||
|
@property (strong, atomic) NSThread *thread;
|
||||||
|
|
||||||
|
#if TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
|
||||||
|
@property (assign, nonatomic) UIBackgroundTaskIdentifier backgroundTaskId;
|
||||||
|
#endif
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation SDWebImageDownloaderOperation
|
@implementation SDWebImageDownloaderOperation {
|
||||||
{
|
|
||||||
size_t width, height;
|
size_t width, height;
|
||||||
|
UIImageOrientation orientation;
|
||||||
BOOL responseFromCached;
|
BOOL responseFromCached;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithRequest:(NSURLRequest *)request options:(SDWebImageDownloaderOptions)options progress:(void (^)(NSUInteger, long long))progressBlock completed:(void (^)(UIImage *, NSData *, NSError *, BOOL))completedBlock cancelled:(void (^)())cancelBlock
|
@synthesize executing = _executing;
|
||||||
{
|
@synthesize finished = _finished;
|
||||||
if ((self = [super init]))
|
|
||||||
{
|
- (id)initWithRequest:(NSURLRequest *)request
|
||||||
|
options:(SDWebImageDownloaderOptions)options
|
||||||
|
progress:(SDWebImageDownloaderProgressBlock)progressBlock
|
||||||
|
completed:(SDWebImageDownloaderCompletedBlock)completedBlock
|
||||||
|
cancelled:(SDWebImageNoParamsBlock)cancelBlock {
|
||||||
|
|
||||||
|
return [self initWithRequest:request
|
||||||
|
inSession:nil
|
||||||
|
options:options
|
||||||
|
progress:progressBlock
|
||||||
|
completed:completedBlock
|
||||||
|
cancelled:cancelBlock];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id)initWithRequest:(NSURLRequest *)request
|
||||||
|
inSession:(NSURLSession *)session
|
||||||
|
options:(SDWebImageDownloaderOptions)options
|
||||||
|
progress:(SDWebImageDownloaderProgressBlock)progressBlock
|
||||||
|
completed:(SDWebImageDownloaderCompletedBlock)completedBlock
|
||||||
|
cancelled:(SDWebImageNoParamsBlock)cancelBlock {
|
||||||
|
if ((self = [super init])) {
|
||||||
_request = request;
|
_request = request;
|
||||||
|
_shouldDecompressImages = YES;
|
||||||
_options = options;
|
_options = options;
|
||||||
_progressBlock = [progressBlock copy];
|
_progressBlock = [progressBlock copy];
|
||||||
_completedBlock = [completedBlock copy];
|
_completedBlock = [completedBlock copy];
|
||||||
|
|
@ -43,55 +82,114 @@
|
||||||
_executing = NO;
|
_executing = NO;
|
||||||
_finished = NO;
|
_finished = NO;
|
||||||
_expectedSize = 0;
|
_expectedSize = 0;
|
||||||
responseFromCached = YES; // Initially wrong until `connection:willCacheResponse:` is called or not called
|
_unownedSession = session;
|
||||||
|
responseFromCached = YES; // Initially wrong until `- URLSession:dataTask:willCacheResponse:completionHandler: is called or not called
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)start
|
- (void)start {
|
||||||
{
|
@synchronized (self) {
|
||||||
if (self.isCancelled)
|
if (self.isCancelled) {
|
||||||
{
|
self.finished = YES;
|
||||||
self.finished = YES;
|
[self reset];
|
||||||
[self reset];
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
|
||||||
|
Class UIApplicationClass = NSClassFromString(@"UIApplication");
|
||||||
|
BOOL hasApplication = UIApplicationClass && [UIApplicationClass respondsToSelector:@selector(sharedApplication)];
|
||||||
|
if (hasApplication && [self shouldContinueWhenAppEntersBackground]) {
|
||||||
|
__weak __typeof__ (self) wself = self;
|
||||||
|
UIApplication * app = [UIApplicationClass performSelector:@selector(sharedApplication)];
|
||||||
|
self.backgroundTaskId = [app beginBackgroundTaskWithExpirationHandler:^{
|
||||||
|
__strong __typeof (wself) sself = wself;
|
||||||
|
|
||||||
|
if (sself) {
|
||||||
|
[sself cancel];
|
||||||
|
|
||||||
|
[app endBackgroundTask:sself.backgroundTaskId];
|
||||||
|
sself.backgroundTaskId = UIBackgroundTaskInvalid;
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
NSURLSession *session = self.unownedSession;
|
||||||
|
if (!self.unownedSession) {
|
||||||
|
NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration];
|
||||||
|
sessionConfig.timeoutIntervalForRequest = 15;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the session for this task
|
||||||
|
* We send nil as delegate queue so that the session creates a serial operation queue for performing all delegate
|
||||||
|
* method calls and completion handler calls.
|
||||||
|
*/
|
||||||
|
self.ownedSession = [NSURLSession sessionWithConfiguration:sessionConfig
|
||||||
|
delegate:self
|
||||||
|
delegateQueue:nil];
|
||||||
|
session = self.ownedSession;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.dataTask = [session dataTaskWithRequest:self.request];
|
||||||
|
self.executing = YES;
|
||||||
|
self.thread = [NSThread currentThread];
|
||||||
|
}
|
||||||
|
|
||||||
|
[self.dataTask resume];
|
||||||
|
|
||||||
|
if (self.dataTask) {
|
||||||
|
if (self.progressBlock) {
|
||||||
|
self.progressBlock(0, NSURLResponseUnknownLength);
|
||||||
|
}
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStartNotification object:self];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (self.completedBlock) {
|
||||||
|
self.completedBlock(nil, nil, [NSError errorWithDomain:NSURLErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey : @"Connection can't be initialized"}], YES);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
|
||||||
|
Class UIApplicationClass = NSClassFromString(@"UIApplication");
|
||||||
|
if(!UIApplicationClass || ![UIApplicationClass respondsToSelector:@selector(sharedApplication)]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (self.backgroundTaskId != UIBackgroundTaskInvalid) {
|
||||||
self.executing = YES;
|
UIApplication * app = [UIApplication performSelector:@selector(sharedApplication)];
|
||||||
self.connection = [NSURLConnection.alloc initWithRequest:self.request delegate:self startImmediately:NO];
|
[app endBackgroundTask:self.backgroundTaskId];
|
||||||
|
self.backgroundTaskId = UIBackgroundTaskInvalid;
|
||||||
[self.connection start];
|
|
||||||
|
|
||||||
if (self.connection)
|
|
||||||
{
|
|
||||||
if (self.progressBlock)
|
|
||||||
{
|
|
||||||
self.progressBlock(0, -1);
|
|
||||||
}
|
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStartNotification object:self];
|
|
||||||
|
|
||||||
// Make sure to run the runloop in our background thread so it can process downloaded data
|
|
||||||
CFRunLoopRun();
|
|
||||||
}
|
}
|
||||||
else
|
#endif
|
||||||
{
|
}
|
||||||
if (self.completedBlock)
|
|
||||||
{
|
- (void)cancel {
|
||||||
self.completedBlock(nil, nil, [NSError errorWithDomain:NSURLErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey: @"Connection can't be initialized"}], YES);
|
@synchronized (self) {
|
||||||
|
if (self.thread) {
|
||||||
|
[self performSelector:@selector(cancelInternalAndStop) onThread:self.thread withObject:nil waitUntilDone:NO];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
[self cancelInternal];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)cancel
|
- (void)cancelInternalAndStop {
|
||||||
{
|
if (self.isFinished) return;
|
||||||
|
[self cancelInternal];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)cancelInternal {
|
||||||
if (self.isFinished) return;
|
if (self.isFinished) return;
|
||||||
[super cancel];
|
[super cancel];
|
||||||
if (self.cancelBlock) self.cancelBlock();
|
if (self.cancelBlock) self.cancelBlock();
|
||||||
|
|
||||||
if (self.connection)
|
if (self.dataTask) {
|
||||||
{
|
[self.dataTask cancel];
|
||||||
[self.connection cancel];
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:self];
|
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:self];
|
||||||
|
});
|
||||||
|
|
||||||
// As we cancelled the connection, its callback won't be called and thus won't
|
// As we cancelled the connection, its callback won't be called and thus won't
|
||||||
// maintain the isFinished and isExecuting flags.
|
// maintain the isFinished and isExecuting flags.
|
||||||
|
|
@ -102,138 +200,158 @@
|
||||||
[self reset];
|
[self reset];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)done
|
- (void)done {
|
||||||
{
|
|
||||||
self.finished = YES;
|
self.finished = YES;
|
||||||
self.executing = NO;
|
self.executing = NO;
|
||||||
[self reset];
|
[self reset];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)reset
|
- (void)reset {
|
||||||
{
|
|
||||||
self.cancelBlock = nil;
|
self.cancelBlock = nil;
|
||||||
self.completedBlock = nil;
|
self.completedBlock = nil;
|
||||||
self.progressBlock = nil;
|
self.progressBlock = nil;
|
||||||
self.connection = nil;
|
self.dataTask = nil;
|
||||||
self.imageData = nil;
|
self.imageData = nil;
|
||||||
|
self.thread = nil;
|
||||||
|
if (self.ownedSession) {
|
||||||
|
[self.ownedSession invalidateAndCancel];
|
||||||
|
self.ownedSession = nil;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setFinished:(BOOL)finished
|
- (void)setFinished:(BOOL)finished {
|
||||||
{
|
|
||||||
[self willChangeValueForKey:@"isFinished"];
|
[self willChangeValueForKey:@"isFinished"];
|
||||||
_finished = finished;
|
_finished = finished;
|
||||||
[self didChangeValueForKey:@"isFinished"];
|
[self didChangeValueForKey:@"isFinished"];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setExecuting:(BOOL)executing
|
- (void)setExecuting:(BOOL)executing {
|
||||||
{
|
|
||||||
[self willChangeValueForKey:@"isExecuting"];
|
[self willChangeValueForKey:@"isExecuting"];
|
||||||
_executing = executing;
|
_executing = executing;
|
||||||
[self didChangeValueForKey:@"isExecuting"];
|
[self didChangeValueForKey:@"isExecuting"];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)isConcurrent
|
- (BOOL)isConcurrent {
|
||||||
{
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark NSURLConnection (delegate)
|
#pragma mark NSURLSessionDataDelegate
|
||||||
|
|
||||||
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
|
- (void)URLSession:(NSURLSession *)session
|
||||||
{
|
dataTask:(NSURLSessionDataTask *)dataTask
|
||||||
if (![response respondsToSelector:@selector(statusCode)] || [((NSHTTPURLResponse *)response) statusCode] < 400)
|
didReceiveResponse:(NSURLResponse *)response
|
||||||
{
|
completionHandler:(void (^)(NSURLSessionResponseDisposition disposition))completionHandler {
|
||||||
NSUInteger expected = response.expectedContentLength > 0 ? (NSUInteger)response.expectedContentLength : 0;
|
|
||||||
|
//'304 Not Modified' is an exceptional one
|
||||||
|
if (![response respondsToSelector:@selector(statusCode)] || ([((NSHTTPURLResponse *)response) statusCode] < 400 && [((NSHTTPURLResponse *)response) statusCode] != 304)) {
|
||||||
|
NSInteger expected = response.expectedContentLength > 0 ? (NSInteger)response.expectedContentLength : 0;
|
||||||
self.expectedSize = expected;
|
self.expectedSize = expected;
|
||||||
if (self.progressBlock)
|
if (self.progressBlock) {
|
||||||
{
|
|
||||||
self.progressBlock(0, expected);
|
self.progressBlock(0, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.imageData = [NSMutableData.alloc initWithCapacity:expected];
|
self.imageData = [[NSMutableData alloc] initWithCapacity:expected];
|
||||||
|
self.response = response;
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadReceiveResponseNotification object:self];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
NSUInteger code = [((NSHTTPURLResponse *)response) statusCode];
|
||||||
[self.connection cancel];
|
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:nil];
|
//This is the case when server returns '304 Not Modified'. It means that remote image is not changed.
|
||||||
|
//In case of 304 we need just cancel the operation and return cached image from the cache.
|
||||||
|
if (code == 304) {
|
||||||
|
[self cancelInternal];
|
||||||
|
} else {
|
||||||
|
[self.dataTask cancel];
|
||||||
|
}
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:self];
|
||||||
|
});
|
||||||
|
|
||||||
if (self.completedBlock)
|
if (self.completedBlock) {
|
||||||
{
|
|
||||||
self.completedBlock(nil, nil, [NSError errorWithDomain:NSURLErrorDomain code:[((NSHTTPURLResponse *)response) statusCode] userInfo:nil], YES);
|
self.completedBlock(nil, nil, [NSError errorWithDomain:NSURLErrorDomain code:[((NSHTTPURLResponse *)response) statusCode] userInfo:nil], YES);
|
||||||
}
|
}
|
||||||
|
|
||||||
[self done];
|
[self done];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (completionHandler) {
|
||||||
|
completionHandler(NSURLSessionResponseAllow);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
|
- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data {
|
||||||
{
|
|
||||||
[self.imageData appendData:data];
|
[self.imageData appendData:data];
|
||||||
|
|
||||||
if ((self.options & SDWebImageDownloaderProgressiveDownload) && self.expectedSize > 0 && self.completedBlock)
|
if ((self.options & SDWebImageDownloaderProgressiveDownload) && self.expectedSize > 0 && self.completedBlock) {
|
||||||
{
|
|
||||||
// The following code is from http://www.cocoaintheshell.com/2011/05/progressive-images-download-imageio/
|
// The following code is from http://www.cocoaintheshell.com/2011/05/progressive-images-download-imageio/
|
||||||
// Thanks to the author @Nyx0uf
|
// Thanks to the author @Nyx0uf
|
||||||
|
|
||||||
// Get the total bytes downloaded
|
// Get the total bytes downloaded
|
||||||
const NSUInteger totalSize = self.imageData.length;
|
const NSInteger totalSize = self.imageData.length;
|
||||||
|
|
||||||
// Update the data source, we must pass ALL the data, not just the new bytes
|
// Update the data source, we must pass ALL the data, not just the new bytes
|
||||||
CGImageSourceRef imageSource = CGImageSourceCreateIncremental(NULL);
|
CGImageSourceRef imageSource = CGImageSourceCreateWithData((__bridge CFDataRef)self.imageData, NULL);
|
||||||
CGImageSourceUpdateData(imageSource, (__bridge CFDataRef)self.imageData, totalSize == self.expectedSize);
|
|
||||||
|
|
||||||
if (width + height == 0)
|
if (width + height == 0) {
|
||||||
{
|
|
||||||
CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL);
|
CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL);
|
||||||
if (properties)
|
if (properties) {
|
||||||
{
|
NSInteger orientationValue = -1;
|
||||||
CFTypeRef val = CFDictionaryGetValue(properties, kCGImagePropertyPixelHeight);
|
CFTypeRef val = CFDictionaryGetValue(properties, kCGImagePropertyPixelHeight);
|
||||||
if (val) CFNumberGetValue(val, kCFNumberLongType, &height);
|
if (val) CFNumberGetValue(val, kCFNumberLongType, &height);
|
||||||
val = CFDictionaryGetValue(properties, kCGImagePropertyPixelWidth);
|
val = CFDictionaryGetValue(properties, kCGImagePropertyPixelWidth);
|
||||||
if (val) CFNumberGetValue(val, kCFNumberLongType, &width);
|
if (val) CFNumberGetValue(val, kCFNumberLongType, &width);
|
||||||
|
val = CFDictionaryGetValue(properties, kCGImagePropertyOrientation);
|
||||||
|
if (val) CFNumberGetValue(val, kCFNumberNSIntegerType, &orientationValue);
|
||||||
CFRelease(properties);
|
CFRelease(properties);
|
||||||
|
|
||||||
|
// When we draw to Core Graphics, we lose orientation information,
|
||||||
|
// which means the image below born of initWithCGIImage will be
|
||||||
|
// oriented incorrectly sometimes. (Unlike the image born of initWithData
|
||||||
|
// in didCompleteWithError.) So save it here and pass it on later.
|
||||||
|
orientation = [[self class] orientationFromPropertyValue:(orientationValue == -1 ? 1 : orientationValue)];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (width + height > 0 && totalSize < self.expectedSize)
|
if (width + height > 0 && totalSize < self.expectedSize) {
|
||||||
{
|
|
||||||
// Create the image
|
// Create the image
|
||||||
CGImageRef partialImageRef = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL);
|
CGImageRef partialImageRef = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL);
|
||||||
|
|
||||||
#ifdef TARGET_OS_IPHONE
|
#ifdef TARGET_OS_IPHONE
|
||||||
// Workaround for iOS anamorphic image
|
// Workaround for iOS anamorphic image
|
||||||
if (partialImageRef)
|
if (partialImageRef) {
|
||||||
{
|
|
||||||
const size_t partialHeight = CGImageGetHeight(partialImageRef);
|
const size_t partialHeight = CGImageGetHeight(partialImageRef);
|
||||||
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
||||||
CGContextRef bmContext = CGBitmapContextCreate(NULL, width, height, 8, width * 4, colorSpace, kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedFirst);
|
CGContextRef bmContext = CGBitmapContextCreate(NULL, width, height, 8, width * 4, colorSpace, kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedFirst);
|
||||||
CGColorSpaceRelease(colorSpace);
|
CGColorSpaceRelease(colorSpace);
|
||||||
if (bmContext)
|
if (bmContext) {
|
||||||
{
|
|
||||||
CGContextDrawImage(bmContext, (CGRect){.origin.x = 0.0f, .origin.y = 0.0f, .size.width = width, .size.height = partialHeight}, partialImageRef);
|
CGContextDrawImage(bmContext, (CGRect){.origin.x = 0.0f, .origin.y = 0.0f, .size.width = width, .size.height = partialHeight}, partialImageRef);
|
||||||
CGImageRelease(partialImageRef);
|
CGImageRelease(partialImageRef);
|
||||||
partialImageRef = CGBitmapContextCreateImage(bmContext);
|
partialImageRef = CGBitmapContextCreateImage(bmContext);
|
||||||
CGContextRelease(bmContext);
|
CGContextRelease(bmContext);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
CGImageRelease(partialImageRef);
|
CGImageRelease(partialImageRef);
|
||||||
partialImageRef = nil;
|
partialImageRef = nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (partialImageRef)
|
if (partialImageRef) {
|
||||||
{
|
UIImage *image = [UIImage imageWithCGImage:partialImageRef scale:1 orientation:orientation];
|
||||||
UIImage *image = [UIImage imageWithCGImage:partialImageRef];
|
NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:self.request.URL];
|
||||||
UIImage *scaledImage = [self scaledImageForKey:self.request.URL.absoluteString image:image];
|
UIImage *scaledImage = [self scaledImageForKey:key image:image];
|
||||||
image = [UIImage decodedImageWithImage:scaledImage];
|
if (self.shouldDecompressImages) {
|
||||||
|
image = [UIImage decodedImageWithImage:scaledImage];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
image = scaledImage;
|
||||||
|
}
|
||||||
CGImageRelease(partialImageRef);
|
CGImageRelease(partialImageRef);
|
||||||
dispatch_async(dispatch_get_main_queue(), ^
|
dispatch_main_sync_safe(^{
|
||||||
{
|
if (self.completedBlock) {
|
||||||
if (self.completedBlock)
|
|
||||||
{
|
|
||||||
self.completedBlock(image, nil, nil, NO);
|
self.completedBlock(image, nil, nil, NO);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -243,90 +361,144 @@
|
||||||
CFRelease(imageSource);
|
CFRelease(imageSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.progressBlock)
|
if (self.progressBlock) {
|
||||||
{
|
|
||||||
self.progressBlock(self.imageData.length, self.expectedSize);
|
self.progressBlock(self.imageData.length, self.expectedSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (UIImage *)scaledImageForKey:(NSString *)key image:(UIImage *)image
|
- (void)URLSession:(NSURLSession *)session
|
||||||
{
|
dataTask:(NSURLSessionDataTask *)dataTask
|
||||||
return SDScaledImageForKey(key, image);
|
willCacheResponse:(NSCachedURLResponse *)proposedResponse
|
||||||
}
|
completionHandler:(void (^)(NSCachedURLResponse *cachedResponse))completionHandler {
|
||||||
|
|
||||||
- (void)connectionDidFinishLoading:(NSURLConnection *)aConnection
|
responseFromCached = NO; // If this method is called, it means the response wasn't read from cache
|
||||||
{
|
NSCachedURLResponse *cachedResponse = proposedResponse;
|
||||||
CFRunLoopStop(CFRunLoopGetCurrent());
|
|
||||||
self.connection = nil;
|
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:nil];
|
if (self.request.cachePolicy == NSURLRequestReloadIgnoringLocalCacheData) {
|
||||||
|
// Prevents caching of responses
|
||||||
SDWebImageDownloaderCompletedBlock completionBlock = self.completedBlock;
|
cachedResponse = nil;
|
||||||
|
|
||||||
if (completionBlock)
|
|
||||||
{
|
|
||||||
if (self.options & SDWebImageDownloaderIgnoreCachedResponse && responseFromCached)
|
|
||||||
{
|
|
||||||
completionBlock(nil, nil, nil, YES);
|
|
||||||
self.completionBlock = nil;
|
|
||||||
[self done];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
UIImage *image = [UIImage sd_imageWithData:self.imageData];
|
|
||||||
|
|
||||||
image = [self scaledImageForKey:self.request.URL.absoluteString image:image];
|
|
||||||
|
|
||||||
if (!image.images) // Do not force decod animated GIFs
|
|
||||||
{
|
|
||||||
image = [UIImage decodedImageWithImage:image];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CGSizeEqualToSize(image.size, CGSizeZero))
|
|
||||||
{
|
|
||||||
completionBlock(nil, nil, [NSError errorWithDomain:@"SDWebImageErrorDomain" code:0 userInfo:@{NSLocalizedDescriptionKey: @"Downloaded image has 0 pixels"}], YES);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
completionBlock(image, self.imageData, nil, YES);
|
|
||||||
}
|
|
||||||
self.completionBlock = nil;
|
|
||||||
[self done];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
if (completionHandler) {
|
||||||
{
|
completionHandler(cachedResponse);
|
||||||
[self done];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
|
#pragma mark NSURLSessionTaskDelegate
|
||||||
{
|
|
||||||
CFRunLoopStop(CFRunLoopGetCurrent());
|
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:nil];
|
|
||||||
|
|
||||||
if (self.completedBlock)
|
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
|
||||||
{
|
@synchronized(self) {
|
||||||
self.completedBlock(nil, nil, error, YES);
|
self.thread = nil;
|
||||||
|
self.dataTask = nil;
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:self];
|
||||||
|
if (!error) {
|
||||||
|
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadFinishNotification object:self];
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
if (self.completedBlock) {
|
||||||
|
self.completedBlock(nil, nil, error, YES);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
SDWebImageDownloaderCompletedBlock completionBlock = self.completedBlock;
|
||||||
|
|
||||||
|
if (![[NSURLCache sharedURLCache] cachedResponseForRequest:_request]) {
|
||||||
|
responseFromCached = NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (completionBlock) {
|
||||||
|
if (self.options & SDWebImageDownloaderIgnoreCachedResponse && responseFromCached) {
|
||||||
|
completionBlock(nil, nil, nil, YES);
|
||||||
|
} else if (self.imageData) {
|
||||||
|
UIImage *image = [UIImage sd_imageWithData:self.imageData];
|
||||||
|
NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:self.request.URL];
|
||||||
|
image = [self scaledImageForKey:key image:image];
|
||||||
|
|
||||||
|
// Do not force decoding animated GIFs
|
||||||
|
if (!image.images) {
|
||||||
|
if (self.shouldDecompressImages) {
|
||||||
|
image = [UIImage decodedImageWithImage:image];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (CGSizeEqualToSize(image.size, CGSizeZero)) {
|
||||||
|
completionBlock(nil, nil, [NSError errorWithDomain:SDWebImageErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey : @"Downloaded image has 0 pixels"}], YES);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
completionBlock(image, self.imageData, nil, YES);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
completionBlock(nil, nil, [NSError errorWithDomain:SDWebImageErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey : @"Image data is nil"}], YES);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.completionBlock = nil;
|
||||||
[self done];
|
[self done];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse
|
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler {
|
||||||
{
|
|
||||||
responseFromCached = NO; // If this method is called, it means the response wasn't read from cache
|
NSURLSessionAuthChallengeDisposition disposition = NSURLSessionAuthChallengePerformDefaultHandling;
|
||||||
if (self.request.cachePolicy == NSURLRequestReloadIgnoringLocalCacheData)
|
__block NSURLCredential *credential = nil;
|
||||||
{
|
|
||||||
// Prevents caching of responses
|
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
|
||||||
return nil;
|
if (!(self.options & SDWebImageDownloaderAllowInvalidSSLCertificates)) {
|
||||||
|
disposition = NSURLSessionAuthChallengePerformDefaultHandling;
|
||||||
|
} else {
|
||||||
|
credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
|
||||||
|
disposition = NSURLSessionAuthChallengeUseCredential;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ([challenge previousFailureCount] == 0) {
|
||||||
|
if (self.credential) {
|
||||||
|
credential = self.credential;
|
||||||
|
disposition = NSURLSessionAuthChallengeUseCredential;
|
||||||
|
} else {
|
||||||
|
disposition = NSURLSessionAuthChallengeCancelAuthenticationChallenge;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
disposition = NSURLSessionAuthChallengeCancelAuthenticationChallenge;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
if (completionHandler) {
|
||||||
return cachedResponse;
|
completionHandler(disposition, credential);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma mark Helper methods
|
||||||
|
|
||||||
|
+ (UIImageOrientation)orientationFromPropertyValue:(NSInteger)value {
|
||||||
|
switch (value) {
|
||||||
|
case 1:
|
||||||
|
return UIImageOrientationUp;
|
||||||
|
case 3:
|
||||||
|
return UIImageOrientationDown;
|
||||||
|
case 8:
|
||||||
|
return UIImageOrientationLeft;
|
||||||
|
case 6:
|
||||||
|
return UIImageOrientationRight;
|
||||||
|
case 2:
|
||||||
|
return UIImageOrientationUpMirrored;
|
||||||
|
case 4:
|
||||||
|
return UIImageOrientationDownMirrored;
|
||||||
|
case 5:
|
||||||
|
return UIImageOrientationLeftMirrored;
|
||||||
|
case 7:
|
||||||
|
return UIImageOrientationRightMirrored;
|
||||||
|
default:
|
||||||
|
return UIImageOrientationUp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (UIImage *)scaledImageForKey:(NSString *)key image:(UIImage *)image {
|
||||||
|
return SDScaledImageForKey(key, image);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)shouldContinueWhenAppEntersBackground {
|
||||||
|
return self.options & SDWebImageDownloaderContinueInBackground;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -11,40 +11,90 @@
|
||||||
#import "SDWebImageDownloader.h"
|
#import "SDWebImageDownloader.h"
|
||||||
#import "SDImageCache.h"
|
#import "SDImageCache.h"
|
||||||
|
|
||||||
typedef enum
|
typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* By default, when a URL fail to be downloaded, the URL is blacklisted so the library won't keep trying.
|
* By default, when a URL fail to be downloaded, the URL is blacklisted so the library won't keep trying.
|
||||||
* This flag disable this blacklisting.
|
* This flag disable this blacklisting.
|
||||||
*/
|
*/
|
||||||
SDWebImageRetryFailed = 1 << 0,
|
SDWebImageRetryFailed = 1 << 0,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* By default, image downloads are started during UI interactions, this flags disable this feature,
|
* By default, image downloads are started during UI interactions, this flags disable this feature,
|
||||||
* leading to delayed download on UIScrollView deceleration for instance.
|
* leading to delayed download on UIScrollView deceleration for instance.
|
||||||
*/
|
*/
|
||||||
SDWebImageLowPriority = 1 << 1,
|
SDWebImageLowPriority = 1 << 1,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This flag disables on-disk caching
|
* This flag disables on-disk caching
|
||||||
*/
|
*/
|
||||||
SDWebImageCacheMemoryOnly = 1 << 2,
|
SDWebImageCacheMemoryOnly = 1 << 2,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This flag enables progressive download, the image is displayed progressively during download as a browser would do.
|
* This flag enables progressive download, the image is displayed progressively during download as a browser would do.
|
||||||
* By default, the image is only displayed once completely downloaded.
|
* By default, the image is only displayed once completely downloaded.
|
||||||
*/
|
*/
|
||||||
SDWebImageProgressiveDownload = 1 << 3,
|
SDWebImageProgressiveDownload = 1 << 3,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Even if the image is cached, respect the HTTP response cache control, and refresh the image from remote location if needed.
|
* Even if the image is cached, respect the HTTP response cache control, and refresh the image from remote location if needed.
|
||||||
* The disk caching will be handled by NSURLCache instead of SDWebImage leading to slight performance degradation.
|
* The disk caching will be handled by NSURLCache instead of SDWebImage leading to slight performance degradation.
|
||||||
* This option helps deal with images changing behind the same request URL, e.g. Facebook graph api profile pics.
|
* This option helps deal with images changing behind the same request URL, e.g. Facebook graph api profile pics.
|
||||||
* If a cached image is refreshed, the completion block is called once with the cached image and again with the final image.
|
* If a cached image is refreshed, the completion block is called once with the cached image and again with the final image.
|
||||||
*
|
*
|
||||||
* Use this flag only if you can't make your URLs static with embeded cache busting parameter.
|
* Use this flag only if you can't make your URLs static with embedded cache busting parameter.
|
||||||
*/
|
*/
|
||||||
SDWebImageRefreshCached = 1 << 4
|
SDWebImageRefreshCached = 1 << 4,
|
||||||
} SDWebImageOptions;
|
|
||||||
|
|
||||||
typedef void(^SDWebImageCompletedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType);
|
/**
|
||||||
typedef void(^SDWebImageCompletedWithFinishedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished);
|
* In iOS 4+, continue the download of the image if the app goes to background. This is achieved by asking the system for
|
||||||
|
* extra time in background to let the request finish. If the background task expires the operation will be cancelled.
|
||||||
|
*/
|
||||||
|
SDWebImageContinueInBackground = 1 << 5,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles cookies stored in NSHTTPCookieStore by setting
|
||||||
|
* NSMutableURLRequest.HTTPShouldHandleCookies = YES;
|
||||||
|
*/
|
||||||
|
SDWebImageHandleCookies = 1 << 6,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable to allow untrusted SSL certificates.
|
||||||
|
* Useful for testing purposes. Use with caution in production.
|
||||||
|
*/
|
||||||
|
SDWebImageAllowInvalidSSLCertificates = 1 << 7,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By default, images are loaded in the order in which they were queued. This flag moves them to
|
||||||
|
* the front of the queue.
|
||||||
|
*/
|
||||||
|
SDWebImageHighPriority = 1 << 8,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By default, placeholder images are loaded while the image is loading. This flag will delay the loading
|
||||||
|
* of the placeholder image until after the image has finished loading.
|
||||||
|
*/
|
||||||
|
SDWebImageDelayPlaceholder = 1 << 9,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We usually don't call transformDownloadedImage delegate method on animated images,
|
||||||
|
* as most transformation code would mangle it.
|
||||||
|
* Use this flag to transform them anyway.
|
||||||
|
*/
|
||||||
|
SDWebImageTransformAnimatedImage = 1 << 10,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By default, image is added to the imageView after download. But in some cases, we want to
|
||||||
|
* have the hand before setting the image (apply a filter or add it with cross-fade animation for instance)
|
||||||
|
* Use this flag if you want to manually set the image in the completion when success
|
||||||
|
*/
|
||||||
|
SDWebImageAvoidAutoSetImage = 1 << 11
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef void(^SDWebImageCompletionBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL);
|
||||||
|
|
||||||
|
typedef void(^SDWebImageCompletionWithFinishedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL);
|
||||||
|
|
||||||
|
typedef NSString *(^SDWebImageCacheKeyFilterBlock)(NSURL *url);
|
||||||
|
|
||||||
|
|
||||||
@class SDWebImageManager;
|
@class SDWebImageManager;
|
||||||
|
|
@ -57,7 +107,7 @@ typedef void(^SDWebImageCompletedWithFinishedBlock)(UIImage *image, NSError *err
|
||||||
* Controls which image should be downloaded when the image is not found in the cache.
|
* Controls which image should be downloaded when the image is not found in the cache.
|
||||||
*
|
*
|
||||||
* @param imageManager The current `SDWebImageManager`
|
* @param imageManager The current `SDWebImageManager`
|
||||||
* @param imageURL The url of the image to be downloaded
|
* @param imageURL The url of the image to be downloaded
|
||||||
*
|
*
|
||||||
* @return Return NO to prevent the downloading of the image on cache misses. If not implemented, YES is implied.
|
* @return Return NO to prevent the downloading of the image on cache misses. If not implemented, YES is implied.
|
||||||
*/
|
*/
|
||||||
|
|
@ -68,8 +118,8 @@ typedef void(^SDWebImageCompletedWithFinishedBlock)(UIImage *image, NSError *err
|
||||||
* NOTE: This method is called from a global queue in order to not to block the main thread.
|
* NOTE: This method is called from a global queue in order to not to block the main thread.
|
||||||
*
|
*
|
||||||
* @param imageManager The current `SDWebImageManager`
|
* @param imageManager The current `SDWebImageManager`
|
||||||
* @param image The image to transform
|
* @param image The image to transform
|
||||||
* @param imageURL The url of the image to transform
|
* @param imageURL The url of the image to transform
|
||||||
*
|
*
|
||||||
* @return The transformed image object.
|
* @return The transformed image object.
|
||||||
*/
|
*/
|
||||||
|
|
@ -88,22 +138,20 @@ typedef void(^SDWebImageCompletedWithFinishedBlock)(UIImage *image, NSError *err
|
||||||
* @code
|
* @code
|
||||||
|
|
||||||
SDWebImageManager *manager = [SDWebImageManager sharedManager];
|
SDWebImageManager *manager = [SDWebImageManager sharedManager];
|
||||||
[manager downloadWithURL:imageURL
|
[manager downloadImageWithURL:imageURL
|
||||||
options:0
|
options:0
|
||||||
progress:nil
|
progress:nil
|
||||||
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished)
|
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||||
{
|
if (image) {
|
||||||
if (image)
|
// do something with image
|
||||||
{
|
}
|
||||||
// do something with image
|
}];
|
||||||
}
|
|
||||||
}];
|
|
||||||
|
|
||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
@interface SDWebImageManager : NSObject
|
@interface SDWebImageManager : NSObject
|
||||||
|
|
||||||
@property (weak, nonatomic) id<SDWebImageManagerDelegate> delegate;
|
@property (weak, nonatomic) id <SDWebImageManagerDelegate> delegate;
|
||||||
|
|
||||||
@property (strong, nonatomic, readonly) SDImageCache *imageCache;
|
@property (strong, nonatomic, readonly) SDImageCache *imageCache;
|
||||||
@property (strong, nonatomic, readonly) SDWebImageDownloader *imageDownloader;
|
@property (strong, nonatomic, readonly) SDWebImageDownloader *imageDownloader;
|
||||||
|
|
@ -117,15 +165,14 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager];
|
||||||
*
|
*
|
||||||
* @code
|
* @code
|
||||||
|
|
||||||
[[SDWebImageManager sharedManager] setCacheKeyFilter:^(NSURL *url)
|
[[SDWebImageManager sharedManager] setCacheKeyFilter:^(NSURL *url) {
|
||||||
{
|
|
||||||
url = [[NSURL alloc] initWithScheme:url.scheme host:url.host path:url.path];
|
url = [[NSURL alloc] initWithScheme:url.scheme host:url.host path:url.path];
|
||||||
return [url absoluteString];
|
return [url absoluteString];
|
||||||
}];
|
}];
|
||||||
|
|
||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
@property (strong) NSString *(^cacheKeyFilter)(NSURL *url);
|
@property (nonatomic, copy) SDWebImageCacheKeyFilterBlock cacheKeyFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns global SDWebImageManager instance.
|
* Returns global SDWebImageManager instance.
|
||||||
|
|
@ -134,33 +181,51 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager];
|
||||||
*/
|
*/
|
||||||
+ (SDWebImageManager *)sharedManager;
|
+ (SDWebImageManager *)sharedManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows to specify instance of cache and image downloader used with image manager.
|
||||||
|
* @return new instance of `SDWebImageManager` with specified cache and downloader.
|
||||||
|
*/
|
||||||
|
- (instancetype)initWithCache:(SDImageCache *)cache downloader:(SDWebImageDownloader *)downloader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Downloads the image at the given URL if not present in cache or return the cached version otherwise.
|
* Downloads the image at the given URL if not present in cache or return the cached version otherwise.
|
||||||
*
|
*
|
||||||
* @param url The URL to the image
|
* @param url The URL to the image
|
||||||
* @param options A mask to specify options to use for this request
|
* @param options A mask to specify options to use for this request
|
||||||
* @param progressBlock A block called while image is downloading
|
* @param progressBlock A block called while image is downloading
|
||||||
* @param completedBlock A block called when operation has been completed.
|
* @param completedBlock A block called when operation has been completed.
|
||||||
*
|
*
|
||||||
* This block as no return value and takes the requested UIImage as first parameter.
|
* This parameter is required.
|
||||||
|
*
|
||||||
|
* This block has no return value and takes the requested UIImage as first parameter.
|
||||||
* In case of error the image parameter is nil and the second parameter may contain an NSError.
|
* In case of error the image parameter is nil and the second parameter may contain an NSError.
|
||||||
*
|
*
|
||||||
* The third parameter is an `SDImageCacheType` enum indicating if the image was retrived from the local cache
|
* The third parameter is an `SDImageCacheType` enum indicating if the image was retrieved from the local cache
|
||||||
* or from the memory cache or from the network.
|
* or from the memory cache or from the network.
|
||||||
*
|
*
|
||||||
* The last parameter is set to NO when the SDWebImageProgressiveDownload option is used and the image is
|
* The last parameter is set to NO when the SDWebImageProgressiveDownload option is used and the image is
|
||||||
* downloading. This block is thus called repetidly with a partial image. When image is fully downloaded, the
|
* downloading. This block is thus called repeatedly with a partial image. When image is fully downloaded, the
|
||||||
* block is called a last time with the full image and the last parameter set to YES.
|
* block is called a last time with the full image and the last parameter set to YES.
|
||||||
*
|
*
|
||||||
* @return Returns a cancellable NSOperation
|
* @return Returns an NSObject conforming to SDWebImageOperation. Should be an instance of SDWebImageDownloaderOperation
|
||||||
*/
|
*/
|
||||||
- (id<SDWebImageOperation>)downloadWithURL:(NSURL *)url
|
- (id <SDWebImageOperation>)downloadImageWithURL:(NSURL *)url
|
||||||
options:(SDWebImageOptions)options
|
options:(SDWebImageOptions)options
|
||||||
progress:(SDWebImageDownloaderProgressBlock)progressBlock
|
progress:(SDWebImageDownloaderProgressBlock)progressBlock
|
||||||
completed:(SDWebImageCompletedWithFinishedBlock)completedBlock;
|
completed:(SDWebImageCompletionWithFinishedBlock)completedBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancel all current opreations
|
* Saves image to cache for given URL
|
||||||
|
*
|
||||||
|
* @param image The image to cache
|
||||||
|
* @param url The URL to the image
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
- (void)saveImageToCache:(UIImage *)image forURL:(NSURL *)url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancel all current operations
|
||||||
*/
|
*/
|
||||||
- (void)cancelAll;
|
- (void)cancelAll;
|
||||||
|
|
||||||
|
|
@ -169,4 +234,71 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager];
|
||||||
*/
|
*/
|
||||||
- (BOOL)isRunning;
|
- (BOOL)isRunning;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if image has already been cached
|
||||||
|
*
|
||||||
|
* @param url image url
|
||||||
|
*
|
||||||
|
* @return if the image was already cached
|
||||||
|
*/
|
||||||
|
- (BOOL)cachedImageExistsForURL:(NSURL *)url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if image has already been cached on disk only
|
||||||
|
*
|
||||||
|
* @param url image url
|
||||||
|
*
|
||||||
|
* @return if the image was already cached (disk only)
|
||||||
|
*/
|
||||||
|
- (BOOL)diskImageExistsForURL:(NSURL *)url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Async check if image has already been cached
|
||||||
|
*
|
||||||
|
* @param url image url
|
||||||
|
* @param completionBlock the block to be executed when the check is finished
|
||||||
|
*
|
||||||
|
* @note the completion block is always executed on the main queue
|
||||||
|
*/
|
||||||
|
- (void)cachedImageExistsForURL:(NSURL *)url
|
||||||
|
completion:(SDWebImageCheckCacheCompletionBlock)completionBlock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Async check if image has already been cached on disk only
|
||||||
|
*
|
||||||
|
* @param url image url
|
||||||
|
* @param completionBlock the block to be executed when the check is finished
|
||||||
|
*
|
||||||
|
* @note the completion block is always executed on the main queue
|
||||||
|
*/
|
||||||
|
- (void)diskImageExistsForURL:(NSURL *)url
|
||||||
|
completion:(SDWebImageCheckCacheCompletionBlock)completionBlock;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*Return the cache key for a given URL
|
||||||
|
*/
|
||||||
|
- (NSString *)cacheKeyForURL:(NSURL *)url;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
#pragma mark - Deprecated
|
||||||
|
|
||||||
|
typedef void(^SDWebImageCompletedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType) __deprecated_msg("Block type deprecated. Use `SDWebImageCompletionBlock`");
|
||||||
|
typedef void(^SDWebImageCompletedWithFinishedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) __deprecated_msg("Block type deprecated. Use `SDWebImageCompletionWithFinishedBlock`");
|
||||||
|
|
||||||
|
|
||||||
|
@interface SDWebImageManager (Deprecated)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Downloads the image at the given URL if not present in cache or return the cached version otherwise.
|
||||||
|
*
|
||||||
|
* @deprecated This method has been deprecated. Use `downloadImageWithURL:options:progress:completed:`
|
||||||
|
*/
|
||||||
|
- (id <SDWebImageOperation>)downloadWithURL:(NSURL *)url
|
||||||
|
options:(SDWebImageOptions)options
|
||||||
|
progress:(SDWebImageDownloaderProgressBlock)progressBlock
|
||||||
|
completed:(SDWebImageCompletedWithFinishedBlock)completedBlock __deprecated_msg("Method deprecated. Use `downloadImageWithURL:options:progress:completed:`");
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -7,13 +7,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import "SDWebImageManager.h"
|
#import "SDWebImageManager.h"
|
||||||
#import "UIImage+GIF.h"
|
|
||||||
#import <objc/message.h>
|
#import <objc/message.h>
|
||||||
|
|
||||||
@interface SDWebImageCombinedOperation : NSObject <SDWebImageOperation>
|
@interface SDWebImageCombinedOperation : NSObject <SDWebImageOperation>
|
||||||
|
|
||||||
@property (assign, nonatomic, getter = isCancelled) BOOL cancelled;
|
@property (assign, nonatomic, getter = isCancelled) BOOL cancelled;
|
||||||
@property (copy, nonatomic) void (^cancelBlock)();
|
@property (copy, nonatomic) SDWebImageNoParamsBlock cancelBlock;
|
||||||
|
@property (strong, nonatomic) NSOperation *cacheOperation;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
@ -21,101 +21,152 @@
|
||||||
|
|
||||||
@property (strong, nonatomic, readwrite) SDImageCache *imageCache;
|
@property (strong, nonatomic, readwrite) SDImageCache *imageCache;
|
||||||
@property (strong, nonatomic, readwrite) SDWebImageDownloader *imageDownloader;
|
@property (strong, nonatomic, readwrite) SDWebImageDownloader *imageDownloader;
|
||||||
@property (strong, nonatomic) NSMutableArray *failedURLs;
|
@property (strong, nonatomic) NSMutableSet *failedURLs;
|
||||||
@property (strong, nonatomic) NSMutableArray *runningOperations;
|
@property (strong, nonatomic) NSMutableArray *runningOperations;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation SDWebImageManager
|
@implementation SDWebImageManager
|
||||||
|
|
||||||
+ (id)sharedManager
|
+ (id)sharedManager {
|
||||||
{
|
|
||||||
static dispatch_once_t once;
|
static dispatch_once_t once;
|
||||||
static id instance;
|
static id instance;
|
||||||
dispatch_once(&once, ^{instance = self.new;});
|
dispatch_once(&once, ^{
|
||||||
|
instance = [self new];
|
||||||
|
});
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)init
|
- (instancetype)init {
|
||||||
{
|
SDImageCache *cache = [SDImageCache sharedImageCache];
|
||||||
if ((self = [super init]))
|
SDWebImageDownloader *downloader = [SDWebImageDownloader sharedDownloader];
|
||||||
{
|
return [self initWithCache:cache downloader:downloader];
|
||||||
_imageCache = [self createCache];
|
}
|
||||||
_imageDownloader = SDWebImageDownloader.new;
|
|
||||||
_failedURLs = NSMutableArray.new;
|
- (instancetype)initWithCache:(SDImageCache *)cache downloader:(SDWebImageDownloader *)downloader {
|
||||||
_runningOperations = NSMutableArray.new;
|
if ((self = [super init])) {
|
||||||
|
_imageCache = cache;
|
||||||
|
_imageDownloader = downloader;
|
||||||
|
_failedURLs = [NSMutableSet new];
|
||||||
|
_runningOperations = [NSMutableArray new];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (SDImageCache *)createCache
|
- (NSString *)cacheKeyForURL:(NSURL *)url {
|
||||||
{
|
if (!url) {
|
||||||
return [SDImageCache sharedImageCache];
|
return @"";
|
||||||
}
|
|
||||||
|
|
||||||
- (NSString *)cacheKeyForURL:(NSURL *)url
|
|
||||||
{
|
|
||||||
if (self.cacheKeyFilter)
|
|
||||||
{
|
|
||||||
return self.cacheKeyFilter(url);
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
if (self.cacheKeyFilter) {
|
||||||
|
return self.cacheKeyFilter(url);
|
||||||
|
} else {
|
||||||
return [url absoluteString];
|
return [url absoluteString];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id<SDWebImageOperation>)downloadWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedWithFinishedBlock)completedBlock
|
- (BOOL)cachedImageExistsForURL:(NSURL *)url {
|
||||||
{
|
NSString *key = [self cacheKeyForURL:url];
|
||||||
|
if ([self.imageCache imageFromMemoryCacheForKey:key] != nil) return YES;
|
||||||
|
return [self.imageCache diskImageExistsWithKey:key];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)diskImageExistsForURL:(NSURL *)url {
|
||||||
|
NSString *key = [self cacheKeyForURL:url];
|
||||||
|
return [self.imageCache diskImageExistsWithKey:key];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)cachedImageExistsForURL:(NSURL *)url
|
||||||
|
completion:(SDWebImageCheckCacheCompletionBlock)completionBlock {
|
||||||
|
NSString *key = [self cacheKeyForURL:url];
|
||||||
|
|
||||||
|
BOOL isInMemoryCache = ([self.imageCache imageFromMemoryCacheForKey:key] != nil);
|
||||||
|
|
||||||
|
if (isInMemoryCache) {
|
||||||
|
// making sure we call the completion block on the main queue
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
if (completionBlock) {
|
||||||
|
completionBlock(YES);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
[self.imageCache diskImageExistsWithKey:key completion:^(BOOL isInDiskCache) {
|
||||||
|
// the completion block of checkDiskCacheForImageWithKey:completion: is always called on the main queue, no need to further dispatch
|
||||||
|
if (completionBlock) {
|
||||||
|
completionBlock(isInDiskCache);
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)diskImageExistsForURL:(NSURL *)url
|
||||||
|
completion:(SDWebImageCheckCacheCompletionBlock)completionBlock {
|
||||||
|
NSString *key = [self cacheKeyForURL:url];
|
||||||
|
|
||||||
|
[self.imageCache diskImageExistsWithKey:key completion:^(BOOL isInDiskCache) {
|
||||||
|
// the completion block of checkDiskCacheForImageWithKey:completion: is always called on the main queue, no need to further dispatch
|
||||||
|
if (completionBlock) {
|
||||||
|
completionBlock(isInDiskCache);
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id <SDWebImageOperation>)downloadImageWithURL:(NSURL *)url
|
||||||
|
options:(SDWebImageOptions)options
|
||||||
|
progress:(SDWebImageDownloaderProgressBlock)progressBlock
|
||||||
|
completed:(SDWebImageCompletionWithFinishedBlock)completedBlock {
|
||||||
|
// Invoking this method without a completedBlock is pointless
|
||||||
|
NSAssert(completedBlock != nil, @"If you mean to prefetch the image, use -[SDWebImagePrefetcher prefetchURLs] instead");
|
||||||
|
|
||||||
// Very common mistake is to send the URL using NSString object instead of NSURL. For some strange reason, XCode won't
|
// Very common mistake is to send the URL using NSString object instead of NSURL. For some strange reason, XCode won't
|
||||||
// throw any warning for this type mismatch. Here we failsafe this error by allowing URLs to be passed as NSString.
|
// throw any warning for this type mismatch. Here we failsafe this error by allowing URLs to be passed as NSString.
|
||||||
if ([url isKindOfClass:NSString.class])
|
if ([url isKindOfClass:NSString.class]) {
|
||||||
{
|
|
||||||
url = [NSURL URLWithString:(NSString *)url];
|
url = [NSURL URLWithString:(NSString *)url];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prevents app crashing on argument type error like sending NSNull instead of NSURL
|
// Prevents app crashing on argument type error like sending NSNull instead of NSURL
|
||||||
if (![url isKindOfClass:NSURL.class])
|
if (![url isKindOfClass:NSURL.class]) {
|
||||||
{
|
|
||||||
url = nil;
|
url = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
__block SDWebImageCombinedOperation *operation = SDWebImageCombinedOperation.new;
|
__block SDWebImageCombinedOperation *operation = [SDWebImageCombinedOperation new];
|
||||||
__weak SDWebImageCombinedOperation *weakOperation = operation;
|
__weak SDWebImageCombinedOperation *weakOperation = operation;
|
||||||
|
|
||||||
BOOL isFailedUrl = NO;
|
BOOL isFailedUrl = NO;
|
||||||
@synchronized(self.failedURLs)
|
@synchronized (self.failedURLs) {
|
||||||
{
|
|
||||||
isFailedUrl = [self.failedURLs containsObject:url];
|
isFailedUrl = [self.failedURLs containsObject:url];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!url || !completedBlock || (!(options & SDWebImageRetryFailed) && isFailedUrl))
|
if (url.absoluteString.length == 0 || (!(options & SDWebImageRetryFailed) && isFailedUrl)) {
|
||||||
{
|
dispatch_main_sync_safe(^{
|
||||||
if (completedBlock)
|
|
||||||
{
|
|
||||||
NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil];
|
NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil];
|
||||||
completedBlock(nil, error, SDImageCacheTypeNone, YES);
|
completedBlock(nil, error, SDImageCacheTypeNone, YES, url);
|
||||||
}
|
});
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@synchronized(self.runningOperations)
|
@synchronized (self.runningOperations) {
|
||||||
{
|
|
||||||
[self.runningOperations addObject:operation];
|
[self.runningOperations addObject:operation];
|
||||||
}
|
}
|
||||||
NSString *key = [self cacheKeyForURL:url];
|
NSString *key = [self cacheKeyForURL:url];
|
||||||
|
|
||||||
[self.imageCache queryDiskCacheForKey:key done:^(UIImage *image, SDImageCacheType cacheType)
|
operation.cacheOperation = [self.imageCache queryDiskCacheForKey:key done:^(UIImage *image, SDImageCacheType cacheType) {
|
||||||
{
|
if (operation.isCancelled) {
|
||||||
if (operation.isCancelled) return;
|
@synchronized (self.runningOperations) {
|
||||||
|
[self.runningOperations removeObject:operation];
|
||||||
|
}
|
||||||
|
|
||||||
if ((!image || options & SDWebImageRefreshCached) && (![self.delegate respondsToSelector:@selector(imageManager:shouldDownloadImageForURL:)] || [self.delegate imageManager:self shouldDownloadImageForURL:url]))
|
return;
|
||||||
{
|
}
|
||||||
if (image && options & SDWebImageRefreshCached)
|
|
||||||
{
|
if ((!image || options & SDWebImageRefreshCached) && (![self.delegate respondsToSelector:@selector(imageManager:shouldDownloadImageForURL:)] || [self.delegate imageManager:self shouldDownloadImageForURL:url])) {
|
||||||
// If image was found in the cache bug SDWebImageRefreshCached is provided, notify about the cached image
|
if (image && options & SDWebImageRefreshCached) {
|
||||||
// AND try to re-download it in order to let a chance to NSURLCache to refresh it from server.
|
dispatch_main_sync_safe(^{
|
||||||
completedBlock(image, nil, cacheType, YES);
|
// If image was found in the cache but SDWebImageRefreshCached is provided, notify about the cached image
|
||||||
|
// AND try to re-download it in order to let a chance to NSURLCache to refresh it from server.
|
||||||
|
completedBlock(image, nil, cacheType, YES, url);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// download if no image or requested to refresh anyway, and download allowed by delegate
|
// download if no image or requested to refresh anyway, and download allowed by delegate
|
||||||
|
|
@ -123,93 +174,122 @@
|
||||||
if (options & SDWebImageLowPriority) downloaderOptions |= SDWebImageDownloaderLowPriority;
|
if (options & SDWebImageLowPriority) downloaderOptions |= SDWebImageDownloaderLowPriority;
|
||||||
if (options & SDWebImageProgressiveDownload) downloaderOptions |= SDWebImageDownloaderProgressiveDownload;
|
if (options & SDWebImageProgressiveDownload) downloaderOptions |= SDWebImageDownloaderProgressiveDownload;
|
||||||
if (options & SDWebImageRefreshCached) downloaderOptions |= SDWebImageDownloaderUseNSURLCache;
|
if (options & SDWebImageRefreshCached) downloaderOptions |= SDWebImageDownloaderUseNSURLCache;
|
||||||
if (image && options & SDWebImageRefreshCached)
|
if (options & SDWebImageContinueInBackground) downloaderOptions |= SDWebImageDownloaderContinueInBackground;
|
||||||
{
|
if (options & SDWebImageHandleCookies) downloaderOptions |= SDWebImageDownloaderHandleCookies;
|
||||||
|
if (options & SDWebImageAllowInvalidSSLCertificates) downloaderOptions |= SDWebImageDownloaderAllowInvalidSSLCertificates;
|
||||||
|
if (options & SDWebImageHighPriority) downloaderOptions |= SDWebImageDownloaderHighPriority;
|
||||||
|
if (image && options & SDWebImageRefreshCached) {
|
||||||
// force progressive off if image already cached but forced refreshing
|
// force progressive off if image already cached but forced refreshing
|
||||||
downloaderOptions &= ~SDWebImageDownloaderProgressiveDownload;
|
downloaderOptions &= ~SDWebImageDownloaderProgressiveDownload;
|
||||||
// ignore image read from NSURLCache if image if cached but force refreshing
|
// ignore image read from NSURLCache if image if cached but force refreshing
|
||||||
downloaderOptions |= SDWebImageDownloaderIgnoreCachedResponse;
|
downloaderOptions |= SDWebImageDownloaderIgnoreCachedResponse;
|
||||||
}
|
}
|
||||||
__block id<SDWebImageOperation> subOperation = [self.imageDownloader downloadImageWithURL:url options:downloaderOptions progress:progressBlock completed:^(UIImage *downloadedImage, NSData *data, NSError *error, BOOL finished)
|
id <SDWebImageOperation> subOperation = [self.imageDownloader downloadImageWithURL:url options:downloaderOptions progress:progressBlock completed:^(UIImage *downloadedImage, NSData *data, NSError *error, BOOL finished) {
|
||||||
{
|
__strong __typeof(weakOperation) strongOperation = weakOperation;
|
||||||
if (weakOperation.cancelled)
|
if (!strongOperation || strongOperation.isCancelled) {
|
||||||
{
|
// Do nothing if the operation was cancelled
|
||||||
completedBlock(nil, nil, SDImageCacheTypeNone, finished);
|
// See #699 for more details
|
||||||
|
// if we would call the completedBlock, there could be a race condition between this block and another completedBlock for the same object, so if this one is called second, we will overwrite the new data
|
||||||
}
|
}
|
||||||
else if (error)
|
else if (error) {
|
||||||
{
|
dispatch_main_sync_safe(^{
|
||||||
completedBlock(nil, error, SDImageCacheTypeNone, finished);
|
if (strongOperation && !strongOperation.isCancelled) {
|
||||||
|
completedBlock(nil, error, SDImageCacheTypeNone, finished, url);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (error.code != NSURLErrorNotConnectedToInternet)
|
if ( error.code != NSURLErrorNotConnectedToInternet
|
||||||
{
|
&& error.code != NSURLErrorCancelled
|
||||||
@synchronized(self.failedURLs)
|
&& error.code != NSURLErrorTimedOut
|
||||||
{
|
&& error.code != NSURLErrorInternationalRoamingOff
|
||||||
|
&& error.code != NSURLErrorDataNotAllowed
|
||||||
|
&& error.code != NSURLErrorCannotFindHost
|
||||||
|
&& error.code != NSURLErrorCannotConnectToHost) {
|
||||||
|
@synchronized (self.failedURLs) {
|
||||||
[self.failedURLs addObject:url];
|
[self.failedURLs addObject:url];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
if ((options & SDWebImageRetryFailed)) {
|
||||||
|
@synchronized (self.failedURLs) {
|
||||||
|
[self.failedURLs removeObject:url];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
BOOL cacheOnDisk = !(options & SDWebImageCacheMemoryOnly);
|
BOOL cacheOnDisk = !(options & SDWebImageCacheMemoryOnly);
|
||||||
|
|
||||||
if (options & SDWebImageRefreshCached && image && !downloadedImage)
|
if (options & SDWebImageRefreshCached && image && !downloadedImage) {
|
||||||
{
|
|
||||||
// Image refresh hit the NSURLCache cache, do not call the completion block
|
// Image refresh hit the NSURLCache cache, do not call the completion block
|
||||||
}
|
}
|
||||||
// NOTE: We don't call transformDownloadedImage delegate method on animated images as most transformation code would mangle it
|
else if (downloadedImage && (!downloadedImage.images || (options & SDWebImageTransformAnimatedImage)) && [self.delegate respondsToSelector:@selector(imageManager:transformDownloadedImage:withURL:)]) {
|
||||||
else if (downloadedImage && !downloadedImage.images && [self.delegate respondsToSelector:@selector(imageManager:transformDownloadedImage:withURL:)])
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
|
||||||
{
|
|
||||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^
|
|
||||||
{
|
|
||||||
UIImage *transformedImage = [self.delegate imageManager:self transformDownloadedImage:downloadedImage withURL:url];
|
UIImage *transformedImage = [self.delegate imageManager:self transformDownloadedImage:downloadedImage withURL:url];
|
||||||
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^
|
if (transformedImage && finished) {
|
||||||
{
|
BOOL imageWasTransformed = ![transformedImage isEqual:downloadedImage];
|
||||||
completedBlock(transformedImage, nil, SDImageCacheTypeNone, finished);
|
[self.imageCache storeImage:transformedImage recalculateFromImage:imageWasTransformed imageData:(imageWasTransformed ? nil : data) forKey:key toDisk:cacheOnDisk];
|
||||||
});
|
}
|
||||||
|
|
||||||
if (transformedImage && finished)
|
dispatch_main_sync_safe(^{
|
||||||
{
|
if (strongOperation && !strongOperation.isCancelled) {
|
||||||
NSData *dataToStore = [transformedImage isEqual:downloadedImage] ? data : nil;
|
completedBlock(transformedImage, nil, SDImageCacheTypeNone, finished, url);
|
||||||
[self.imageCache storeImage:transformedImage imageData:dataToStore forKey:key toDisk:cacheOnDisk];
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (downloadedImage && finished) {
|
||||||
|
[self.imageCache storeImage:downloadedImage recalculateFromImage:NO imageData:data forKey:key toDisk:cacheOnDisk];
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch_main_sync_safe(^{
|
||||||
|
if (strongOperation && !strongOperation.isCancelled) {
|
||||||
|
completedBlock(downloadedImage, nil, SDImageCacheTypeNone, finished, url);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
|
||||||
completedBlock(downloadedImage, nil, SDImageCacheTypeNone, finished);
|
|
||||||
|
|
||||||
if (downloadedImage && finished)
|
if (finished) {
|
||||||
{
|
@synchronized (self.runningOperations) {
|
||||||
[self.imageCache storeImage:downloadedImage imageData:data forKey:key toDisk:cacheOnDisk];
|
if (strongOperation) {
|
||||||
|
[self.runningOperations removeObject:strongOperation];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}];
|
||||||
|
operation.cancelBlock = ^{
|
||||||
|
[subOperation cancel];
|
||||||
|
|
||||||
if (finished)
|
@synchronized (self.runningOperations) {
|
||||||
{
|
__strong __typeof(weakOperation) strongOperation = weakOperation;
|
||||||
@synchronized(self.runningOperations)
|
if (strongOperation) {
|
||||||
{
|
[self.runningOperations removeObject:strongOperation];
|
||||||
[self.runningOperations removeObject:operation];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}];
|
};
|
||||||
operation.cancelBlock = ^{[subOperation cancel];};
|
|
||||||
}
|
}
|
||||||
else if (image)
|
else if (image) {
|
||||||
{
|
dispatch_main_sync_safe(^{
|
||||||
completedBlock(image, nil, cacheType, YES);
|
__strong __typeof(weakOperation) strongOperation = weakOperation;
|
||||||
@synchronized(self.runningOperations)
|
if (strongOperation && !strongOperation.isCancelled) {
|
||||||
{
|
completedBlock(image, nil, cacheType, YES, url);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
@synchronized (self.runningOperations) {
|
||||||
[self.runningOperations removeObject:operation];
|
[self.runningOperations removeObject:operation];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
// Image not in cache and download disallowed by delegate
|
// Image not in cache and download disallowed by delegate
|
||||||
completedBlock(nil, nil, SDImageCacheTypeNone, YES);
|
dispatch_main_sync_safe(^{
|
||||||
@synchronized(self.runningOperations)
|
__strong __typeof(weakOperation) strongOperation = weakOperation;
|
||||||
{
|
if (strongOperation && !weakOperation.isCancelled) {
|
||||||
|
completedBlock(nil, nil, SDImageCacheTypeNone, YES, url);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
@synchronized (self.runningOperations) {
|
||||||
[self.runningOperations removeObject:operation];
|
[self.runningOperations removeObject:operation];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -218,44 +298,78 @@
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)cancelAll
|
- (void)saveImageToCache:(UIImage *)image forURL:(NSURL *)url {
|
||||||
{
|
if (image && url) {
|
||||||
@synchronized(self.runningOperations)
|
NSString *key = [self cacheKeyForURL:url];
|
||||||
{
|
[self.imageCache storeImage:image forKey:key toDisk:YES];
|
||||||
[self.runningOperations makeObjectsPerformSelector:@selector(cancel)];
|
|
||||||
[self.runningOperations removeAllObjects];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)isRunning
|
- (void)cancelAll {
|
||||||
{
|
@synchronized (self.runningOperations) {
|
||||||
return self.runningOperations.count > 0;
|
NSArray *copiedOperations = [self.runningOperations copy];
|
||||||
|
[copiedOperations makeObjectsPerformSelector:@selector(cancel)];
|
||||||
|
[self.runningOperations removeObjectsInArray:copiedOperations];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)isRunning {
|
||||||
|
BOOL isRunning = NO;
|
||||||
|
@synchronized(self.runningOperations) {
|
||||||
|
isRunning = (self.runningOperations.count > 0);
|
||||||
|
}
|
||||||
|
return isRunning;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
@implementation SDWebImageCombinedOperation
|
@implementation SDWebImageCombinedOperation
|
||||||
|
|
||||||
- (void)setCancelBlock:(void (^)())cancelBlock
|
- (void)setCancelBlock:(SDWebImageNoParamsBlock)cancelBlock {
|
||||||
{
|
// check if the operation is already cancelled, then we just call the cancelBlock
|
||||||
if (self.isCancelled)
|
if (self.isCancelled) {
|
||||||
{
|
if (cancelBlock) {
|
||||||
if (cancelBlock) cancelBlock();
|
cancelBlock();
|
||||||
}
|
}
|
||||||
else
|
_cancelBlock = nil; // don't forget to nil the cancelBlock, otherwise we will get crashes
|
||||||
{
|
} else {
|
||||||
_cancelBlock = [cancelBlock copy];
|
_cancelBlock = [cancelBlock copy];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)cancel
|
- (void)cancel {
|
||||||
{
|
|
||||||
self.cancelled = YES;
|
self.cancelled = YES;
|
||||||
if (self.cancelBlock)
|
if (self.cacheOperation) {
|
||||||
{
|
[self.cacheOperation cancel];
|
||||||
|
self.cacheOperation = nil;
|
||||||
|
}
|
||||||
|
if (self.cancelBlock) {
|
||||||
self.cancelBlock();
|
self.cancelBlock();
|
||||||
self.cancelBlock = nil;
|
|
||||||
|
// TODO: this is a temporary fix to #809.
|
||||||
|
// Until we can figure the exact cause of the crash, going with the ivar instead of the setter
|
||||||
|
// self.cancelBlock = nil;
|
||||||
|
_cancelBlock = nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@implementation SDWebImageManager (Deprecated)
|
||||||
|
|
||||||
|
// deprecated method, uses the non deprecated method
|
||||||
|
// adapter for the completion block
|
||||||
|
- (id <SDWebImageOperation>)downloadWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedWithFinishedBlock)completedBlock {
|
||||||
|
return [self downloadImageWithURL:url
|
||||||
|
options:options
|
||||||
|
progress:progressBlock
|
||||||
|
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||||
|
if (completedBlock) {
|
||||||
|
completedBlock(image, error, cacheType, finished);
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,45 @@
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import "SDWebImageManager.h"
|
#import "SDWebImageManager.h"
|
||||||
|
|
||||||
|
@class SDWebImagePrefetcher;
|
||||||
|
|
||||||
|
@protocol SDWebImagePrefetcherDelegate <NSObject>
|
||||||
|
|
||||||
|
@optional
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when an image was prefetched.
|
||||||
|
*
|
||||||
|
* @param imagePrefetcher The current image prefetcher
|
||||||
|
* @param imageURL The image url that was prefetched
|
||||||
|
* @param finishedCount The total number of images that were prefetched (successful or not)
|
||||||
|
* @param totalCount The total number of images that were to be prefetched
|
||||||
|
*/
|
||||||
|
- (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didPrefetchURL:(NSURL *)imageURL finishedCount:(NSUInteger)finishedCount totalCount:(NSUInteger)totalCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when all images are prefetched.
|
||||||
|
* @param imagePrefetcher The current image prefetcher
|
||||||
|
* @param totalCount The total number of images that were prefetched (whether successful or not)
|
||||||
|
* @param skippedCount The total number of images that were skipped
|
||||||
|
*/
|
||||||
|
- (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didFinishWithTotalCount:(NSUInteger)totalCount skippedCount:(NSUInteger)skippedCount;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
typedef void(^SDWebImagePrefetcherProgressBlock)(NSUInteger noOfFinishedUrls, NSUInteger noOfTotalUrls);
|
||||||
|
typedef void(^SDWebImagePrefetcherCompletionBlock)(NSUInteger noOfFinishedUrls, NSUInteger noOfSkippedUrls);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prefetch some URLs in the cache for future use. Images are downloaded in low priority.
|
* Prefetch some URLs in the cache for future use. Images are downloaded in low priority.
|
||||||
*/
|
*/
|
||||||
@interface SDWebImagePrefetcher : NSObject
|
@interface SDWebImagePrefetcher : NSObject
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The web image manager
|
||||||
|
*/
|
||||||
|
@property (strong, nonatomic, readonly) SDWebImageManager *manager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum number of URLs to prefetch at the same time. Defaults to 3.
|
* Maximum number of URLs to prefetch at the same time. Defaults to 3.
|
||||||
*/
|
*/
|
||||||
|
|
@ -24,12 +58,23 @@
|
||||||
*/
|
*/
|
||||||
@property (nonatomic, assign) SDWebImageOptions options;
|
@property (nonatomic, assign) SDWebImageOptions options;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queue options for Prefetcher. Defaults to Main Queue.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, assign) dispatch_queue_t prefetcherQueue;
|
||||||
|
|
||||||
|
@property (weak, nonatomic) id <SDWebImagePrefetcherDelegate> delegate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the global image prefetcher instance.
|
* Return the global image prefetcher instance.
|
||||||
*/
|
*/
|
||||||
+ (SDWebImagePrefetcher *)sharedImagePrefetcher;
|
+ (SDWebImagePrefetcher *)sharedImagePrefetcher;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows you to instantiate a prefetcher with any arbitrary image manager.
|
||||||
|
*/
|
||||||
|
- (id)initWithImageManager:(SDWebImageManager *)manager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assign list of URLs to let SDWebImagePrefetcher to queue the prefetching,
|
* Assign list of URLs to let SDWebImagePrefetcher to queue the prefetching,
|
||||||
* currently one image is downloaded at a time,
|
* currently one image is downloaded at a time,
|
||||||
|
|
@ -44,10 +89,15 @@
|
||||||
* currently one image is downloaded at a time,
|
* currently one image is downloaded at a time,
|
||||||
* and skips images for failed downloads and proceed to the next image in the list
|
* and skips images for failed downloads and proceed to the next image in the list
|
||||||
*
|
*
|
||||||
* @param urls list of URLs to prefetch
|
* @param urls list of URLs to prefetch
|
||||||
|
* @param progressBlock block to be called when progress updates;
|
||||||
|
* first parameter is the number of completed (successful or not) requests,
|
||||||
|
* second parameter is the total number of images originally requested to be prefetched
|
||||||
* @param completionBlock block to be called when prefetching is completed
|
* @param completionBlock block to be called when prefetching is completed
|
||||||
|
* first param is the number of completed (successful or not) requests,
|
||||||
|
* second parameter is the number of skipped requests
|
||||||
*/
|
*/
|
||||||
- (void)prefetchURLs:(NSArray *)urls completed:(void (^)(NSUInteger finishedCount, NSUInteger skippedCount))completionBlock;
|
- (void)prefetchURLs:(NSArray *)urls progress:(SDWebImagePrefetcherProgressBlock)progressBlock completed:(SDWebImagePrefetcherCompletionBlock)completionBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove and cancel queued list
|
* Remove and cancel queued list
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import "SDWebImagePrefetcher.h"
|
#import "SDWebImagePrefetcher.h"
|
||||||
#import "SDWebImageManager.h"
|
|
||||||
|
|
||||||
@interface SDWebImagePrefetcher ()
|
@interface SDWebImagePrefetcher ()
|
||||||
|
|
||||||
|
|
@ -17,106 +16,120 @@
|
||||||
@property (assign, nonatomic) NSUInteger skippedCount;
|
@property (assign, nonatomic) NSUInteger skippedCount;
|
||||||
@property (assign, nonatomic) NSUInteger finishedCount;
|
@property (assign, nonatomic) NSUInteger finishedCount;
|
||||||
@property (assign, nonatomic) NSTimeInterval startedTime;
|
@property (assign, nonatomic) NSTimeInterval startedTime;
|
||||||
@property (copy, nonatomic) void (^completionBlock)(NSUInteger, NSUInteger);
|
@property (copy, nonatomic) SDWebImagePrefetcherCompletionBlock completionBlock;
|
||||||
|
@property (copy, nonatomic) SDWebImagePrefetcherProgressBlock progressBlock;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation SDWebImagePrefetcher
|
@implementation SDWebImagePrefetcher
|
||||||
|
|
||||||
+ (SDWebImagePrefetcher *)sharedImagePrefetcher
|
+ (SDWebImagePrefetcher *)sharedImagePrefetcher {
|
||||||
{
|
|
||||||
static dispatch_once_t once;
|
static dispatch_once_t once;
|
||||||
static id instance;
|
static id instance;
|
||||||
dispatch_once(&once, ^{instance = self.new;});
|
dispatch_once(&once, ^{
|
||||||
|
instance = [self new];
|
||||||
|
});
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)init
|
- (id)init {
|
||||||
{
|
return [self initWithImageManager:[SDWebImageManager new]];
|
||||||
if ((self = [super init]))
|
}
|
||||||
{
|
|
||||||
_manager = SDWebImageManager.new;
|
- (id)initWithImageManager:(SDWebImageManager *)manager {
|
||||||
|
if ((self = [super init])) {
|
||||||
|
_manager = manager;
|
||||||
_options = SDWebImageLowPriority;
|
_options = SDWebImageLowPriority;
|
||||||
|
_prefetcherQueue = dispatch_get_main_queue();
|
||||||
self.maxConcurrentDownloads = 3;
|
self.maxConcurrentDownloads = 3;
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setMaxConcurrentDownloads:(NSUInteger)maxConcurrentDownloads
|
- (void)setMaxConcurrentDownloads:(NSUInteger)maxConcurrentDownloads {
|
||||||
{
|
|
||||||
self.manager.imageDownloader.maxConcurrentDownloads = maxConcurrentDownloads;
|
self.manager.imageDownloader.maxConcurrentDownloads = maxConcurrentDownloads;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSUInteger)maxConcurrentDownloads
|
- (NSUInteger)maxConcurrentDownloads {
|
||||||
{
|
|
||||||
return self.manager.imageDownloader.maxConcurrentDownloads;
|
return self.manager.imageDownloader.maxConcurrentDownloads;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)startPrefetchingAtIndex:(NSUInteger)index
|
- (void)startPrefetchingAtIndex:(NSUInteger)index {
|
||||||
{
|
|
||||||
if (index >= self.prefetchURLs.count) return;
|
if (index >= self.prefetchURLs.count) return;
|
||||||
self.requestedCount++;
|
self.requestedCount++;
|
||||||
[self.manager downloadWithURL:self.prefetchURLs[index] options:self.options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished)
|
[self.manager downloadImageWithURL:self.prefetchURLs[index] options:self.options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||||
{
|
|
||||||
if (!finished) return;
|
if (!finished) return;
|
||||||
self.finishedCount++;
|
self.finishedCount++;
|
||||||
|
|
||||||
if (image)
|
if (image) {
|
||||||
{
|
if (self.progressBlock) {
|
||||||
NSLog(@"Prefetched %d out of %d", self.finishedCount, self.prefetchURLs.count);
|
self.progressBlock(self.finishedCount,[self.prefetchURLs count]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
if (self.progressBlock) {
|
||||||
NSLog(@"Prefetched %d out of %d (Failed)", self.finishedCount, [self.prefetchURLs count]);
|
self.progressBlock(self.finishedCount,[self.prefetchURLs count]);
|
||||||
|
}
|
||||||
// Add last failed
|
// Add last failed
|
||||||
self.skippedCount++;
|
self.skippedCount++;
|
||||||
}
|
}
|
||||||
|
if ([self.delegate respondsToSelector:@selector(imagePrefetcher:didPrefetchURL:finishedCount:totalCount:)]) {
|
||||||
if (self.prefetchURLs.count > self.requestedCount)
|
[self.delegate imagePrefetcher:self
|
||||||
{
|
didPrefetchURL:self.prefetchURLs[index]
|
||||||
[self startPrefetchingAtIndex:self.requestedCount];
|
finishedCount:self.finishedCount
|
||||||
|
totalCount:self.prefetchURLs.count
|
||||||
|
];
|
||||||
}
|
}
|
||||||
else if (self.finishedCount == self.requestedCount)
|
if (self.prefetchURLs.count > self.requestedCount) {
|
||||||
{
|
dispatch_async(self.prefetcherQueue, ^{
|
||||||
|
[self startPrefetchingAtIndex:self.requestedCount];
|
||||||
|
});
|
||||||
|
} else if (self.finishedCount == self.requestedCount) {
|
||||||
[self reportStatus];
|
[self reportStatus];
|
||||||
if (self.completionBlock)
|
if (self.completionBlock) {
|
||||||
{
|
|
||||||
self.completionBlock(self.finishedCount, self.skippedCount);
|
self.completionBlock(self.finishedCount, self.skippedCount);
|
||||||
self.completionBlock = nil;
|
self.completionBlock = nil;
|
||||||
}
|
}
|
||||||
|
self.progressBlock = nil;
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)reportStatus
|
- (void)reportStatus {
|
||||||
{
|
|
||||||
NSUInteger total = [self.prefetchURLs count];
|
NSUInteger total = [self.prefetchURLs count];
|
||||||
NSLog(@"Finished prefetching (%d successful, %d skipped, timeElasped %.2f)", total - self.skippedCount, self.skippedCount, CFAbsoluteTimeGetCurrent() - self.startedTime);
|
if ([self.delegate respondsToSelector:@selector(imagePrefetcher:didFinishWithTotalCount:skippedCount:)]) {
|
||||||
|
[self.delegate imagePrefetcher:self
|
||||||
|
didFinishWithTotalCount:(total - self.skippedCount)
|
||||||
|
skippedCount:self.skippedCount
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)prefetchURLs:(NSArray *)urls
|
- (void)prefetchURLs:(NSArray *)urls {
|
||||||
{
|
[self prefetchURLs:urls progress:nil completed:nil];
|
||||||
[self prefetchURLs:urls completed:nil];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)prefetchURLs:(NSArray *)urls completed:(void (^)(NSUInteger, NSUInteger))completionBlock
|
- (void)prefetchURLs:(NSArray *)urls progress:(SDWebImagePrefetcherProgressBlock)progressBlock completed:(SDWebImagePrefetcherCompletionBlock)completionBlock {
|
||||||
{
|
|
||||||
[self cancelPrefetching]; // Prevent duplicate prefetch request
|
[self cancelPrefetching]; // Prevent duplicate prefetch request
|
||||||
self.startedTime = CFAbsoluteTimeGetCurrent();
|
self.startedTime = CFAbsoluteTimeGetCurrent();
|
||||||
self.prefetchURLs = urls;
|
self.prefetchURLs = urls;
|
||||||
self.completionBlock = completionBlock;
|
self.completionBlock = completionBlock;
|
||||||
|
self.progressBlock = progressBlock;
|
||||||
|
|
||||||
// Starts prefetching from the very first image on the list with the max allowed concurrency
|
if (urls.count == 0) {
|
||||||
NSUInteger listCount = self.prefetchURLs.count;
|
if (completionBlock) {
|
||||||
for (NSUInteger i = 0; i < self.maxConcurrentDownloads && self.requestedCount < listCount; i++)
|
completionBlock(0,0);
|
||||||
{
|
}
|
||||||
[self startPrefetchingAtIndex:i];
|
} else {
|
||||||
|
// Starts prefetching from the very first image on the list with the max allowed concurrency
|
||||||
|
NSUInteger listCount = self.prefetchURLs.count;
|
||||||
|
for (NSUInteger i = 0; i < self.maxConcurrentDownloads && self.requestedCount < listCount; i++) {
|
||||||
|
[self startPrefetchingAtIndex:i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)cancelPrefetching
|
- (void)cancelPrefetching {
|
||||||
{
|
|
||||||
self.prefetchURLs = nil;
|
self.prefetchURLs = nil;
|
||||||
self.skippedCount = 0;
|
self.skippedCount = 0;
|
||||||
self.requestedCount = 0;
|
self.requestedCount = 0;
|
||||||
|
|
|
||||||
|
|
@ -14,166 +14,216 @@
|
||||||
*/
|
*/
|
||||||
@interface UIButton (WebCache)
|
@interface UIButton (WebCache)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current image URL.
|
||||||
|
*/
|
||||||
|
- (NSURL *)sd_currentImageURL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the image URL for a control state.
|
||||||
|
*
|
||||||
|
* @param state Which state you want to know the URL for. The values are described in UIControlState.
|
||||||
|
*/
|
||||||
|
- (NSURL *)sd_imageURLForState:(UIControlState)state;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`.
|
* Set the imageView `image` with an `url`.
|
||||||
*
|
*
|
||||||
* The downloand is asynchronous and cached.
|
* The download is asynchronous and cached.
|
||||||
*
|
*
|
||||||
* @param url The url for the image.
|
* @param url The url for the image.
|
||||||
* @param state The state that uses the specified title. The values are described in UIControlState.
|
* @param state The state that uses the specified title. The values are described in UIControlState.
|
||||||
*/
|
*/
|
||||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state;
|
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url` and a placeholder.
|
* Set the imageView `image` with an `url` and a placeholder.
|
||||||
*
|
*
|
||||||
* The downloand is asynchronous and cached.
|
* The download is asynchronous and cached.
|
||||||
*
|
*
|
||||||
* @param url The url for the image.
|
* @param url The url for the image.
|
||||||
* @param state The state that uses the specified title. The values are described in UIControlState.
|
* @param state The state that uses the specified title. The values are described in UIControlState.
|
||||||
* @param placeholder The image to be set initially, until the image request finishes.
|
* @param placeholder The image to be set initially, until the image request finishes.
|
||||||
* @see setImageWithURL:placeholderImage:options:
|
* @see sd_setImageWithURL:placeholderImage:options:
|
||||||
*/
|
*/
|
||||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder;
|
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||||
*
|
*
|
||||||
* The downloand is asynchronous and cached.
|
* The download is asynchronous and cached.
|
||||||
*
|
*
|
||||||
* @param url The url for the image.
|
* @param url The url for the image.
|
||||||
* @param state The state that uses the specified title. The values are described in UIControlState.
|
* @param state The state that uses the specified title. The values are described in UIControlState.
|
||||||
* @param placeholder The image to be set initially, until the image request finishes.
|
* @param placeholder The image to be set initially, until the image request finishes.
|
||||||
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||||
*/
|
*/
|
||||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
|
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`.
|
* Set the imageView `image` with an `url`.
|
||||||
*
|
*
|
||||||
* The downloand is asynchronous and cached.
|
* The download is asynchronous and cached.
|
||||||
*
|
*
|
||||||
* @param url The url for the image.
|
* @param url The url for the image.
|
||||||
* @param state The state that uses the specified title. The values are described in UIControlState.
|
* @param state The state that uses the specified title. The values are described in UIControlState.
|
||||||
* @param completedBlock A block called when operation has been completed. This block as no return value
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||||
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||||
* indicating if the image was retrived from the local cache of from the network.
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
|
* The fourth parameter is the original image url.
|
||||||
*/
|
*/
|
||||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock;
|
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`, placeholder.
|
* Set the imageView `image` with an `url`, placeholder.
|
||||||
*
|
*
|
||||||
* The downloand is asynchronous and cached.
|
* The download is asynchronous and cached.
|
||||||
*
|
*
|
||||||
* @param url The url for the image.
|
* @param url The url for the image.
|
||||||
* @param state The state that uses the specified title. The values are described in UIControlState.
|
* @param state The state that uses the specified title. The values are described in UIControlState.
|
||||||
* @param placeholder The image to be set initially, until the image request finishes.
|
* @param placeholder The image to be set initially, until the image request finishes.
|
||||||
* @param completedBlock A block called when operation has been completed. This block as no return value
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||||
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||||
* indicating if the image was retrived from the local cache of from the network.
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
|
* The fourth parameter is the original image url.
|
||||||
*/
|
*/
|
||||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock;
|
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||||
*
|
*
|
||||||
* The downloand is asynchronous and cached.
|
* The download is asynchronous and cached.
|
||||||
*
|
*
|
||||||
* @param url The url for the image.
|
* @param url The url for the image.
|
||||||
* @param state The state that uses the specified title. The values are described in UIControlState.
|
* @param state The state that uses the specified title. The values are described in UIControlState.
|
||||||
* @param placeholder The image to be set initially, until the image request finishes.
|
* @param placeholder The image to be set initially, until the image request finishes.
|
||||||
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||||
* @param completedBlock A block called when operation has been completed. This block as no return value
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||||
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||||
* indicating if the image was retrived from the local cache of from the network.
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
|
* The fourth parameter is the original image url.
|
||||||
*/
|
*/
|
||||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock;
|
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the backgroundImageView `image` with an `url`.
|
* Set the backgroundImageView `image` with an `url`.
|
||||||
*
|
*
|
||||||
* The downloand is asynchronous and cached.
|
* The download is asynchronous and cached.
|
||||||
*
|
*
|
||||||
* @param url The url for the image.
|
* @param url The url for the image.
|
||||||
* @param state The state that uses the specified title. The values are described in UIControlState.
|
* @param state The state that uses the specified title. The values are described in UIControlState.
|
||||||
*/
|
*/
|
||||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state;
|
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the backgroundImageView `image` with an `url` and a placeholder.
|
* Set the backgroundImageView `image` with an `url` and a placeholder.
|
||||||
*
|
*
|
||||||
* The downloand is asynchronous and cached.
|
* The download is asynchronous and cached.
|
||||||
*
|
*
|
||||||
* @param url The url for the image.
|
* @param url The url for the image.
|
||||||
* @param state The state that uses the specified title. The values are described in UIControlState.
|
* @param state The state that uses the specified title. The values are described in UIControlState.
|
||||||
* @param placeholder The image to be set initially, until the image request finishes.
|
* @param placeholder The image to be set initially, until the image request finishes.
|
||||||
* @see setImageWithURL:placeholderImage:options:
|
* @see sd_setImageWithURL:placeholderImage:options:
|
||||||
*/
|
*/
|
||||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder;
|
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the backgroundImageView `image` with an `url`, placeholder and custom options.
|
* Set the backgroundImageView `image` with an `url`, placeholder and custom options.
|
||||||
*
|
*
|
||||||
* The downloand is asynchronous and cached.
|
* The download is asynchronous and cached.
|
||||||
*
|
*
|
||||||
* @param url The url for the image.
|
* @param url The url for the image.
|
||||||
* @param state The state that uses the specified title. The values are described in UIControlState.
|
* @param state The state that uses the specified title. The values are described in UIControlState.
|
||||||
* @param placeholder The image to be set initially, until the image request finishes.
|
* @param placeholder The image to be set initially, until the image request finishes.
|
||||||
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||||
*/
|
*/
|
||||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
|
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the backgroundImageView `image` with an `url`.
|
* Set the backgroundImageView `image` with an `url`.
|
||||||
*
|
*
|
||||||
* The downloand is asynchronous and cached.
|
* The download is asynchronous and cached.
|
||||||
*
|
*
|
||||||
* @param url The url for the image.
|
* @param url The url for the image.
|
||||||
* @param state The state that uses the specified title. The values are described in UIControlState.
|
* @param state The state that uses the specified title. The values are described in UIControlState.
|
||||||
* @param completedBlock A block object to be executed after the request operation
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
* completed. This block has no return value and takes three argument: the requested
|
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||||
* `UIImage` object, the `NSError` object describing error that occurred, and an
|
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||||
* `SDImageCacheType` enum describing the source of the image obtained from.
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
|
* The fourth parameter is the original image url.
|
||||||
*/
|
*/
|
||||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock;
|
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the backgroundImageView `image` with an `url`, placeholder.
|
* Set the backgroundImageView `image` with an `url`, placeholder.
|
||||||
*
|
*
|
||||||
* The downloand is asynchronous and cached.
|
* The download is asynchronous and cached.
|
||||||
*
|
*
|
||||||
* @param url The url for the image.
|
* @param url The url for the image.
|
||||||
* @param state The state that uses the specified title. The values are described in UIControlState.
|
* @param state The state that uses the specified title. The values are described in UIControlState.
|
||||||
* @param placeholder The image to be set initially, until the image request finishes.
|
* @param placeholder The image to be set initially, until the image request finishes.
|
||||||
* @param completedBlock A block object to be executed after the request operation
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
* completed. This block has no return value and takes three argument: the requested
|
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||||
* `UIImage` object, the `NSError` object describing error that occurred, and an
|
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||||
* `SDImageCacheType` enum describing the source of the image obtained from.
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
|
* The fourth parameter is the original image url.
|
||||||
*/
|
*/
|
||||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock;
|
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the backgroundImageView `image` with an `url`, placeholder and custom options.
|
* Set the backgroundImageView `image` with an `url`, placeholder and custom options.
|
||||||
*
|
*
|
||||||
* The downloand is asynchronous and cached.
|
* The download is asynchronous and cached.
|
||||||
*
|
*
|
||||||
* @param url The url for the image.
|
* @param url The url for the image.
|
||||||
* @param placeholder The image to be set initially, until the image request finishes.
|
* @param placeholder The image to be set initially, until the image request finishes.
|
||||||
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||||
* @param completedBlock A block object to be executed after the request operation
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
* completed. This block has no return value and takes three argument: the requested
|
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||||
* `UIImage` object, the `NSError` object describing error that occurred, and an
|
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||||
* `SDImageCacheType` enum describing the source of the image obtained from.
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
|
* The fourth parameter is the original image url.
|
||||||
*/
|
*/
|
||||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock;
|
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancel the current download
|
* Cancel the current image download
|
||||||
*/
|
*/
|
||||||
- (void)cancelCurrentImageLoad;
|
- (void)sd_cancelImageLoadForState:(UIControlState)state;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancel the current backgroundImage download
|
||||||
|
*/
|
||||||
|
- (void)sd_cancelBackgroundImageLoadForState:(UIControlState)state;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@interface UIButton (WebCacheDeprecated)
|
||||||
|
|
||||||
|
- (NSURL *)currentImageURL __deprecated_msg("Use `sd_currentImageURL`");
|
||||||
|
- (NSURL *)imageURLForState:(UIControlState)state __deprecated_msg("Use `sd_imageURLForState:`");
|
||||||
|
|
||||||
|
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:`");
|
||||||
|
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:`");
|
||||||
|
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:options:`");
|
||||||
|
|
||||||
|
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:completed:`");
|
||||||
|
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:completed:`");
|
||||||
|
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:options:completed:`");
|
||||||
|
|
||||||
|
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:`");
|
||||||
|
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:`");
|
||||||
|
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:options:`");
|
||||||
|
|
||||||
|
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:completed:`");
|
||||||
|
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:completed:`");
|
||||||
|
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:options:completed:`");
|
||||||
|
|
||||||
|
- (void)cancelCurrentImageLoad __deprecated_msg("Use `sd_cancelImageLoadForState:`");
|
||||||
|
- (void)cancelBackgroundImageLoadForState:(UIControlState)state __deprecated_msg("Use `sd_cancelBackgroundImageLoadForState:`");
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -8,146 +8,263 @@
|
||||||
|
|
||||||
#import "UIButton+WebCache.h"
|
#import "UIButton+WebCache.h"
|
||||||
#import "objc/runtime.h"
|
#import "objc/runtime.h"
|
||||||
|
#import "UIView+WebCacheOperation.h"
|
||||||
|
|
||||||
static char operationKey;
|
static char imageURLStorageKey;
|
||||||
|
|
||||||
@implementation UIButton (WebCache)
|
@implementation UIButton (WebCache)
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state
|
- (NSURL *)sd_currentImageURL {
|
||||||
{
|
NSURL *url = self.imageURLStorage[@(self.state)];
|
||||||
[self setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
|
|
||||||
|
if (!url) {
|
||||||
|
url = self.imageURLStorage[@(UIControlStateNormal)];
|
||||||
|
}
|
||||||
|
|
||||||
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder
|
- (NSURL *)sd_imageURLForState:(UIControlState)state {
|
||||||
{
|
return self.imageURLStorage[@(state)];
|
||||||
[self setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options
|
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state {
|
||||||
{
|
[self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
|
||||||
[self setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock
|
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder {
|
||||||
{
|
[self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil];
|
||||||
[self setImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock];
|
|
||||||
}
|
|
||||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock
|
|
||||||
{
|
|
||||||
[self setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock
|
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
||||||
{
|
[self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
|
||||||
[self cancelCurrentImageLoad];
|
}
|
||||||
|
|
||||||
|
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock {
|
||||||
|
[self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock {
|
||||||
|
[self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
|
||||||
|
|
||||||
[self setImage:placeholder forState:state];
|
[self setImage:placeholder forState:state];
|
||||||
|
[self sd_cancelImageLoadForState:state];
|
||||||
|
|
||||||
if (url)
|
if (!url) {
|
||||||
{
|
[self.imageURLStorage removeObjectForKey:@(state)];
|
||||||
__weak UIButton *wself = self;
|
|
||||||
id<SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished)
|
dispatch_main_async_safe(^{
|
||||||
{
|
if (completedBlock) {
|
||||||
if (!wself) return;
|
NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
|
||||||
void (^block)(void) = ^
|
completedBlock(nil, error, SDImageCacheTypeNone, url);
|
||||||
{
|
|
||||||
__strong UIButton *sself = wself;
|
|
||||||
if (!sself) return;
|
|
||||||
if (image)
|
|
||||||
{
|
|
||||||
[sself setImage:image forState:state];
|
|
||||||
}
|
|
||||||
if (completedBlock && finished)
|
|
||||||
{
|
|
||||||
completedBlock(image, error, cacheType);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if ([NSThread isMainThread])
|
|
||||||
{
|
|
||||||
block();
|
|
||||||
}
|
}
|
||||||
else
|
});
|
||||||
{
|
|
||||||
dispatch_sync(dispatch_get_main_queue(), block);
|
return;
|
||||||
}
|
|
||||||
}];
|
|
||||||
objc_setAssociatedObject(self, &operationKey, operation, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.imageURLStorage[@(state)] = url;
|
||||||
|
|
||||||
|
__weak __typeof(self)wself = self;
|
||||||
|
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||||
|
if (!wself) return;
|
||||||
|
dispatch_main_sync_safe(^{
|
||||||
|
__strong UIButton *sself = wself;
|
||||||
|
if (!sself) return;
|
||||||
|
if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock)
|
||||||
|
{
|
||||||
|
completedBlock(image, error, cacheType, url);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (image) {
|
||||||
|
[sself setImage:image forState:state];
|
||||||
|
}
|
||||||
|
if (completedBlock && finished) {
|
||||||
|
completedBlock(image, error, cacheType, url);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}];
|
||||||
|
[self sd_setImageLoadOperation:operation forState:state];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state
|
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state {
|
||||||
{
|
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
|
||||||
[self setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder
|
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder {
|
||||||
{
|
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil];
|
||||||
[self setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options
|
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
||||||
{
|
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
|
||||||
[self setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock
|
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock {
|
||||||
{
|
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock];
|
||||||
[self setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock
|
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock {
|
||||||
{
|
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock];
|
||||||
[self setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock
|
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
|
||||||
{
|
[self sd_cancelBackgroundImageLoadForState:state];
|
||||||
[self cancelCurrentImageLoad];
|
|
||||||
|
|
||||||
[self setBackgroundImage:placeholder forState:state];
|
[self setBackgroundImage:placeholder forState:state];
|
||||||
|
|
||||||
if (url)
|
if (url) {
|
||||||
{
|
__weak __typeof(self)wself = self;
|
||||||
__weak UIButton *wself = self;
|
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||||
id<SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished)
|
|
||||||
{
|
|
||||||
if (!wself) return;
|
if (!wself) return;
|
||||||
void (^block)(void) = ^
|
dispatch_main_sync_safe(^{
|
||||||
{
|
|
||||||
__strong UIButton *sself = wself;
|
__strong UIButton *sself = wself;
|
||||||
if (!sself) return;
|
if (!sself) return;
|
||||||
if (image)
|
if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock)
|
||||||
{
|
{
|
||||||
|
completedBlock(image, error, cacheType, url);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (image) {
|
||||||
[sself setBackgroundImage:image forState:state];
|
[sself setBackgroundImage:image forState:state];
|
||||||
}
|
}
|
||||||
if (completedBlock && finished)
|
if (completedBlock && finished) {
|
||||||
{
|
completedBlock(image, error, cacheType, url);
|
||||||
completedBlock(image, error, cacheType);
|
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
if ([NSThread isMainThread])
|
|
||||||
{
|
|
||||||
block();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dispatch_sync(dispatch_get_main_queue(), block);
|
|
||||||
}
|
|
||||||
}];
|
}];
|
||||||
objc_setAssociatedObject(self, &operationKey, operation, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
[self sd_setBackgroundImageLoadOperation:operation forState:state];
|
||||||
|
} else {
|
||||||
|
dispatch_main_async_safe(^{
|
||||||
|
NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
|
||||||
|
if (completedBlock) {
|
||||||
|
completedBlock(nil, error, SDImageCacheTypeNone, url);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)sd_setImageLoadOperation:(id<SDWebImageOperation>)operation forState:(UIControlState)state {
|
||||||
|
[self sd_setImageLoadOperation:operation forKey:[NSString stringWithFormat:@"UIButtonImageOperation%@", @(state)]];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)cancelCurrentImageLoad
|
- (void)sd_cancelImageLoadForState:(UIControlState)state {
|
||||||
{
|
[self sd_cancelImageLoadOperationWithKey:[NSString stringWithFormat:@"UIButtonImageOperation%@", @(state)]];
|
||||||
// Cancel in progress downloader from queue
|
}
|
||||||
id<SDWebImageOperation> operation = objc_getAssociatedObject(self, &operationKey);
|
|
||||||
if (operation)
|
- (void)sd_setBackgroundImageLoadOperation:(id<SDWebImageOperation>)operation forState:(UIControlState)state {
|
||||||
|
[self sd_setImageLoadOperation:operation forKey:[NSString stringWithFormat:@"UIButtonBackgroundImageOperation%@", @(state)]];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)sd_cancelBackgroundImageLoadForState:(UIControlState)state {
|
||||||
|
[self sd_cancelImageLoadOperationWithKey:[NSString stringWithFormat:@"UIButtonBackgroundImageOperation%@", @(state)]];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSMutableDictionary *)imageURLStorage {
|
||||||
|
NSMutableDictionary *storage = objc_getAssociatedObject(self, &imageURLStorageKey);
|
||||||
|
if (!storage)
|
||||||
{
|
{
|
||||||
[operation cancel];
|
storage = [NSMutableDictionary dictionary];
|
||||||
objc_setAssociatedObject(self, &operationKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
objc_setAssociatedObject(self, &imageURLStorageKey, storage, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return storage;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@implementation UIButton (WebCacheDeprecated)
|
||||||
|
|
||||||
|
- (NSURL *)currentImageURL {
|
||||||
|
return [self sd_currentImageURL];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSURL *)imageURLForState:(UIControlState)state {
|
||||||
|
return [self sd_imageURLForState:state];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state {
|
||||||
|
[self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder {
|
||||||
|
[self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
||||||
|
[self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock {
|
||||||
|
[self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||||
|
if (completedBlock) {
|
||||||
|
completedBlock(image, error, cacheType);
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock {
|
||||||
|
[self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||||
|
if (completedBlock) {
|
||||||
|
completedBlock(image, error, cacheType);
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
|
||||||
|
[self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||||
|
if (completedBlock) {
|
||||||
|
completedBlock(image, error, cacheType);
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state {
|
||||||
|
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder {
|
||||||
|
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
||||||
|
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock {
|
||||||
|
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||||
|
if (completedBlock) {
|
||||||
|
completedBlock(image, error, cacheType);
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock {
|
||||||
|
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||||
|
if (completedBlock) {
|
||||||
|
completedBlock(image, error, cacheType);
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
|
||||||
|
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||||
|
if (completedBlock) {
|
||||||
|
completedBlock(image, error, cacheType);
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)cancelCurrentImageLoad {
|
||||||
|
// in a backwards compatible manner, cancel for current state
|
||||||
|
[self sd_cancelImageLoadForState:self.state];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)cancelBackgroundImageLoadForState:(UIControlState)state {
|
||||||
|
[self sd_cancelBackgroundImageLoadForState:state];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,12 @@
|
||||||
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
|
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#import "NSData+GIF.h"
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
@interface UIImage (GIF)
|
@interface UIImage (GIF)
|
||||||
|
|
||||||
+ (UIImage *)sd_animatedGIFNamed:(NSString *)name;
|
+ (UIImage *)sd_animatedGIFNamed:(NSString *)name;
|
||||||
|
|
||||||
+ (UIImage *)sd_animatedGIFWithData:(NSData *)data;
|
+ (UIImage *)sd_animatedGIFWithData:(NSData *)data;
|
||||||
|
|
||||||
- (UIImage *)sd_animatedImageByScalingAndCroppingToSize:(CGSize)size;
|
- (UIImage *)sd_animatedImageByScalingAndCroppingToSize:(CGSize)size;
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,8 @@
|
||||||
|
|
||||||
@implementation UIImage (GIF)
|
@implementation UIImage (GIF)
|
||||||
|
|
||||||
+ (UIImage *)sd_animatedGIFWithData:(NSData *)data
|
+ (UIImage *)sd_animatedGIFWithData:(NSData *)data {
|
||||||
{
|
if (!data) {
|
||||||
if (!data)
|
|
||||||
{
|
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -24,31 +22,29 @@
|
||||||
|
|
||||||
UIImage *animatedImage;
|
UIImage *animatedImage;
|
||||||
|
|
||||||
if (count <= 1)
|
if (count <= 1) {
|
||||||
{
|
|
||||||
animatedImage = [[UIImage alloc] initWithData:data];
|
animatedImage = [[UIImage alloc] initWithData:data];
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
NSMutableArray *images = [NSMutableArray array];
|
NSMutableArray *images = [NSMutableArray array];
|
||||||
|
|
||||||
NSTimeInterval duration = 0.0f;
|
NSTimeInterval duration = 0.0f;
|
||||||
|
|
||||||
for (size_t i = 0; i < count; i++)
|
for (size_t i = 0; i < count; i++) {
|
||||||
{
|
|
||||||
CGImageRef image = CGImageSourceCreateImageAtIndex(source, i, NULL);
|
CGImageRef image = CGImageSourceCreateImageAtIndex(source, i, NULL);
|
||||||
|
if (!image) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
NSDictionary *frameProperties = CFBridgingRelease(CGImageSourceCopyPropertiesAtIndex(source, i, NULL));
|
duration += [self sd_frameDurationAtIndex:i source:source];
|
||||||
duration += [[[frameProperties objectForKey:(NSString*)kCGImagePropertyGIFDictionary] objectForKey:(NSString*)kCGImagePropertyGIFDelayTime] doubleValue];
|
|
||||||
|
|
||||||
[images addObject:[UIImage imageWithCGImage:image scale:[UIScreen mainScreen].scale orientation:UIImageOrientationUp]];
|
[images addObject:[UIImage imageWithCGImage:image scale:[UIScreen mainScreen].scale orientation:UIImageOrientationUp]];
|
||||||
|
|
||||||
CGImageRelease(image);
|
CGImageRelease(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!duration)
|
if (!duration) {
|
||||||
{
|
duration = (1.0f / 10.0f) * count;
|
||||||
duration = (1.0f/10.0f)*count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
animatedImage = [UIImage animatedImageWithImages:images duration:duration];
|
animatedImage = [UIImage animatedImageWithImages:images duration:duration];
|
||||||
|
|
@ -59,18 +55,46 @@
|
||||||
return animatedImage;
|
return animatedImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (UIImage *)sd_animatedGIFNamed:(NSString *)name
|
+ (float)sd_frameDurationAtIndex:(NSUInteger)index source:(CGImageSourceRef)source {
|
||||||
{
|
float frameDuration = 0.1f;
|
||||||
|
CFDictionaryRef cfFrameProperties = CGImageSourceCopyPropertiesAtIndex(source, index, nil);
|
||||||
|
NSDictionary *frameProperties = (__bridge NSDictionary *)cfFrameProperties;
|
||||||
|
NSDictionary *gifProperties = frameProperties[(NSString *)kCGImagePropertyGIFDictionary];
|
||||||
|
|
||||||
|
NSNumber *delayTimeUnclampedProp = gifProperties[(NSString *)kCGImagePropertyGIFUnclampedDelayTime];
|
||||||
|
if (delayTimeUnclampedProp) {
|
||||||
|
frameDuration = [delayTimeUnclampedProp floatValue];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
NSNumber *delayTimeProp = gifProperties[(NSString *)kCGImagePropertyGIFDelayTime];
|
||||||
|
if (delayTimeProp) {
|
||||||
|
frameDuration = [delayTimeProp floatValue];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Many annoying ads specify a 0 duration to make an image flash as quickly as possible.
|
||||||
|
// We follow Firefox's behavior and use a duration of 100 ms for any frames that specify
|
||||||
|
// a duration of <= 10 ms. See <rdar://problem/7689300> and <http://webkit.org/b/36082>
|
||||||
|
// for more information.
|
||||||
|
|
||||||
|
if (frameDuration < 0.011f) {
|
||||||
|
frameDuration = 0.100f;
|
||||||
|
}
|
||||||
|
|
||||||
|
CFRelease(cfFrameProperties);
|
||||||
|
return frameDuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (UIImage *)sd_animatedGIFNamed:(NSString *)name {
|
||||||
CGFloat scale = [UIScreen mainScreen].scale;
|
CGFloat scale = [UIScreen mainScreen].scale;
|
||||||
|
|
||||||
if (scale > 1.0f)
|
if (scale > 1.0f) {
|
||||||
{
|
|
||||||
NSString *retinaPath = [[NSBundle mainBundle] pathForResource:[name stringByAppendingString:@"@2x"] ofType:@"gif"];
|
NSString *retinaPath = [[NSBundle mainBundle] pathForResource:[name stringByAppendingString:@"@2x"] ofType:@"gif"];
|
||||||
|
|
||||||
NSData *data = [NSData dataWithContentsOfFile:retinaPath];
|
NSData *data = [NSData dataWithContentsOfFile:retinaPath];
|
||||||
|
|
||||||
if (data)
|
if (data) {
|
||||||
{
|
|
||||||
return [UIImage sd_animatedGIFWithData:data];
|
return [UIImage sd_animatedGIFWithData:data];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -78,21 +102,18 @@
|
||||||
|
|
||||||
data = [NSData dataWithContentsOfFile:path];
|
data = [NSData dataWithContentsOfFile:path];
|
||||||
|
|
||||||
if (data)
|
if (data) {
|
||||||
{
|
|
||||||
return [UIImage sd_animatedGIFWithData:data];
|
return [UIImage sd_animatedGIFWithData:data];
|
||||||
}
|
}
|
||||||
|
|
||||||
return [UIImage imageNamed:name];
|
return [UIImage imageNamed:name];
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"gif"];
|
NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"gif"];
|
||||||
|
|
||||||
NSData *data = [NSData dataWithContentsOfFile:path];
|
NSData *data = [NSData dataWithContentsOfFile:path];
|
||||||
|
|
||||||
if (data)
|
if (data) {
|
||||||
{
|
|
||||||
return [UIImage sd_animatedGIFWithData:data];
|
return [UIImage sd_animatedGIFWithData:data];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -100,46 +121,41 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (UIImage *)sd_animatedImageByScalingAndCroppingToSize:(CGSize)size
|
- (UIImage *)sd_animatedImageByScalingAndCroppingToSize:(CGSize)size {
|
||||||
{
|
if (CGSizeEqualToSize(self.size, size) || CGSizeEqualToSize(size, CGSizeZero)) {
|
||||||
if (CGSizeEqualToSize(self.size, size) || CGSizeEqualToSize(size, CGSizeZero))
|
|
||||||
{
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
CGSize scaledSize = size;
|
CGSize scaledSize = size;
|
||||||
CGPoint thumbnailPoint = CGPointZero;
|
CGPoint thumbnailPoint = CGPointZero;
|
||||||
|
|
||||||
CGFloat widthFactor = size.width / self.size.width;
|
CGFloat widthFactor = size.width / self.size.width;
|
||||||
CGFloat heightFactor = size.height / self.size.height;
|
CGFloat heightFactor = size.height / self.size.height;
|
||||||
CGFloat scaleFactor = (widthFactor > heightFactor) ? widthFactor :heightFactor;
|
CGFloat scaleFactor = (widthFactor > heightFactor) ? widthFactor : heightFactor;
|
||||||
scaledSize.width = self.size.width * scaleFactor;
|
scaledSize.width = self.size.width * scaleFactor;
|
||||||
scaledSize.height = self.size.height * scaleFactor;
|
scaledSize.height = self.size.height * scaleFactor;
|
||||||
|
|
||||||
if (widthFactor > heightFactor)
|
if (widthFactor > heightFactor) {
|
||||||
{
|
|
||||||
thumbnailPoint.y = (size.height - scaledSize.height) * 0.5;
|
thumbnailPoint.y = (size.height - scaledSize.height) * 0.5;
|
||||||
}
|
}
|
||||||
else if (widthFactor < heightFactor)
|
else if (widthFactor < heightFactor) {
|
||||||
{
|
|
||||||
thumbnailPoint.x = (size.width - scaledSize.width) * 0.5;
|
thumbnailPoint.x = (size.width - scaledSize.width) * 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSMutableArray *scaledImages = [NSMutableArray array];
|
NSMutableArray *scaledImages = [NSMutableArray array];
|
||||||
|
|
||||||
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
|
for (UIImage *image in self.images) {
|
||||||
|
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
|
||||||
|
|
||||||
for (UIImage *image in self.images)
|
|
||||||
{
|
|
||||||
[image drawInRect:CGRectMake(thumbnailPoint.x, thumbnailPoint.y, scaledSize.width, scaledSize.height)];
|
[image drawInRect:CGRectMake(thumbnailPoint.x, thumbnailPoint.y, scaledSize.width, scaledSize.height)];
|
||||||
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
|
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
|
||||||
|
|
||||||
[scaledImages addObject:newImage];
|
[scaledImages addObject:newImage];
|
||||||
|
|
||||||
|
UIGraphicsEndImageContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
UIGraphicsEndImageContext();
|
return [UIImage animatedImageWithImages:scaledImages duration:self.duration];
|
||||||
|
|
||||||
return [UIImage animatedImageWithImages:scaledImages duration:self.duration];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -8,31 +8,111 @@
|
||||||
|
|
||||||
#import "UIImage+MultiFormat.h"
|
#import "UIImage+MultiFormat.h"
|
||||||
#import "UIImage+GIF.h"
|
#import "UIImage+GIF.h"
|
||||||
|
#import "NSData+ImageContentType.h"
|
||||||
|
#import <ImageIO/ImageIO.h>
|
||||||
|
|
||||||
|
#ifdef SD_WEBP
|
||||||
#import "UIImage+WebP.h"
|
#import "UIImage+WebP.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
@implementation UIImage (MultiFormat)
|
@implementation UIImage (MultiFormat)
|
||||||
|
|
||||||
+ (UIImage *)sd_imageWithData:(NSData *)data
|
+ (UIImage *)sd_imageWithData:(NSData *)data {
|
||||||
{
|
if (!data) {
|
||||||
UIImage *image;
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
if ([data sd_isGIF])
|
UIImage *image;
|
||||||
{
|
NSString *imageContentType = [NSData sd_contentTypeForImageData:data];
|
||||||
|
if ([imageContentType isEqualToString:@"image/gif"]) {
|
||||||
image = [UIImage sd_animatedGIFWithData:data];
|
image = [UIImage sd_animatedGIFWithData:data];
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
image = [[UIImage alloc] initWithData:data];
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef SD_WEBP
|
#ifdef SD_WEBP
|
||||||
if (!image) // TODO: detect webp signature
|
else if ([imageContentType isEqualToString:@"image/webp"])
|
||||||
{
|
{
|
||||||
image = [UIImage sd_imageWithWebPData:data];
|
image = [UIImage sd_imageWithWebPData:data];
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
else {
|
||||||
|
image = [[UIImage alloc] initWithData:data];
|
||||||
|
UIImageOrientation orientation = [self sd_imageOrientationFromImageData:data];
|
||||||
|
if (orientation != UIImageOrientationUp) {
|
||||||
|
image = [UIImage imageWithCGImage:image.CGImage
|
||||||
|
scale:image.scale
|
||||||
|
orientation:orientation];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
+(UIImageOrientation)sd_imageOrientationFromImageData:(NSData *)imageData {
|
||||||
|
UIImageOrientation result = UIImageOrientationUp;
|
||||||
|
CGImageSourceRef imageSource = CGImageSourceCreateWithData((__bridge CFDataRef)imageData, NULL);
|
||||||
|
if (imageSource) {
|
||||||
|
CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL);
|
||||||
|
if (properties) {
|
||||||
|
CFTypeRef val;
|
||||||
|
int exifOrientation;
|
||||||
|
val = CFDictionaryGetValue(properties, kCGImagePropertyOrientation);
|
||||||
|
if (val) {
|
||||||
|
CFNumberGetValue(val, kCFNumberIntType, &exifOrientation);
|
||||||
|
result = [self sd_exifOrientationToiOSOrientation:exifOrientation];
|
||||||
|
} // else - if it's not set it remains at up
|
||||||
|
CFRelease((CFTypeRef) properties);
|
||||||
|
} else {
|
||||||
|
//NSLog(@"NO PROPERTIES, FAIL");
|
||||||
|
}
|
||||||
|
CFRelease(imageSource);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark EXIF orientation tag converter
|
||||||
|
// Convert an EXIF image orientation to an iOS one.
|
||||||
|
// reference see here: http://sylvana.net/jpegcrop/exif_orientation.html
|
||||||
|
+ (UIImageOrientation) sd_exifOrientationToiOSOrientation:(int)exifOrientation {
|
||||||
|
UIImageOrientation orientation = UIImageOrientationUp;
|
||||||
|
switch (exifOrientation) {
|
||||||
|
case 1:
|
||||||
|
orientation = UIImageOrientationUp;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
orientation = UIImageOrientationDown;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 8:
|
||||||
|
orientation = UIImageOrientationLeft;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 6:
|
||||||
|
orientation = UIImageOrientationRight;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
orientation = UIImageOrientationUpMirrored;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
orientation = UIImageOrientationDownMirrored;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 5:
|
||||||
|
orientation = UIImageOrientationLeftMirrored;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 7:
|
||||||
|
orientation = UIImageOrientationRightMirrored;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return orientation;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,14 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifdef SD_WEBP
|
#ifdef SD_WEBP
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
// Fix for issue #416 Undefined symbols for architecture armv7 since WebP introduction when deploying to device
|
// Fix for issue #416 Undefined symbols for architecture armv7 since WebP introduction when deploying to device
|
||||||
void WebPInitPremultiplyNEON(void);
|
void WebPInitPremultiplyNEON(void);
|
||||||
|
|
||||||
void WebPInitUpsamplersNEON(void);
|
void WebPInitUpsamplersNEON(void);
|
||||||
|
|
||||||
void VP8DspInitNEON(void);
|
void VP8DspInitNEON(void);
|
||||||
|
|
||||||
@interface UIImage (WebP)
|
@interface UIImage (WebP)
|
||||||
|
|
@ -19,4 +22,5 @@ void VP8DspInitNEON(void);
|
||||||
+ (UIImage *)sd_imageWithWebPData:(NSData *)data;
|
+ (UIImage *)sd_imageWithWebPData:(NSData *)data;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,12 @@
|
||||||
|
|
||||||
#ifdef SD_WEBP
|
#ifdef SD_WEBP
|
||||||
#import "UIImage+WebP.h"
|
#import "UIImage+WebP.h"
|
||||||
|
|
||||||
|
#if !COCOAPODS
|
||||||
#import "webp/decode.h"
|
#import "webp/decode.h"
|
||||||
|
#else
|
||||||
|
#import "webp/decode.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
// Callback for CGDataProviderRelease
|
// Callback for CGDataProviderRelease
|
||||||
static void FreeImageData(void *info, const void *data, size_t size)
|
static void FreeImageData(void *info, const void *data, size_t size)
|
||||||
|
|
@ -18,27 +23,27 @@ static void FreeImageData(void *info, const void *data, size_t size)
|
||||||
|
|
||||||
@implementation UIImage (WebP)
|
@implementation UIImage (WebP)
|
||||||
|
|
||||||
+ (UIImage *)sd_imageWithWebPData:(NSData *)data
|
+ (UIImage *)sd_imageWithWebPData:(NSData *)data {
|
||||||
{
|
|
||||||
WebPDecoderConfig config;
|
WebPDecoderConfig config;
|
||||||
if (!WebPInitDecoderConfig(&config))
|
if (!WebPInitDecoderConfig(&config)) {
|
||||||
{
|
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
config.output.colorspace = MODE_rgbA;
|
if (WebPGetFeatures(data.bytes, data.length, &config.input) != VP8_STATUS_OK) {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
config.output.colorspace = config.input.has_alpha ? MODE_rgbA : MODE_RGB;
|
||||||
config.options.use_threads = 1;
|
config.options.use_threads = 1;
|
||||||
|
|
||||||
// Decode the WebP image data into a RGBA value array.
|
// Decode the WebP image data into a RGBA value array.
|
||||||
if (WebPDecode(data.bytes, data.length, &config) != VP8_STATUS_OK)
|
if (WebPDecode(data.bytes, data.length, &config) != VP8_STATUS_OK) {
|
||||||
{
|
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
int width = config.input.width;
|
int width = config.input.width;
|
||||||
int height = config.input.height;
|
int height = config.input.height;
|
||||||
if (config.options.use_scaling)
|
if (config.options.use_scaling) {
|
||||||
{
|
|
||||||
width = config.options.scaled_width;
|
width = config.options.scaled_width;
|
||||||
height = config.options.scaled_height;
|
height = config.options.scaled_height;
|
||||||
}
|
}
|
||||||
|
|
@ -47,9 +52,10 @@ static void FreeImageData(void *info, const void *data, size_t size)
|
||||||
CGDataProviderRef provider =
|
CGDataProviderRef provider =
|
||||||
CGDataProviderCreateWithData(NULL, config.output.u.RGBA.rgba, config.output.u.RGBA.size, FreeImageData);
|
CGDataProviderCreateWithData(NULL, config.output.u.RGBA.rgba, config.output.u.RGBA.size, FreeImageData);
|
||||||
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
|
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
|
||||||
CGBitmapInfo bitmapInfo = kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast;
|
CGBitmapInfo bitmapInfo = config.input.has_alpha ? kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast : 0;
|
||||||
|
size_t components = config.input.has_alpha ? 4 : 3;
|
||||||
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
|
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
|
||||||
CGImageRef imageRef = CGImageCreate(width, height, 8, 32, 4 * width, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);
|
CGImageRef imageRef = CGImageCreate(width, height, 8, components * 8, components * width, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);
|
||||||
|
|
||||||
CGColorSpaceRelease(colorSpaceRef);
|
CGColorSpaceRelease(colorSpaceRef);
|
||||||
CGDataProviderRelease(provider);
|
CGDataProviderRelease(provider);
|
||||||
|
|
@ -62,8 +68,11 @@ static void FreeImageData(void *info, const void *data, size_t size)
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
#if !COCOAPODS
|
||||||
// Functions to resolve some undefined symbols when using WebP and force_load flag
|
// Functions to resolve some undefined symbols when using WebP and force_load flag
|
||||||
void WebPInitPremultiplyNEON(void) {}
|
void WebPInitPremultiplyNEON(void) {}
|
||||||
void WebPInitUpsamplersNEON(void) {}
|
void WebPInitUpsamplersNEON(void) {}
|
||||||
void VP8DspInitNEON(void) {}
|
void VP8DspInitNEON(void) {}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,100 @@
|
||||||
|
/*
|
||||||
|
* This file is part of the SDWebImage package.
|
||||||
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#import <UIKit/UIKit.h>
|
||||||
|
#import "SDWebImageCompat.h"
|
||||||
|
#import "SDWebImageManager.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Integrates SDWebImage async downloading and caching of remote images with UIImageView for highlighted state.
|
||||||
|
*/
|
||||||
|
@interface UIImageView (HighlightedWebCache)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the imageView `highlightedImage` with an `url`.
|
||||||
|
*
|
||||||
|
* The download is asynchronous and cached.
|
||||||
|
*
|
||||||
|
* @param url The url for the image.
|
||||||
|
*/
|
||||||
|
- (void)sd_setHighlightedImageWithURL:(NSURL *)url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the imageView `highlightedImage` with an `url` and custom options.
|
||||||
|
*
|
||||||
|
* The download is asynchronous and cached.
|
||||||
|
*
|
||||||
|
* @param url The url for the image.
|
||||||
|
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||||
|
*/
|
||||||
|
- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the imageView `highlightedImage` with an `url`.
|
||||||
|
*
|
||||||
|
* The download is asynchronous and cached.
|
||||||
|
*
|
||||||
|
* @param url The url for the image.
|
||||||
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
|
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||||
|
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||||
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
|
* The fourth parameter is the original image url.
|
||||||
|
*/
|
||||||
|
- (void)sd_setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the imageView `highlightedImage` with an `url` and custom options.
|
||||||
|
*
|
||||||
|
* The download is asynchronous and cached.
|
||||||
|
*
|
||||||
|
* @param url The url for the image.
|
||||||
|
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||||
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
|
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||||
|
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||||
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
|
* The fourth parameter is the original image url.
|
||||||
|
*/
|
||||||
|
- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the imageView `highlightedImage` with an `url` and custom options.
|
||||||
|
*
|
||||||
|
* The download is asynchronous and cached.
|
||||||
|
*
|
||||||
|
* @param url The url for the image.
|
||||||
|
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||||
|
* @param progressBlock A block called while image is downloading
|
||||||
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
|
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||||
|
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||||
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
|
* The fourth parameter is the original image url.
|
||||||
|
*/
|
||||||
|
- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancel the current download
|
||||||
|
*/
|
||||||
|
- (void)sd_cancelCurrentHighlightedImageLoad;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@interface UIImageView (HighlightedWebCacheDeprecated)
|
||||||
|
|
||||||
|
- (void)setHighlightedImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:`");
|
||||||
|
- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:`");
|
||||||
|
- (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:completed:`");
|
||||||
|
- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:completed:`");
|
||||||
|
- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:progress:completed:`");
|
||||||
|
|
||||||
|
- (void)cancelCurrentHighlightedImageLoad __deprecated_msg("Use `sd_cancelCurrentHighlightedImageLoad`");
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
@ -0,0 +1,112 @@
|
||||||
|
/*
|
||||||
|
* This file is part of the SDWebImage package.
|
||||||
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#import "UIImageView+HighlightedWebCache.h"
|
||||||
|
#import "UIView+WebCacheOperation.h"
|
||||||
|
|
||||||
|
#define UIImageViewHighlightedWebCacheOperationKey @"highlightedImage"
|
||||||
|
|
||||||
|
@implementation UIImageView (HighlightedWebCache)
|
||||||
|
|
||||||
|
- (void)sd_setHighlightedImageWithURL:(NSURL *)url {
|
||||||
|
[self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options {
|
||||||
|
[self sd_setHighlightedImageWithURL:url options:options progress:nil completed:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)sd_setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock {
|
||||||
|
[self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:completedBlock];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
|
||||||
|
[self sd_setHighlightedImageWithURL:url options:options progress:nil completed:completedBlock];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock {
|
||||||
|
[self sd_cancelCurrentHighlightedImageLoad];
|
||||||
|
|
||||||
|
if (url) {
|
||||||
|
__weak __typeof(self)wself = self;
|
||||||
|
id<SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||||
|
if (!wself) return;
|
||||||
|
dispatch_main_sync_safe (^
|
||||||
|
{
|
||||||
|
if (!wself) return;
|
||||||
|
if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock)
|
||||||
|
{
|
||||||
|
completedBlock(image, error, cacheType, url);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (image) {
|
||||||
|
wself.highlightedImage = image;
|
||||||
|
[wself setNeedsLayout];
|
||||||
|
}
|
||||||
|
if (completedBlock && finished) {
|
||||||
|
completedBlock(image, error, cacheType, url);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}];
|
||||||
|
[self sd_setImageLoadOperation:operation forKey:UIImageViewHighlightedWebCacheOperationKey];
|
||||||
|
} else {
|
||||||
|
dispatch_main_async_safe(^{
|
||||||
|
NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
|
||||||
|
if (completedBlock) {
|
||||||
|
completedBlock(nil, error, SDImageCacheTypeNone, url);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)sd_cancelCurrentHighlightedImageLoad {
|
||||||
|
[self sd_cancelImageLoadOperationWithKey:UIImageViewHighlightedWebCacheOperationKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@implementation UIImageView (HighlightedWebCacheDeprecated)
|
||||||
|
|
||||||
|
- (void)setHighlightedImageWithURL:(NSURL *)url {
|
||||||
|
[self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options {
|
||||||
|
[self sd_setHighlightedImageWithURL:url options:options progress:nil completed:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock {
|
||||||
|
[self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||||
|
if (completedBlock) {
|
||||||
|
completedBlock(image, error, cacheType);
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
|
||||||
|
[self sd_setHighlightedImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||||
|
if (completedBlock) {
|
||||||
|
completedBlock(image, error, cacheType);
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock {
|
||||||
|
[self sd_setHighlightedImageWithURL:url options:0 progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||||
|
if (completedBlock) {
|
||||||
|
completedBlock(image, error, cacheType);
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)cancelCurrentHighlightedImageLoad {
|
||||||
|
[self sd_cancelCurrentHighlightedImageLoad];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
@ -26,16 +26,15 @@
|
||||||
|
|
||||||
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
|
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
|
||||||
|
|
||||||
if (cell == nil)
|
if (cell == nil) {
|
||||||
{
|
|
||||||
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier]
|
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier]
|
||||||
autorelease];
|
autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Here we use the provided setImageWithURL: method to load the web image
|
// Here we use the provided sd_setImageWithURL: method to load the web image
|
||||||
// Ensure you use a placeholder image otherwise cells will be initialized with no image
|
// Ensure you use a placeholder image otherwise cells will be initialized with no image
|
||||||
[cell.imageView setImageWithURL:[NSURL URLWithString:@"http://example.com/image.jpg"]
|
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://example.com/image.jpg"]
|
||||||
placeholderImage:[UIImage imageNamed:@"placeholder"]];
|
placeholderImage:[UIImage imageNamed:@"placeholder"]];
|
||||||
|
|
||||||
cell.textLabel.text = @"My Text";
|
cell.textLabel.text = @"My Text";
|
||||||
return cell;
|
return cell;
|
||||||
|
|
@ -45,98 +44,172 @@
|
||||||
*/
|
*/
|
||||||
@interface UIImageView (WebCache)
|
@interface UIImageView (WebCache)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current image URL.
|
||||||
|
*
|
||||||
|
* Note that because of the limitations of categories this property can get out of sync
|
||||||
|
* if you use sd_setImage: directly.
|
||||||
|
*/
|
||||||
|
- (NSURL *)sd_imageURL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`.
|
* Set the imageView `image` with an `url`.
|
||||||
*
|
*
|
||||||
* The downloand is asynchronous and cached.
|
* The download is asynchronous and cached.
|
||||||
*
|
*
|
||||||
* @param url The url for the image.
|
* @param url The url for the image.
|
||||||
*/
|
*/
|
||||||
- (void)setImageWithURL:(NSURL *)url;
|
- (void)sd_setImageWithURL:(NSURL *)url;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url` and a placeholder.
|
* Set the imageView `image` with an `url` and a placeholder.
|
||||||
*
|
*
|
||||||
* The downloand is asynchronous and cached.
|
* The download is asynchronous and cached.
|
||||||
*
|
*
|
||||||
* @param url The url for the image.
|
* @param url The url for the image.
|
||||||
* @param placeholder The image to be set initially, until the image request finishes.
|
* @param placeholder The image to be set initially, until the image request finishes.
|
||||||
* @see setImageWithURL:placeholderImage:options:
|
* @see sd_setImageWithURL:placeholderImage:options:
|
||||||
*/
|
*/
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder;
|
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||||
*
|
*
|
||||||
* The downloand is asynchronous and cached.
|
* The download is asynchronous and cached.
|
||||||
*
|
*
|
||||||
* @param url The url for the image.
|
* @param url The url for the image.
|
||||||
* @param placeholder The image to be set initially, until the image request finishes.
|
* @param placeholder The image to be set initially, until the image request finishes.
|
||||||
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||||
*/
|
*/
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
|
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`.
|
* Set the imageView `image` with an `url`.
|
||||||
*
|
*
|
||||||
* The downloand is asynchronous and cached.
|
* The download is asynchronous and cached.
|
||||||
*
|
*
|
||||||
* @param url The url for the image.
|
* @param url The url for the image.
|
||||||
* @param completedBlock A block called when operation has been completed. This block as no return value
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||||
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||||
* indicating if the image was retrived from the local cache of from the network.
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
|
* The fourth parameter is the original image url.
|
||||||
*/
|
*/
|
||||||
- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock;
|
- (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`, placeholder.
|
* Set the imageView `image` with an `url`, placeholder.
|
||||||
*
|
*
|
||||||
* The downloand is asynchronous and cached.
|
* The download is asynchronous and cached.
|
||||||
*
|
*
|
||||||
* @param url The url for the image.
|
* @param url The url for the image.
|
||||||
* @param placeholder The image to be set initially, until the image request finishes.
|
* @param placeholder The image to be set initially, until the image request finishes.
|
||||||
* @param completedBlock A block called when operation has been completed. This block as no return value
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||||
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||||
* indicating if the image was retrived from the local cache of from the network.
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
|
* The fourth parameter is the original image url.
|
||||||
*/
|
*/
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock;
|
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||||
*
|
*
|
||||||
* The downloand is asynchronous and cached.
|
* The download is asynchronous and cached.
|
||||||
*
|
*
|
||||||
* @param url The url for the image.
|
* @param url The url for the image.
|
||||||
* @param placeholder The image to be set initially, until the image request finishes.
|
* @param placeholder The image to be set initially, until the image request finishes.
|
||||||
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||||
* @param completedBlock A block called when operation has been completed. This block as no return value
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||||
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||||
* indicating if the image was retrived from the local cache of from the network.
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
|
* The fourth parameter is the original image url.
|
||||||
*/
|
*/
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock;
|
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||||
*
|
*
|
||||||
* The downloand is asynchronous and cached.
|
* The download is asynchronous and cached.
|
||||||
*
|
*
|
||||||
* @param url The url for the image.
|
* @param url The url for the image.
|
||||||
* @param placeholder The image to be set initially, until the image request finishes.
|
* @param placeholder The image to be set initially, until the image request finishes.
|
||||||
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||||
* @param progressBlock A block called while image is downloading
|
* @param progressBlock A block called while image is downloading
|
||||||
* @param completedBlock A block called when operation has been completed. This block as no return value
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||||
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||||
* indicating if the image was retrived from the local cache of from the network.
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
|
* The fourth parameter is the original image url.
|
||||||
*/
|
*/
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock;
|
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the imageView `image` with an `url` and optionally a placeholder image.
|
||||||
|
*
|
||||||
|
* The download is asynchronous and cached.
|
||||||
|
*
|
||||||
|
* @param url The url for the image.
|
||||||
|
* @param placeholder The image to be set initially, until the image request finishes.
|
||||||
|
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||||
|
* @param progressBlock A block called while image is downloading
|
||||||
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
|
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||||
|
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||||
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
|
* The fourth parameter is the original image url.
|
||||||
|
*/
|
||||||
|
- (void)sd_setImageWithPreviousCachedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Download an array of images and starts them in an animation loop
|
||||||
|
*
|
||||||
|
* @param arrayOfURLs An array of NSURL
|
||||||
|
*/
|
||||||
|
- (void)sd_setAnimationImagesWithURLs:(NSArray *)arrayOfURLs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancel the current download
|
* Cancel the current download
|
||||||
*/
|
*/
|
||||||
- (void)cancelCurrentImageLoad;
|
- (void)sd_cancelCurrentImageLoad;
|
||||||
|
|
||||||
|
- (void)sd_cancelCurrentAnimationImagesLoad;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show activity UIActivityIndicatorView
|
||||||
|
*/
|
||||||
|
- (void)setShowActivityIndicatorView:(BOOL)show;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set desired UIActivityIndicatorViewStyle
|
||||||
|
*
|
||||||
|
* @param style The style of the UIActivityIndicatorView
|
||||||
|
*/
|
||||||
|
- (void)setIndicatorStyle:(UIActivityIndicatorViewStyle)style;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@interface UIImageView (WebCacheDeprecated)
|
||||||
|
|
||||||
|
- (NSURL *)imageURL __deprecated_msg("Use `sd_imageURL`");
|
||||||
|
|
||||||
|
- (void)setImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:`");
|
||||||
|
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:`");
|
||||||
|
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options`");
|
||||||
|
|
||||||
|
- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:completed:`");
|
||||||
|
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:completed:`");
|
||||||
|
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:completed:`");
|
||||||
|
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:progress:completed:`");
|
||||||
|
|
||||||
|
- (void)sd_setImageWithPreviousCachedImageWithURL:(NSURL *)url andPlaceholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithPreviousCachedImageWithURL:placeholderImage:options:progress:completed:`");
|
||||||
|
|
||||||
|
- (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs __deprecated_msg("Use `sd_setAnimationImagesWithURLs:`");
|
||||||
|
|
||||||
|
- (void)cancelCurrentArrayLoad __deprecated_msg("Use `sd_cancelCurrentAnimationImagesLoad`");
|
||||||
|
|
||||||
|
- (void)cancelCurrentImageLoad __deprecated_msg("Use `sd_cancelCurrentImageLoad`");
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -8,89 +8,274 @@
|
||||||
|
|
||||||
#import "UIImageView+WebCache.h"
|
#import "UIImageView+WebCache.h"
|
||||||
#import "objc/runtime.h"
|
#import "objc/runtime.h"
|
||||||
|
#import "UIView+WebCacheOperation.h"
|
||||||
|
|
||||||
static char operationKey;
|
static char imageURLKey;
|
||||||
|
static char TAG_ACTIVITY_INDICATOR;
|
||||||
|
static char TAG_ACTIVITY_STYLE;
|
||||||
|
static char TAG_ACTIVITY_SHOW;
|
||||||
|
|
||||||
@implementation UIImageView (WebCache)
|
@implementation UIImageView (WebCache)
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url
|
- (void)sd_setImageWithURL:(NSURL *)url {
|
||||||
{
|
[self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil];
|
||||||
[self setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder
|
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
|
||||||
{
|
[self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil];
|
||||||
[self setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options
|
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
||||||
{
|
[self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil];
|
||||||
[self setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock
|
- (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock {
|
||||||
{
|
[self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:completedBlock];
|
||||||
[self setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:completedBlock];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock
|
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock {
|
||||||
{
|
[self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:completedBlock];
|
||||||
[self setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:completedBlock];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock
|
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
|
||||||
{
|
[self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:completedBlock];
|
||||||
[self setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:completedBlock];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock;
|
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock {
|
||||||
{
|
[self sd_cancelCurrentImageLoad];
|
||||||
[self cancelCurrentImageLoad];
|
objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||||
|
|
||||||
self.image = placeholder;
|
if (!(options & SDWebImageDelayPlaceholder)) {
|
||||||
|
dispatch_main_async_safe(^{
|
||||||
|
self.image = placeholder;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (url)
|
if (url) {
|
||||||
{
|
|
||||||
__weak UIImageView *wself = self;
|
// check if activityView is enabled or not
|
||||||
id<SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished)
|
if ([self showActivityIndicatorView]) {
|
||||||
{
|
[self addActivityIndicator];
|
||||||
|
}
|
||||||
|
|
||||||
|
__weak __typeof(self)wself = self;
|
||||||
|
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||||
|
[wself removeActivityIndicator];
|
||||||
if (!wself) return;
|
if (!wself) return;
|
||||||
void (^block)(void) = ^
|
dispatch_main_sync_safe(^{
|
||||||
{
|
if (!wself) return;
|
||||||
__strong UIImageView *sself = wself;
|
if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock)
|
||||||
if (!sself) return;
|
|
||||||
if (image)
|
|
||||||
{
|
{
|
||||||
sself.image = image;
|
completedBlock(image, error, cacheType, url);
|
||||||
[sself setNeedsLayout];
|
return;
|
||||||
}
|
}
|
||||||
if (completedBlock && finished)
|
else if (image) {
|
||||||
{
|
wself.image = image;
|
||||||
completedBlock(image, error, cacheType);
|
[wself setNeedsLayout];
|
||||||
|
} else {
|
||||||
|
if ((options & SDWebImageDelayPlaceholder)) {
|
||||||
|
wself.image = placeholder;
|
||||||
|
[wself setNeedsLayout];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
if (completedBlock && finished) {
|
||||||
if ([NSThread isMainThread])
|
completedBlock(image, error, cacheType, url);
|
||||||
{
|
}
|
||||||
block();
|
});
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dispatch_sync(dispatch_get_main_queue(), block);
|
|
||||||
}
|
|
||||||
}];
|
}];
|
||||||
objc_setAssociatedObject(self, &operationKey, operation, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
[self sd_setImageLoadOperation:operation forKey:@"UIImageViewImageLoad"];
|
||||||
|
} else {
|
||||||
|
dispatch_main_async_safe(^{
|
||||||
|
[self removeActivityIndicator];
|
||||||
|
if (completedBlock) {
|
||||||
|
NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
|
||||||
|
completedBlock(nil, error, SDImageCacheTypeNone, url);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)cancelCurrentImageLoad
|
- (void)sd_setImageWithPreviousCachedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock {
|
||||||
{
|
NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:url];
|
||||||
// Cancel in progress downloader from queue
|
UIImage *lastPreviousCachedImage = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:key];
|
||||||
id<SDWebImageOperation> operation = objc_getAssociatedObject(self, &operationKey);
|
|
||||||
if (operation)
|
[self sd_setImageWithURL:url placeholderImage:lastPreviousCachedImage ?: placeholder options:options progress:progressBlock completed:completedBlock];
|
||||||
{
|
}
|
||||||
[operation cancel];
|
|
||||||
objc_setAssociatedObject(self, &operationKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
- (NSURL *)sd_imageURL {
|
||||||
|
return objc_getAssociatedObject(self, &imageURLKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)sd_setAnimationImagesWithURLs:(NSArray *)arrayOfURLs {
|
||||||
|
[self sd_cancelCurrentAnimationImagesLoad];
|
||||||
|
__weak __typeof(self)wself = self;
|
||||||
|
|
||||||
|
NSMutableArray *operationsArray = [[NSMutableArray alloc] init];
|
||||||
|
|
||||||
|
for (NSURL *logoImageURL in arrayOfURLs) {
|
||||||
|
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:logoImageURL options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||||
|
if (!wself) return;
|
||||||
|
dispatch_main_sync_safe(^{
|
||||||
|
__strong UIImageView *sself = wself;
|
||||||
|
[sself stopAnimating];
|
||||||
|
if (sself && image) {
|
||||||
|
NSMutableArray *currentImages = [[sself animationImages] mutableCopy];
|
||||||
|
if (!currentImages) {
|
||||||
|
currentImages = [[NSMutableArray alloc] init];
|
||||||
|
}
|
||||||
|
[currentImages addObject:image];
|
||||||
|
|
||||||
|
sself.animationImages = currentImages;
|
||||||
|
[sself setNeedsLayout];
|
||||||
|
}
|
||||||
|
[sself startAnimating];
|
||||||
|
});
|
||||||
|
}];
|
||||||
|
[operationsArray addObject:operation];
|
||||||
|
}
|
||||||
|
|
||||||
|
[self sd_setImageLoadOperation:[NSArray arrayWithArray:operationsArray] forKey:@"UIImageViewAnimationImages"];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)sd_cancelCurrentImageLoad {
|
||||||
|
[self sd_cancelImageLoadOperationWithKey:@"UIImageViewImageLoad"];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)sd_cancelCurrentAnimationImagesLoad {
|
||||||
|
[self sd_cancelImageLoadOperationWithKey:@"UIImageViewAnimationImages"];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#pragma mark -
|
||||||
|
- (UIActivityIndicatorView *)activityIndicator {
|
||||||
|
return (UIActivityIndicatorView *)objc_getAssociatedObject(self, &TAG_ACTIVITY_INDICATOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setActivityIndicator:(UIActivityIndicatorView *)activityIndicator {
|
||||||
|
objc_setAssociatedObject(self, &TAG_ACTIVITY_INDICATOR, activityIndicator, OBJC_ASSOCIATION_RETAIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setShowActivityIndicatorView:(BOOL)show{
|
||||||
|
objc_setAssociatedObject(self, &TAG_ACTIVITY_SHOW, [NSNumber numberWithBool:show], OBJC_ASSOCIATION_RETAIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)showActivityIndicatorView{
|
||||||
|
return [objc_getAssociatedObject(self, &TAG_ACTIVITY_SHOW) boolValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setIndicatorStyle:(UIActivityIndicatorViewStyle)style{
|
||||||
|
objc_setAssociatedObject(self, &TAG_ACTIVITY_STYLE, [NSNumber numberWithInt:style], OBJC_ASSOCIATION_RETAIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (int)getIndicatorStyle{
|
||||||
|
return [objc_getAssociatedObject(self, &TAG_ACTIVITY_STYLE) intValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)addActivityIndicator {
|
||||||
|
if (!self.activityIndicator) {
|
||||||
|
self.activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:[self getIndicatorStyle]];
|
||||||
|
self.activityIndicator.translatesAutoresizingMaskIntoConstraints = NO;
|
||||||
|
|
||||||
|
dispatch_main_async_safe(^{
|
||||||
|
[self addSubview:self.activityIndicator];
|
||||||
|
|
||||||
|
[self addConstraint:[NSLayoutConstraint constraintWithItem:self.activityIndicator
|
||||||
|
attribute:NSLayoutAttributeCenterX
|
||||||
|
relatedBy:NSLayoutRelationEqual
|
||||||
|
toItem:self
|
||||||
|
attribute:NSLayoutAttributeCenterX
|
||||||
|
multiplier:1.0
|
||||||
|
constant:0.0]];
|
||||||
|
[self addConstraint:[NSLayoutConstraint constraintWithItem:self.activityIndicator
|
||||||
|
attribute:NSLayoutAttributeCenterY
|
||||||
|
relatedBy:NSLayoutRelationEqual
|
||||||
|
toItem:self
|
||||||
|
attribute:NSLayoutAttributeCenterY
|
||||||
|
multiplier:1.0
|
||||||
|
constant:0.0]];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch_main_async_safe(^{
|
||||||
|
[self.activityIndicator startAnimating];
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)removeActivityIndicator {
|
||||||
|
if (self.activityIndicator) {
|
||||||
|
[self.activityIndicator removeFromSuperview];
|
||||||
|
self.activityIndicator = nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@implementation UIImageView (WebCacheDeprecated)
|
||||||
|
|
||||||
|
- (NSURL *)imageURL {
|
||||||
|
return [self sd_imageURL];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setImageWithURL:(NSURL *)url {
|
||||||
|
[self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
|
||||||
|
[self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
||||||
|
[self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock {
|
||||||
|
[self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||||
|
if (completedBlock) {
|
||||||
|
completedBlock(image, error, cacheType);
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock {
|
||||||
|
[self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||||
|
if (completedBlock) {
|
||||||
|
completedBlock(image, error, cacheType);
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
|
||||||
|
[self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||||
|
if (completedBlock) {
|
||||||
|
completedBlock(image, error, cacheType);
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock {
|
||||||
|
[self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||||
|
if (completedBlock) {
|
||||||
|
completedBlock(image, error, cacheType);
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)sd_setImageWithPreviousCachedImageWithURL:(NSURL *)url andPlaceholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock {
|
||||||
|
[self sd_setImageWithPreviousCachedImageWithURL:url placeholderImage:placeholder options:options progress:progressBlock completed:completedBlock];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)cancelCurrentArrayLoad {
|
||||||
|
[self sd_cancelCurrentAnimationImagesLoad];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)cancelCurrentImageLoad {
|
||||||
|
[self sd_cancelCurrentImageLoad];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs {
|
||||||
|
[self sd_setAnimationImagesWithURLs:arrayOfURLs];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* This file is part of the SDWebImage package.
|
||||||
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#import <UIKit/UIKit.h>
|
||||||
|
#import "SDWebImageManager.h"
|
||||||
|
|
||||||
|
@interface UIView (WebCacheOperation)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the image load operation (storage in a UIView based dictionary)
|
||||||
|
*
|
||||||
|
* @param operation the operation
|
||||||
|
* @param key key for storing the operation
|
||||||
|
*/
|
||||||
|
- (void)sd_setImageLoadOperation:(id)operation forKey:(NSString *)key;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancel all operations for the current UIView and key
|
||||||
|
*
|
||||||
|
* @param key key for identifying the operations
|
||||||
|
*/
|
||||||
|
- (void)sd_cancelImageLoadOperationWithKey:(NSString *)key;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Just remove the operations corresponding to the current UIView and key without cancelling them
|
||||||
|
*
|
||||||
|
* @param key key for identifying the operations
|
||||||
|
*/
|
||||||
|
- (void)sd_removeImageLoadOperationWithKey:(NSString *)key;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
* This file is part of the SDWebImage package.
|
||||||
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#import "UIView+WebCacheOperation.h"
|
||||||
|
#import "objc/runtime.h"
|
||||||
|
|
||||||
|
static char loadOperationKey;
|
||||||
|
|
||||||
|
@implementation UIView (WebCacheOperation)
|
||||||
|
|
||||||
|
- (NSMutableDictionary *)operationDictionary {
|
||||||
|
NSMutableDictionary *operations = objc_getAssociatedObject(self, &loadOperationKey);
|
||||||
|
if (operations) {
|
||||||
|
return operations;
|
||||||
|
}
|
||||||
|
operations = [NSMutableDictionary dictionary];
|
||||||
|
objc_setAssociatedObject(self, &loadOperationKey, operations, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||||
|
return operations;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)sd_setImageLoadOperation:(id)operation forKey:(NSString *)key {
|
||||||
|
[self sd_cancelImageLoadOperationWithKey:key];
|
||||||
|
NSMutableDictionary *operationDictionary = [self operationDictionary];
|
||||||
|
[operationDictionary setObject:operation forKey:key];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)sd_cancelImageLoadOperationWithKey:(NSString *)key {
|
||||||
|
// Cancel in progress downloader from queue
|
||||||
|
NSMutableDictionary *operationDictionary = [self operationDictionary];
|
||||||
|
id operations = [operationDictionary objectForKey:key];
|
||||||
|
if (operations) {
|
||||||
|
if ([operations isKindOfClass:[NSArray class]]) {
|
||||||
|
for (id <SDWebImageOperation> operation in operations) {
|
||||||
|
if (operation) {
|
||||||
|
[operation cancel];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if ([operations conformsToProtocol:@protocol(SDWebImageOperation)]){
|
||||||
|
[(id<SDWebImageOperation>) operations cancel];
|
||||||
|
}
|
||||||
|
[operationDictionary removeObjectForKey:key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)sd_removeImageLoadOperationWithKey:(NSString *)key {
|
||||||
|
NSMutableDictionary *operationDictionary = [self operationDictionary];
|
||||||
|
[operationDictionary removeObjectForKey:key];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
source 'https://github.com/CocoaPods/Specs.git'
|
||||||
|
|
||||||
|
xcodeproj 'SDWebImage Tests'
|
||||||
|
workspace '../SDWebImage'
|
||||||
|
|
||||||
|
target 'Tests' do
|
||||||
|
platform :ios, '7.0'
|
||||||
|
pod 'Expecta', '<=0.3.1'
|
||||||
|
pod 'SDWebImage', :path => '../'
|
||||||
|
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,370 @@
|
||||||
|
// !$*UTF8*$!
|
||||||
|
{
|
||||||
|
archiveVersion = 1;
|
||||||
|
classes = {
|
||||||
|
};
|
||||||
|
objectVersion = 46;
|
||||||
|
objects = {
|
||||||
|
|
||||||
|
/* Begin PBXBuildFile section */
|
||||||
|
2278D185E97AF851CF3F9A07 /* libPods-Tests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F0EF05B6C461610578D6C2A6 /* libPods-Tests.a */; };
|
||||||
|
5F7F38AD1AE2A77A00B0E330 /* TestImage.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 5F7F38AC1AE2A77A00B0E330 /* TestImage.jpg */; };
|
||||||
|
DA248D57195472AA00390AB0 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA248D56195472AA00390AB0 /* XCTest.framework */; };
|
||||||
|
DA248D59195472AA00390AB0 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA248D58195472AA00390AB0 /* Foundation.framework */; };
|
||||||
|
DA248D5B195472AA00390AB0 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA248D5A195472AA00390AB0 /* UIKit.framework */; };
|
||||||
|
DA248D61195472AA00390AB0 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = DA248D5F195472AA00390AB0 /* InfoPlist.strings */; };
|
||||||
|
DA248D69195475D800390AB0 /* SDImageCacheTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DA248D68195475D800390AB0 /* SDImageCacheTests.m */; };
|
||||||
|
DA248D6B195476AC00390AB0 /* SDWebImageManagerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DA248D6A195476AC00390AB0 /* SDWebImageManagerTests.m */; };
|
||||||
|
DA91BEBC19795BC9006F2536 /* UIImageMultiFormatTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DA91BEBB19795BC9006F2536 /* UIImageMultiFormatTests.m */; };
|
||||||
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
|
/* Begin PBXFileReference section */
|
||||||
|
0EAE9F732E05E3878DC9D2D1 /* Pods-Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Tests/Pods-Tests.debug.xcconfig"; sourceTree = "<group>"; };
|
||||||
|
2FAA0419497C5AA7F0EA0E20 /* Pods-Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-Tests/Pods-Tests.release.xcconfig"; sourceTree = "<group>"; };
|
||||||
|
5F7F38AC1AE2A77A00B0E330 /* TestImage.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = TestImage.jpg; sourceTree = "<group>"; };
|
||||||
|
DA248D53195472AA00390AB0 /* Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
|
DA248D56195472AA00390AB0 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; };
|
||||||
|
DA248D58195472AA00390AB0 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; };
|
||||||
|
DA248D5A195472AA00390AB0 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; };
|
||||||
|
DA248D5E195472AA00390AB0 /* Tests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Tests-Info.plist"; sourceTree = "<group>"; };
|
||||||
|
DA248D60195472AA00390AB0 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
|
||||||
|
DA248D64195472AA00390AB0 /* Tests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Tests-Prefix.pch"; sourceTree = "<group>"; };
|
||||||
|
DA248D68195475D800390AB0 /* SDImageCacheTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDImageCacheTests.m; sourceTree = "<group>"; };
|
||||||
|
DA248D6A195476AC00390AB0 /* SDWebImageManagerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDWebImageManagerTests.m; sourceTree = "<group>"; };
|
||||||
|
DA91BEBB19795BC9006F2536 /* UIImageMultiFormatTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UIImageMultiFormatTests.m; sourceTree = "<group>"; };
|
||||||
|
F0EF05B6C461610578D6C2A6 /* libPods-Tests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Tests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
|
DA248D50195472AA00390AB0 /* Frameworks */ = {
|
||||||
|
isa = PBXFrameworksBuildPhase;
|
||||||
|
buildActionMask = 2147483647;
|
||||||
|
files = (
|
||||||
|
DA248D57195472AA00390AB0 /* XCTest.framework in Frameworks */,
|
||||||
|
DA248D5B195472AA00390AB0 /* UIKit.framework in Frameworks */,
|
||||||
|
DA248D59195472AA00390AB0 /* Foundation.framework in Frameworks */,
|
||||||
|
2278D185E97AF851CF3F9A07 /* libPods-Tests.a in Frameworks */,
|
||||||
|
);
|
||||||
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
};
|
||||||
|
/* End PBXFrameworksBuildPhase section */
|
||||||
|
|
||||||
|
/* Begin PBXGroup section */
|
||||||
|
8D1A343B1A6D91E95D7795EF /* Pods */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
0EAE9F732E05E3878DC9D2D1 /* Pods-Tests.debug.xcconfig */,
|
||||||
|
2FAA0419497C5AA7F0EA0E20 /* Pods-Tests.release.xcconfig */,
|
||||||
|
);
|
||||||
|
name = Pods;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
|
DA248D451954721A00390AB0 = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
DA248D5C195472AA00390AB0 /* Tests */,
|
||||||
|
DA248D55195472AA00390AB0 /* Frameworks */,
|
||||||
|
DA248D54195472AA00390AB0 /* Products */,
|
||||||
|
8D1A343B1A6D91E95D7795EF /* Pods */,
|
||||||
|
);
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
|
DA248D54195472AA00390AB0 /* Products */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
DA248D53195472AA00390AB0 /* Tests.xctest */,
|
||||||
|
);
|
||||||
|
name = Products;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
|
DA248D55195472AA00390AB0 /* Frameworks */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
DA248D56195472AA00390AB0 /* XCTest.framework */,
|
||||||
|
DA248D58195472AA00390AB0 /* Foundation.framework */,
|
||||||
|
DA248D5A195472AA00390AB0 /* UIKit.framework */,
|
||||||
|
F0EF05B6C461610578D6C2A6 /* libPods-Tests.a */,
|
||||||
|
);
|
||||||
|
name = Frameworks;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
|
DA248D5C195472AA00390AB0 /* Tests */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
5F7F38AC1AE2A77A00B0E330 /* TestImage.jpg */,
|
||||||
|
DA248D5D195472AA00390AB0 /* Supporting Files */,
|
||||||
|
DA248D68195475D800390AB0 /* SDImageCacheTests.m */,
|
||||||
|
DA248D6A195476AC00390AB0 /* SDWebImageManagerTests.m */,
|
||||||
|
DA91BEBB19795BC9006F2536 /* UIImageMultiFormatTests.m */,
|
||||||
|
);
|
||||||
|
path = Tests;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
|
DA248D5D195472AA00390AB0 /* Supporting Files */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
DA248D5E195472AA00390AB0 /* Tests-Info.plist */,
|
||||||
|
DA248D5F195472AA00390AB0 /* InfoPlist.strings */,
|
||||||
|
DA248D64195472AA00390AB0 /* Tests-Prefix.pch */,
|
||||||
|
);
|
||||||
|
name = "Supporting Files";
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
|
/* End PBXGroup section */
|
||||||
|
|
||||||
|
/* Begin PBXNativeTarget section */
|
||||||
|
DA248D52195472AA00390AB0 /* Tests */ = {
|
||||||
|
isa = PBXNativeTarget;
|
||||||
|
buildConfigurationList = DA248D67195472AA00390AB0 /* Build configuration list for PBXNativeTarget "Tests" */;
|
||||||
|
buildPhases = (
|
||||||
|
FBC8982311CD4ED9A3006D45 /* 📦 Check Pods Manifest.lock */,
|
||||||
|
DA248D4F195472AA00390AB0 /* Sources */,
|
||||||
|
DA248D50195472AA00390AB0 /* Frameworks */,
|
||||||
|
DA248D51195472AA00390AB0 /* Resources */,
|
||||||
|
D6347736BDF64FC5A4D078A4 /* 📦 Copy Pods Resources */,
|
||||||
|
4B51E412BA3594400947AC71 /* 📦 Embed Pods Frameworks */,
|
||||||
|
);
|
||||||
|
buildRules = (
|
||||||
|
);
|
||||||
|
dependencies = (
|
||||||
|
);
|
||||||
|
name = Tests;
|
||||||
|
productName = Tests;
|
||||||
|
productReference = DA248D53195472AA00390AB0 /* Tests.xctest */;
|
||||||
|
productType = "com.apple.product-type.bundle.unit-test";
|
||||||
|
};
|
||||||
|
/* End PBXNativeTarget section */
|
||||||
|
|
||||||
|
/* Begin PBXProject section */
|
||||||
|
DA248D461954721A00390AB0 /* Project object */ = {
|
||||||
|
isa = PBXProject;
|
||||||
|
attributes = {
|
||||||
|
LastUpgradeCheck = 0510;
|
||||||
|
};
|
||||||
|
buildConfigurationList = DA248D491954721A00390AB0 /* Build configuration list for PBXProject "SDWebImage Tests" */;
|
||||||
|
compatibilityVersion = "Xcode 3.2";
|
||||||
|
developmentRegion = English;
|
||||||
|
hasScannedForEncodings = 0;
|
||||||
|
knownRegions = (
|
||||||
|
en,
|
||||||
|
);
|
||||||
|
mainGroup = DA248D451954721A00390AB0;
|
||||||
|
productRefGroup = DA248D54195472AA00390AB0 /* Products */;
|
||||||
|
projectDirPath = "";
|
||||||
|
projectRoot = "";
|
||||||
|
targets = (
|
||||||
|
DA248D52195472AA00390AB0 /* Tests */,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
/* End PBXProject section */
|
||||||
|
|
||||||
|
/* Begin PBXResourcesBuildPhase section */
|
||||||
|
DA248D51195472AA00390AB0 /* Resources */ = {
|
||||||
|
isa = PBXResourcesBuildPhase;
|
||||||
|
buildActionMask = 2147483647;
|
||||||
|
files = (
|
||||||
|
5F7F38AD1AE2A77A00B0E330 /* TestImage.jpg in Resources */,
|
||||||
|
DA248D61195472AA00390AB0 /* InfoPlist.strings in Resources */,
|
||||||
|
);
|
||||||
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
};
|
||||||
|
/* End PBXResourcesBuildPhase section */
|
||||||
|
|
||||||
|
/* Begin PBXShellScriptBuildPhase section */
|
||||||
|
4B51E412BA3594400947AC71 /* 📦 Embed Pods Frameworks */ = {
|
||||||
|
isa = PBXShellScriptBuildPhase;
|
||||||
|
buildActionMask = 2147483647;
|
||||||
|
files = (
|
||||||
|
);
|
||||||
|
inputPaths = (
|
||||||
|
);
|
||||||
|
name = "📦 Embed Pods Frameworks";
|
||||||
|
outputPaths = (
|
||||||
|
);
|
||||||
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
shellPath = /bin/sh;
|
||||||
|
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Tests/Pods-Tests-frameworks.sh\"\n";
|
||||||
|
showEnvVarsInLog = 0;
|
||||||
|
};
|
||||||
|
D6347736BDF64FC5A4D078A4 /* 📦 Copy Pods Resources */ = {
|
||||||
|
isa = PBXShellScriptBuildPhase;
|
||||||
|
buildActionMask = 2147483647;
|
||||||
|
files = (
|
||||||
|
);
|
||||||
|
inputPaths = (
|
||||||
|
);
|
||||||
|
name = "📦 Copy Pods Resources";
|
||||||
|
outputPaths = (
|
||||||
|
);
|
||||||
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
shellPath = /bin/sh;
|
||||||
|
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Tests/Pods-Tests-resources.sh\"\n";
|
||||||
|
showEnvVarsInLog = 0;
|
||||||
|
};
|
||||||
|
FBC8982311CD4ED9A3006D45 /* 📦 Check Pods Manifest.lock */ = {
|
||||||
|
isa = PBXShellScriptBuildPhase;
|
||||||
|
buildActionMask = 2147483647;
|
||||||
|
files = (
|
||||||
|
);
|
||||||
|
inputPaths = (
|
||||||
|
);
|
||||||
|
name = "📦 Check Pods Manifest.lock";
|
||||||
|
outputPaths = (
|
||||||
|
);
|
||||||
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
shellPath = /bin/sh;
|
||||||
|
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
|
||||||
|
showEnvVarsInLog = 0;
|
||||||
|
};
|
||||||
|
/* End PBXShellScriptBuildPhase section */
|
||||||
|
|
||||||
|
/* Begin PBXSourcesBuildPhase section */
|
||||||
|
DA248D4F195472AA00390AB0 /* Sources */ = {
|
||||||
|
isa = PBXSourcesBuildPhase;
|
||||||
|
buildActionMask = 2147483647;
|
||||||
|
files = (
|
||||||
|
DA248D69195475D800390AB0 /* SDImageCacheTests.m in Sources */,
|
||||||
|
DA248D6B195476AC00390AB0 /* SDWebImageManagerTests.m in Sources */,
|
||||||
|
DA91BEBC19795BC9006F2536 /* UIImageMultiFormatTests.m in Sources */,
|
||||||
|
);
|
||||||
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
};
|
||||||
|
/* End PBXSourcesBuildPhase section */
|
||||||
|
|
||||||
|
/* Begin PBXVariantGroup section */
|
||||||
|
DA248D5F195472AA00390AB0 /* InfoPlist.strings */ = {
|
||||||
|
isa = PBXVariantGroup;
|
||||||
|
children = (
|
||||||
|
DA248D60195472AA00390AB0 /* en */,
|
||||||
|
);
|
||||||
|
name = InfoPlist.strings;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
|
/* End PBXVariantGroup section */
|
||||||
|
|
||||||
|
/* Begin XCBuildConfiguration section */
|
||||||
|
DA248D4A1954721A00390AB0 /* Debug */ = {
|
||||||
|
isa = XCBuildConfiguration;
|
||||||
|
buildSettings = {
|
||||||
|
};
|
||||||
|
name = Debug;
|
||||||
|
};
|
||||||
|
DA248D4B1954721A00390AB0 /* Release */ = {
|
||||||
|
isa = XCBuildConfiguration;
|
||||||
|
buildSettings = {
|
||||||
|
};
|
||||||
|
name = Release;
|
||||||
|
};
|
||||||
|
DA248D65195472AA00390AB0 /* Debug */ = {
|
||||||
|
isa = XCBuildConfiguration;
|
||||||
|
baseConfigurationReference = 0EAE9F732E05E3878DC9D2D1 /* Pods-Tests.debug.xcconfig */;
|
||||||
|
buildSettings = {
|
||||||
|
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||||
|
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||||
|
CLANG_CXX_LIBRARY = "libc++";
|
||||||
|
CLANG_ENABLE_MODULES = YES;
|
||||||
|
CLANG_ENABLE_OBJC_ARC = YES;
|
||||||
|
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||||
|
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||||
|
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||||
|
CLANG_WARN_EMPTY_BODY = YES;
|
||||||
|
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||||
|
CLANG_WARN_INT_CONVERSION = YES;
|
||||||
|
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||||
|
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||||
|
COPY_PHASE_STRIP = NO;
|
||||||
|
FRAMEWORK_SEARCH_PATHS = (
|
||||||
|
"$(inherited)",
|
||||||
|
"$(DEVELOPER_FRAMEWORKS_DIR)",
|
||||||
|
);
|
||||||
|
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||||
|
GCC_DYNAMIC_NO_PIC = NO;
|
||||||
|
GCC_OPTIMIZATION_LEVEL = 0;
|
||||||
|
GCC_PRECOMPILE_PREFIX_HEADER = YES;
|
||||||
|
GCC_PREFIX_HEADER = "Tests/Tests-Prefix.pch";
|
||||||
|
GCC_PREPROCESSOR_DEFINITIONS = (
|
||||||
|
"DEBUG=1",
|
||||||
|
"$(inherited)",
|
||||||
|
);
|
||||||
|
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
|
||||||
|
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||||
|
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||||
|
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||||
|
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||||
|
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||||
|
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||||
|
INFOPLIST_FILE = "Tests/Tests-Info.plist";
|
||||||
|
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
|
||||||
|
ONLY_ACTIVE_ARCH = YES;
|
||||||
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
|
SDKROOT = iphoneos;
|
||||||
|
WRAPPER_EXTENSION = xctest;
|
||||||
|
};
|
||||||
|
name = Debug;
|
||||||
|
};
|
||||||
|
DA248D66195472AA00390AB0 /* Release */ = {
|
||||||
|
isa = XCBuildConfiguration;
|
||||||
|
baseConfigurationReference = 2FAA0419497C5AA7F0EA0E20 /* Pods-Tests.release.xcconfig */;
|
||||||
|
buildSettings = {
|
||||||
|
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||||
|
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||||
|
CLANG_CXX_LIBRARY = "libc++";
|
||||||
|
CLANG_ENABLE_MODULES = YES;
|
||||||
|
CLANG_ENABLE_OBJC_ARC = YES;
|
||||||
|
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||||
|
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||||
|
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||||
|
CLANG_WARN_EMPTY_BODY = YES;
|
||||||
|
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||||
|
CLANG_WARN_INT_CONVERSION = YES;
|
||||||
|
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||||
|
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||||
|
COPY_PHASE_STRIP = YES;
|
||||||
|
ENABLE_NS_ASSERTIONS = NO;
|
||||||
|
FRAMEWORK_SEARCH_PATHS = (
|
||||||
|
"$(inherited)",
|
||||||
|
"$(DEVELOPER_FRAMEWORKS_DIR)",
|
||||||
|
);
|
||||||
|
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||||
|
GCC_PRECOMPILE_PREFIX_HEADER = YES;
|
||||||
|
GCC_PREFIX_HEADER = "Tests/Tests-Prefix.pch";
|
||||||
|
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||||
|
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||||
|
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||||
|
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||||
|
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||||
|
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||||
|
INFOPLIST_FILE = "Tests/Tests-Info.plist";
|
||||||
|
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
|
||||||
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
|
SDKROOT = iphoneos;
|
||||||
|
VALIDATE_PRODUCT = YES;
|
||||||
|
WRAPPER_EXTENSION = xctest;
|
||||||
|
};
|
||||||
|
name = Release;
|
||||||
|
};
|
||||||
|
/* End XCBuildConfiguration section */
|
||||||
|
|
||||||
|
/* Begin XCConfigurationList section */
|
||||||
|
DA248D491954721A00390AB0 /* Build configuration list for PBXProject "SDWebImage Tests" */ = {
|
||||||
|
isa = XCConfigurationList;
|
||||||
|
buildConfigurations = (
|
||||||
|
DA248D4A1954721A00390AB0 /* Debug */,
|
||||||
|
DA248D4B1954721A00390AB0 /* Release */,
|
||||||
|
);
|
||||||
|
defaultConfigurationIsVisible = 0;
|
||||||
|
defaultConfigurationName = Release;
|
||||||
|
};
|
||||||
|
DA248D67195472AA00390AB0 /* Build configuration list for PBXNativeTarget "Tests" */ = {
|
||||||
|
isa = XCConfigurationList;
|
||||||
|
buildConfigurations = (
|
||||||
|
DA248D65195472AA00390AB0 /* Debug */,
|
||||||
|
DA248D66195472AA00390AB0 /* Release */,
|
||||||
|
);
|
||||||
|
defaultConfigurationIsVisible = 0;
|
||||||
|
defaultConfigurationName = Release;
|
||||||
|
};
|
||||||
|
/* End XCConfigurationList section */
|
||||||
|
};
|
||||||
|
rootObject = DA248D461954721A00390AB0 /* Project object */;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,225 @@
|
||||||
|
//
|
||||||
|
// SDImageCacheTests.m
|
||||||
|
// SDWebImage Tests
|
||||||
|
//
|
||||||
|
// Created by Bogdan Poplauschi on 20/06/14.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
#define EXP_SHORTHAND // required by Expecta
|
||||||
|
|
||||||
|
|
||||||
|
#import <XCTest/XCTest.h>
|
||||||
|
#import <Expecta.h>
|
||||||
|
|
||||||
|
#import "SDImageCache.h"
|
||||||
|
|
||||||
|
NSString *kImageTestKey = @"TestImageKey.jpg";
|
||||||
|
|
||||||
|
@interface SDImageCacheTests : XCTestCase
|
||||||
|
@property (strong, nonatomic) SDImageCache *sharedImageCache;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation SDImageCacheTests
|
||||||
|
|
||||||
|
- (void)setUp
|
||||||
|
{
|
||||||
|
[super setUp];
|
||||||
|
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||||
|
self.sharedImageCache = [SDImageCache sharedImageCache];
|
||||||
|
[self clearAllCaches];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)tearDown
|
||||||
|
{
|
||||||
|
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||||
|
[super tearDown];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testSharedImageCache {
|
||||||
|
expect(self.sharedImageCache).toNot.beNil();
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testSingleton{
|
||||||
|
expect(self.sharedImageCache).to.equal([SDImageCache sharedImageCache]);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testClearDiskCache{
|
||||||
|
[self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey];
|
||||||
|
[self.sharedImageCache clearDiskOnCompletion:^{
|
||||||
|
expect([self.sharedImageCache diskImageExistsWithKey:kImageTestKey]).to.equal(NO);
|
||||||
|
expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.equal([self imageForTesting]);
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testClearMemoryCache{
|
||||||
|
[self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey];
|
||||||
|
[self.sharedImageCache clearMemory];
|
||||||
|
expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.beNil;
|
||||||
|
// Seems not able to access the files correctly (maybe only from test?)
|
||||||
|
//expect([self.sharedImageCache diskImageExistsWithKey:kImageTestKey]).to.equal(YES);
|
||||||
|
[self.sharedImageCache diskImageExistsWithKey:kImageTestKey completion:^(BOOL isInCache) {
|
||||||
|
expect(isInCache).to.equal(YES);
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Testing storeImage:forKey:
|
||||||
|
- (void)testInsertionOfImage {
|
||||||
|
UIImage *image = [self imageForTesting];
|
||||||
|
[self.sharedImageCache storeImage:image forKey:kImageTestKey];
|
||||||
|
expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.equal(image);
|
||||||
|
expect([self.sharedImageCache imageFromDiskCacheForKey:kImageTestKey]).to.equal(image);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Testing storeImage:forKey:toDisk:YES
|
||||||
|
- (void)testInsertionOfImageForcingDiskStorage{
|
||||||
|
UIImage *image = [self imageForTesting];
|
||||||
|
[self.sharedImageCache storeImage:image forKey:kImageTestKey toDisk:YES];
|
||||||
|
expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.equal(image);
|
||||||
|
// Seems not able to access the files correctly (maybe only from test?)
|
||||||
|
//expect([self.sharedImageCache diskImageExistsWithKey:kImageTestKey]).to.equal(YES);
|
||||||
|
[self.sharedImageCache diskImageExistsWithKey:kImageTestKey completion:^(BOOL isInCache) {
|
||||||
|
expect(isInCache).to.equal(YES);
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Testing storeImage:forKey:toDisk:NO
|
||||||
|
- (void)testInsertionOfImageOnlyInMemory {
|
||||||
|
UIImage *image = [self imageForTesting];
|
||||||
|
[self.sharedImageCache storeImage:image forKey:@"TestImage" toDisk:NO];
|
||||||
|
[self.sharedImageCache diskImageExistsWithKey:@"TestImage" completion:^(BOOL isInCache) {
|
||||||
|
expect(isInCache).to.equal(YES);
|
||||||
|
}];
|
||||||
|
[self.sharedImageCache clearMemory];
|
||||||
|
[self.sharedImageCache diskImageExistsWithKey:@"TestImage" completion:^(BOOL isInCache) {
|
||||||
|
expect(isInCache).to.equal(NO);
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testRetrievalImageThroughNSOperation{
|
||||||
|
//- (NSOperation *)queryDiskCacheForKey:(NSString *)key done:(SDWebImageQueryCompletedBlock)doneBlock;
|
||||||
|
UIImage *imageForTesting = [self imageForTesting];
|
||||||
|
[self.sharedImageCache storeImage:imageForTesting forKey:kImageTestKey];
|
||||||
|
NSOperation *operation = [self.sharedImageCache queryDiskCacheForKey:kImageTestKey done:^(UIImage *image, SDImageCacheType cacheType) {
|
||||||
|
expect(image).to.equal(imageForTesting);
|
||||||
|
}];
|
||||||
|
expect(operation).toNot.beNil;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testRemoveImageForKey{
|
||||||
|
[self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey];
|
||||||
|
[self.sharedImageCache removeImageForKey:kImageTestKey];
|
||||||
|
expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.beNil;
|
||||||
|
expect([self.sharedImageCache imageFromDiskCacheForKey:kImageTestKey]).to.beNil;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testRemoveImageForKeyWithCompletion{
|
||||||
|
[self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey];
|
||||||
|
[self.sharedImageCache removeImageForKey:kImageTestKey withCompletion:^{
|
||||||
|
expect([self.sharedImageCache imageFromDiskCacheForKey:kImageTestKey]).to.beNil;
|
||||||
|
expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.beNil;
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testRemoveImageForKeyNotFromDisk{
|
||||||
|
[self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey];
|
||||||
|
[self.sharedImageCache removeImageForKey:kImageTestKey fromDisk:NO];
|
||||||
|
expect([self.sharedImageCache imageFromDiskCacheForKey:kImageTestKey]).toNot.beNil;
|
||||||
|
expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.beNil;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testRemoveImageForKeyFromDisk{
|
||||||
|
[self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey];
|
||||||
|
[self.sharedImageCache removeImageForKey:kImageTestKey fromDisk:NO];
|
||||||
|
expect([self.sharedImageCache imageFromDiskCacheForKey:kImageTestKey]).to.beNil;
|
||||||
|
expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.beNil;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testRemoveImageforKeyNotFromDiskWithCompletion{
|
||||||
|
[self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey];
|
||||||
|
[self.sharedImageCache removeImageForKey:kImageTestKey fromDisk:NO withCompletion:^{
|
||||||
|
expect([self.sharedImageCache imageFromDiskCacheForKey:kImageTestKey]).toNot.beNil;
|
||||||
|
expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.beNil;
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testRemoveImageforKeyFromDiskWithCompletion{
|
||||||
|
[self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey];
|
||||||
|
[self.sharedImageCache removeImageForKey:kImageTestKey fromDisk:YES withCompletion:^{
|
||||||
|
expect([self.sharedImageCache imageFromDiskCacheForKey:kImageTestKey]).to.beNil;
|
||||||
|
expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.beNil;
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO -- Testing insertion with recalculate
|
||||||
|
- (void)testInsertionOfImageOnlyInDisk {
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testInitialCacheSize{
|
||||||
|
expect([self.sharedImageCache getSize]).to.equal(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testInitialDiskCount{
|
||||||
|
[self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey];
|
||||||
|
expect([self.sharedImageCache getDiskCount]).to.equal(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testDiskCountAfterInsertion{
|
||||||
|
[self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey];
|
||||||
|
expect([self.sharedImageCache getDiskCount]).to.equal(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testDefaultCachePathForAnyKey{
|
||||||
|
NSString *path = [self.sharedImageCache defaultCachePathForKey:kImageTestKey];
|
||||||
|
expect(path).toNot.beNil;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testCachePathForNonExistingKey{
|
||||||
|
NSString *path = [self.sharedImageCache cachePathForKey:kImageTestKey inPath:[self.sharedImageCache defaultCachePathForKey:kImageTestKey]];
|
||||||
|
expect(path).to.beNil;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testCachePathForExistingKey{
|
||||||
|
[self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey];
|
||||||
|
NSString *path = [self.sharedImageCache cachePathForKey:kImageTestKey inPath:[self.sharedImageCache defaultCachePathForKey:kImageTestKey]];
|
||||||
|
expect(path).notTo.beNil;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO -- Testing image data insertion
|
||||||
|
|
||||||
|
- (void)testInsertionOfImageData {
|
||||||
|
|
||||||
|
NSData *imageData = [NSData dataWithContentsOfFile:[self testImagePath]];
|
||||||
|
[self.sharedImageCache storeImageDataToDisk:imageData forKey:kImageTestKey];
|
||||||
|
|
||||||
|
UIImage *storedImageFromMemory = [self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey];
|
||||||
|
expect(storedImageFromMemory).to.equal(nil);
|
||||||
|
|
||||||
|
NSString *cachePath = [self.sharedImageCache defaultCachePathForKey:kImageTestKey];
|
||||||
|
NSData *storedImageData = [NSData dataWithContentsOfFile:cachePath];
|
||||||
|
expect([storedImageData isEqualToData:imageData]).will.beTruthy;
|
||||||
|
|
||||||
|
[self.sharedImageCache diskImageExistsWithKey:kImageTestKey completion:^(BOOL isInCache) {
|
||||||
|
expect(isInCache).to.equal(YES);
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark Helper methods
|
||||||
|
|
||||||
|
- (void)clearAllCaches{
|
||||||
|
[self.sharedImageCache clearDisk];
|
||||||
|
[self.sharedImageCache clearMemory];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (UIImage *)imageForTesting{
|
||||||
|
|
||||||
|
return [UIImage imageWithContentsOfFile:[self testImagePath]];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString *)testImagePath {
|
||||||
|
|
||||||
|
NSBundle *testBundle = [NSBundle bundleForClass:[self class]];
|
||||||
|
return [testBundle pathForResource:@"TestImage" ofType:@"jpg"];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
@ -0,0 +1,72 @@
|
||||||
|
//
|
||||||
|
// SDWebImageManagerTests.m
|
||||||
|
// SDWebImage Tests
|
||||||
|
//
|
||||||
|
// Created by Bogdan Poplauschi on 20/06/14.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
#define EXP_SHORTHAND // required by Expecta
|
||||||
|
|
||||||
|
|
||||||
|
#import <XCTest/XCTest.h>
|
||||||
|
#import <Expecta.h>
|
||||||
|
|
||||||
|
#import "SDWebImageManager.h"
|
||||||
|
|
||||||
|
static int64_t kAsyncTestTimeout = 5;
|
||||||
|
|
||||||
|
|
||||||
|
@interface SDWebImageManagerTests : XCTestCase
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation SDWebImageManagerTests
|
||||||
|
|
||||||
|
- (void)setUp
|
||||||
|
{
|
||||||
|
[super setUp];
|
||||||
|
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)tearDown
|
||||||
|
{
|
||||||
|
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||||
|
[super tearDown];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testThatDownloadInvokesCompletionBlockWithCorrectParamsAsync {
|
||||||
|
__block XCTestExpectation *expectation = [self expectationWithDescription:@"Image download completes"];
|
||||||
|
|
||||||
|
NSURL *originalImageURL = [NSURL URLWithString:@"http://s3.amazonaws.com/fast-image-cache/demo-images/FICDDemoImage000.jpg"];
|
||||||
|
|
||||||
|
[[SDWebImageManager sharedManager] downloadImageWithURL:originalImageURL options:SDWebImageRefreshCached progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||||
|
expect(image).toNot.beNil();
|
||||||
|
expect(error).to.beNil();
|
||||||
|
expect(originalImageURL).to.equal(imageURL);
|
||||||
|
|
||||||
|
[expectation fulfill];
|
||||||
|
expectation = nil;
|
||||||
|
}];
|
||||||
|
|
||||||
|
[self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testThatDownloadWithIncorrectURLInvokesCompletionBlockWithAnErrorAsync {
|
||||||
|
__block XCTestExpectation *expectation = [self expectationWithDescription:@"Image download completes"];
|
||||||
|
|
||||||
|
NSURL *originalImageURL = [NSURL URLWithString:@"http://static2.dmcdn.net/static/video/656/177/44771656:jpeg_preview_small.png"];
|
||||||
|
|
||||||
|
[[SDWebImageManager sharedManager] downloadImageWithURL:originalImageURL options:SDWebImageRefreshCached progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||||
|
expect(image).to.beNil();
|
||||||
|
expect(error).toNot.beNil();
|
||||||
|
expect(originalImageURL).to.equal(imageURL);
|
||||||
|
|
||||||
|
[expectation fulfill];
|
||||||
|
expectation = nil;
|
||||||
|
}];
|
||||||
|
|
||||||
|
[self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleDevelopmentRegion</key>
|
||||||
|
<string>en</string>
|
||||||
|
<key>CFBundleExecutable</key>
|
||||||
|
<string>${EXECUTABLE_NAME}</string>
|
||||||
|
<key>CFBundleIdentifier</key>
|
||||||
|
<string>com.SDWebImage.${PRODUCT_NAME:rfc1034identifier}</string>
|
||||||
|
<key>CFBundleInfoDictionaryVersion</key>
|
||||||
|
<string>6.0</string>
|
||||||
|
<key>CFBundlePackageType</key>
|
||||||
|
<string>BNDL</string>
|
||||||
|
<key>CFBundleShortVersionString</key>
|
||||||
|
<string>1.0</string>
|
||||||
|
<key>CFBundleSignature</key>
|
||||||
|
<string>????</string>
|
||||||
|
<key>CFBundleVersion</key>
|
||||||
|
<string>1</string>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
//
|
||||||
|
// Prefix header
|
||||||
|
//
|
||||||
|
// The contents of this file are implicitly included at the beginning of every source file.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifdef __OBJC__
|
||||||
|
#import <UIKit/UIKit.h>
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
//
|
||||||
|
// UIImageMultiFormatTests.m
|
||||||
|
// SDWebImage Tests
|
||||||
|
//
|
||||||
|
// Created by Bogdan Poplauschi on 18/07/14.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
#define EXP_SHORTHAND // required by Expecta
|
||||||
|
|
||||||
|
|
||||||
|
#import <XCTest/XCTest.h>
|
||||||
|
#import <Expecta.h>
|
||||||
|
|
||||||
|
#import "UIImage+MultiFormat.h"
|
||||||
|
|
||||||
|
|
||||||
|
@interface UIImageMultiFormatTests : XCTestCase
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@implementation UIImageMultiFormatTests
|
||||||
|
|
||||||
|
- (void)setUp
|
||||||
|
{
|
||||||
|
[super setUp];
|
||||||
|
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)tearDown
|
||||||
|
{
|
||||||
|
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||||
|
[super tearDown];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testImageOrientationFromImageDataWithInvalidData {
|
||||||
|
// sync download image
|
||||||
|
SEL selector = @selector(sd_imageOrientationFromImageData:);
|
||||||
|
|
||||||
|
UIImageOrientation orientation = [[UIImage class] performSelector:selector withObject:nil];
|
||||||
|
expect(orientation).to.equal(UIImageOrientationUp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
/* Localized versions of Info.plist keys */
|
||||||
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit c2113ad4f955e042a47a681dd6a5beb6cdd46099
|
Subproject commit 1525784d5bc1d9e7e74ff18f9d21a910b60552af
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleDevelopmentRegion</key>
|
||||||
|
<string>en</string>
|
||||||
|
<key>CFBundleExecutable</key>
|
||||||
|
<string>$(EXECUTABLE_NAME)</string>
|
||||||
|
<key>CFBundleIdentifier</key>
|
||||||
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||||
|
<key>CFBundleInfoDictionaryVersion</key>
|
||||||
|
<string>6.0</string>
|
||||||
|
<key>CFBundleName</key>
|
||||||
|
<string>$(PRODUCT_NAME)</string>
|
||||||
|
<key>CFBundlePackageType</key>
|
||||||
|
<string>FMWK</string>
|
||||||
|
<key>CFBundleShortVersionString</key>
|
||||||
|
<string>3.8.1</string>
|
||||||
|
<key>CFBundleSignature</key>
|
||||||
|
<string>????</string>
|
||||||
|
<key>CFBundleVersion</key>
|
||||||
|
<string>$(CURRENT_PROJECT_VERSION)</string>
|
||||||
|
<key>NSPrincipalClass</key>
|
||||||
|
<string></string>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
//
|
||||||
|
// WebImage.h
|
||||||
|
// WebImage
|
||||||
|
//
|
||||||
|
// Created by Florent Vilmart on 2015-03-14.
|
||||||
|
// Copyright (c) 2015 Dailymotion. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
|
//! Project version number for WebImage.
|
||||||
|
FOUNDATION_EXPORT double WebImageVersionNumber;
|
||||||
|
|
||||||
|
//! Project version string for WebImage.
|
||||||
|
FOUNDATION_EXPORT const unsigned char WebImageVersionString[];
|
||||||
|
|
||||||
|
// In this header, you should import all the public headers of your framework using statements like #import <WebImage/PublicHeader.h>
|
||||||
|
|
||||||
|
#import <WebImage/SDWebImageManager.h>
|
||||||
|
#import <WebImage/SDImageCache.h>
|
||||||
|
#import <WebImage/UIImageView+WebCache.h>
|
||||||
|
#import <WebImage/SDWebImageCompat.h>
|
||||||
|
#import <WebImage/UIImageView+HighlightedWebCache.h>
|
||||||
|
#import <WebImage/SDWebImageDownloaderOperation.h>
|
||||||
|
#import <WebImage/UIButton+WebCache.h>
|
||||||
|
#import <WebImage/SDWebImagePrefetcher.h>
|
||||||
|
#import <WebImage/UIView+WebCacheOperation.h>
|
||||||
|
#import <WebImage/UIImage+MultiFormat.h>
|
||||||
|
#import <WebImage/SDWebImageOperation.h>
|
||||||
|
#import <WebImage/SDWebImageDownloader.h>
|
||||||
|
#if !TARGET_OS_TV
|
||||||
|
#import <WebImage/MKAnnotationView+WebCache.h>
|
||||||
|
#endif
|
||||||
|
#import <WebImage/SDWebImageDecoder.h>
|
||||||
|
#import <WebImage/UIImage+WebP.h>
|
||||||
|
#import <WebImage/UIImage+GIF.h>
|
||||||
|
#import <WebImage/NSData+ImageContentType.h>
|
||||||
Loading…
Reference in New Issue