<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Download MMPK (not PrePlannedMapArea) in ArcGIS Runtime SDK for iOS Questions</title>
    <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/download-mmpk-not-preplannedmaparea/m-p/1095181#M7081</link>
    <description>&lt;P&gt;You should be able to &lt;A href="https://developers.arcgis.com/ios/api-reference/interface_a_g_s_portal_item.html#abe62127fdc0d8e8c864bba3a35505f8b" target="_blank"&gt;create an &lt;STRONG&gt;AGSPortalItem&lt;/STRONG&gt;&lt;/A&gt; for the AGOL item for the MMPK, and then call &lt;A href="https://developers.arcgis.com/ios/api-reference/interface_a_g_s_item.html#a578ee8758b6b41cf8a273a99ccbd5424" target="_blank"&gt;&lt;STRONG&gt;fetchData()&lt;/STRONG&gt;&lt;/A&gt; on that to get NSData. You can then call &lt;A href="https://developer.apple.com/documentation/foundation/nsdata/1408033-writetofile" target="_blank"&gt;&lt;STRONG&gt;NSData.writeToFile()&lt;/STRONG&gt;&lt;/A&gt; to write that MMPK to your iOS filesystem as a .mmpk file.&lt;/P&gt;</description>
    <pubDate>Thu, 02 Sep 2021 23:48:55 GMT</pubDate>
    <dc:creator>Nicholas-Furness</dc:creator>
    <dc:date>2021-09-02T23:48:55Z</dc:date>
    <item>
      <title>Download MMPK (not PrePlannedMapArea)</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/download-mmpk-not-preplannedmaparea/m-p/1095132#M7080</link>
      <description>&lt;P&gt;I have several MMPK maps on AGOL that I want to download into my app (not side load).&lt;/P&gt;&lt;P&gt;What are the proper steps to get the mmpk file downloaded into the app?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 21:22:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/download-mmpk-not-preplannedmaparea/m-p/1095132#M7080</guid>
      <dc:creator>RTC</dc:creator>
      <dc:date>2021-09-02T21:22:52Z</dc:date>
    </item>
    <item>
      <title>Re: Download MMPK (not PrePlannedMapArea)</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/download-mmpk-not-preplannedmaparea/m-p/1095181#M7081</link>
      <description>&lt;P&gt;You should be able to &lt;A href="https://developers.arcgis.com/ios/api-reference/interface_a_g_s_portal_item.html#abe62127fdc0d8e8c864bba3a35505f8b" target="_blank"&gt;create an &lt;STRONG&gt;AGSPortalItem&lt;/STRONG&gt;&lt;/A&gt; for the AGOL item for the MMPK, and then call &lt;A href="https://developers.arcgis.com/ios/api-reference/interface_a_g_s_item.html#a578ee8758b6b41cf8a273a99ccbd5424" target="_blank"&gt;&lt;STRONG&gt;fetchData()&lt;/STRONG&gt;&lt;/A&gt; on that to get NSData. You can then call &lt;A href="https://developer.apple.com/documentation/foundation/nsdata/1408033-writetofile" target="_blank"&gt;&lt;STRONG&gt;NSData.writeToFile()&lt;/STRONG&gt;&lt;/A&gt; to write that MMPK to your iOS filesystem as a .mmpk file.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 23:48:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/download-mmpk-not-preplannedmaparea/m-p/1095181#M7081</guid>
      <dc:creator>Nicholas-Furness</dc:creator>
      <dc:date>2021-09-02T23:48:55Z</dc:date>
    </item>
    <item>
      <title>Re: Download MMPK (not PrePlannedMapArea)</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/download-mmpk-not-preplannedmaparea/m-p/1095189#M7082</link>
      <description>&lt;P&gt;Thank you Nicholas, I will give that a try.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Sep 2021 01:21:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/download-mmpk-not-preplannedmaparea/m-p/1095189#M7082</guid>
      <dc:creator>RTC</dc:creator>
      <dc:date>2021-09-03T01:21:19Z</dc:date>
    </item>
    <item>
      <title>Re: Download MMPK (not PrePlannedMapArea)</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/download-mmpk-not-preplannedmaparea/m-p/1096223#M7083</link>
      <description>&lt;P&gt;Hello Nicholas,&lt;/P&gt;&lt;P&gt;I tried to load the portalItem as per your instructions but can't seem to get the portal data to load. When I call the fetchData, noting happens. I can see in the AGS logs that the request get sent but there is never a response. No errors, no data, nothing. Here is how I am calling fetchData, do you see any issues? Thanks for your assistance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="swift"&gt;// tried this way
let portalItem = AGSPortalItem(url: portal, itemID: map.itemId)
// also tried this way
let portalItem = AGSPortalItem(url: myURL)

// load portalItem
portalItem.load {error in
            if let error = error {
                print("Error load mobile map package (mmpk) failed: \(error)")
                return
            }

            if portalItem.type == .mobileMapPackage {
                print("MMPK load completed")

// fetch portal data (This never returns, no error, no data, no response)
                portalItem.fetchData { data, error in
                    if let error = error {
                        print("Error fetch data mobile map package failed: \(error)")
                        return
                    }

                    if data == nil {
                        print("Error MMPK fetch failed: no data")
                    } else {
                        print("MMPK fetch data mobile map package completed")
                        do {
                            try data?.write(to: downloadDirectory)
                            print("MMPK write data mobile map package completed")
                        } catch {
                            print("Error MMPK write data failed: \(error.localizedDescription)")
                        }
                    }
                }

            } else {
                print("Error MMPK load mobile map package (mmpk) failed")
            }

        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Sep 2021 03:25:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/download-mmpk-not-preplannedmaparea/m-p/1096223#M7083</guid>
      <dc:creator>RTC</dc:creator>
      <dc:date>2021-09-08T03:25:14Z</dc:date>
    </item>
    <item>
      <title>Re: Download MMPK (not PrePlannedMapArea)</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/download-mmpk-not-preplannedmaparea/m-p/1096385#M7085</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;I expect that the AGSPortalItem is going out of scope and is being released before fetchData completes and calls into the completion block. Try keeping a strong reference to the AGSPortalItem (maybe make it a var on your class instance). You can nil it out from within the completion block if you need to.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Sep 2021 14:26:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/download-mmpk-not-preplannedmaparea/m-p/1096385#M7085</guid>
      <dc:creator>Nicholas-Furness</dc:creator>
      <dc:date>2021-09-08T14:26:08Z</dc:date>
    </item>
    <item>
      <title>Re: Download MMPK (not PrePlannedMapArea)</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/download-mmpk-not-preplannedmaparea/m-p/1096542#M7086</link>
      <description>&lt;P&gt;There is another way to download the MMPK. You can use &lt;A href="https://developers.arcgis.com/ios/api-reference/interface_a_g_s_request_operation.html" target="_blank" rel="noopener"&gt;&lt;STRONG&gt;AGSRequestOperation&lt;/STRONG&gt;&lt;/A&gt;. The advantage here is that you have access to the download progress, and you can also avoid having to create a large Data object in memory. The AGSRequestOperation can stream the download directly to your file. You would do something like this:&lt;/P&gt;&lt;LI-CODE lang="swift"&gt;func downloadMMPK(from portalItemForMMPK: AGSPortalItem) {
    
    portalItemForMMPK.load { [weak self] error in
        
        guard let self = self else { return }
        
        if let error = error {
            print("Unable to load the portal item: \(error.localizedDescription)")
            return
        }
        
        guard let portalUrl = portalItemForMMPK.portal.url,
              let itemDataUrl = URL(string: "\(portalUrl)/sharing/rest/content/items/\(portalItemForMMPK.itemID)/data"),
              let docsFolder = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first else { return }
        
        let mmpkLocation = docsFolder.appendingPathComponent(portalItemForMMPK.name, isDirectory: false)
        
        let request = AGSRequestOperation(url: itemDataUrl)
        
        request.outputFileURL = mmpkLocation
        request.registerListener(self) { result, error in
            if let error = error {
                print("Unable to download the file: \(error.localizedDescription)")
                return
            }
            
            guard let result = result as? URL,
                  result.isFileURL else { return }
            
            let mmpk = AGSMobileMapPackage(fileURL: result)
            mmpk.load { error in
                if let error = error {
                    print("Unable to open the mmpk file: \(error.localizedDescription)")
                    return
                }
                
                if let mapFromMMPK = mmpk.maps.first {
                    self.mapView.map = mapFromMMPK
                }
            }
        }
        
        request.progressHandler = { (downloaded, total) in
            print("Downloaded \(100 * downloaded/total)%. \(total - downloaded) bytes remaining")
        }

        self.progressView.observedProgress = request.progress
        
        AGSOperationQueue.shared().addOperation(request)
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note, in that code, I've added a ProgressView to my ViewController. I'm actually showing progress twice - once printed to the console in the AGSRequestOperation's &lt;A href="https://developers.arcgis.com/ios/api-reference/interface_a_g_s_request_operation.html#a89d281bc814f0db1861ea937e67c340d" target="_blank" rel="noopener"&gt;&lt;STRONG&gt;progressHandler&lt;/STRONG&gt;&lt;/A&gt;, and at the same time by just having my UI's ProgressView lean on the AGSRequestOperation's &lt;A href="https://developers.arcgis.com/ios/api-reference/interface_a_g_s_request_operation.html#aea996a097f0db9e197c385061b00588c" target="_blank" rel="noopener"&gt;&lt;STRONG&gt;progress&lt;/STRONG&gt;&lt;/A&gt; object.&lt;/P&gt;&lt;P&gt;The key is defining the &lt;A href="https://developers.arcgis.com/ios/api-reference/interface_a_g_s_request_operation.html#a4aee208ce5c471c6936c4886cfa25f22" target="_blank" rel="noopener"&gt;&lt;STRONG&gt;outputFileURL&lt;/STRONG&gt;&lt;/A&gt; property on the AGSRequestOperation. If you do that, the registered listener will be passed a URL object, otherwise it'll get a Data object.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Sep 2021 21:17:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/download-mmpk-not-preplannedmaparea/m-p/1096542#M7086</guid>
      <dc:creator>Nicholas-Furness</dc:creator>
      <dc:date>2021-09-08T21:17:38Z</dc:date>
    </item>
    <item>
      <title>Re: Download MMPK (not PrePlannedMapArea)</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/download-mmpk-not-preplannedmaparea/m-p/1096543#M7087</link>
      <description>&lt;P&gt;Excellent, I will give that a try, thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 08 Sep 2021 21:21:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/download-mmpk-not-preplannedmaparea/m-p/1096543#M7087</guid>
      <dc:creator>RTC</dc:creator>
      <dc:date>2021-09-08T21:21:31Z</dc:date>
    </item>
    <item>
      <title>Re: Download MMPK (not PrePlannedMapArea)</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/download-mmpk-not-preplannedmaparea/m-p/1098287#M7099</link>
      <description>&lt;P&gt;Thanks Nicholas, I think this is the best solution for downloading mmpk files to an iOS app.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Sep 2021 00:19:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/download-mmpk-not-preplannedmaparea/m-p/1098287#M7099</guid>
      <dc:creator>RTC</dc:creator>
      <dc:date>2021-09-15T00:19:31Z</dc:date>
    </item>
    <item>
      <title>Re: Download MMPK (not PrePlannedMapArea)</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/download-mmpk-not-preplannedmaparea/m-p/1157694#M7303</link>
      <description>&lt;P&gt;How we can do the same in Android ??&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2022 07:33:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/download-mmpk-not-preplannedmaparea/m-p/1157694#M7303</guid>
      <dc:creator>GauravBansal0025</dc:creator>
      <dc:date>2022-03-25T07:33:10Z</dc:date>
    </item>
  </channel>
</rss>

