简体   繁体   中英

Can't download image artwork from iTunes

I'm trying to download an image from iTunes with a valid URL - but the image is NOT being downloaded. Here is the link:

http://is5.mzstatic.com/image/thumb/Music7/v4/53/fc/a2/53fca253-84b1-f2cd-4e17-98be502ec53c/UMG_cvrart_00602547534873_01_RGB72_1500x1500_15UMGIM41882.jpg/60x60bb-85.jpg

Now when I try to download the image, it returns NULL for some strange reason:

NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString: @"http://is5.mzstatic.com/image/thumb/Music7/v4/53/fc/a2/53fca253-84b1-f2cd-4e17-98be502ec53c/UMG_cvrart_00602547534873_01_RGB72_1500x1500_15UMGIM41882.jpg/60x60bb-85.jpg"]];

This is only happening for artwork for iTunes links.

(lldb) po imageData
nil

I know this is a while, but in case others are looking for a solution to this ...

In iOS 9 Apple started requiring App Transport Security on URLs. This means that "http:" needs to be replaced by "https:".

When you get an image URL like artworkUrl60 it still comes as "http:" because Apple doesn't want to break existing applications.

The logical thing to do is to replace the "http:" with "https:".

But that doesn't work! It doesn't even work if you paste it into a browser because the mzstatic.com website doesn't appear to have a valid certificate.

The solution is to either completely turn off ATS (not recommended) or to white-list mzstatic.com.

Open Info.plist and insert the following:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <false/>
    <key>NSExceptionDomains</key>
    <dict>
        <key>mzstatic.com</key>
        <dict>
            <!--Include to allow subdomains-->
            <key>NSIncludesSubdomains</key>
            <true/>
            <!--Include to allow HTTP requests-->
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
    </dict>
</dict>

That appears to fix the problem.

David

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM