<?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 Fail to load Traffic Service in ArcGIS Runtime SDK for iOS Questions</title>
    <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/fail-to-load-traffic-service/m-p/1307286#M7625</link>
    <description>&lt;P&gt;I'm trying to load the&amp;nbsp;&lt;A href="https://developers.arcgis.com/rest/network/api-reference/traffic-service.htm" target="_self"&gt;Traffic service&lt;/A&gt;&amp;nbsp;using the AGSPortalItem&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="swift"&gt;AGSPortalItem(url: URL(string: "http://traffic.arcgis.com/arcgis/rest/services/World/Traffic/MapServer")!)
AGSFeatureLayer(item: portalItem, layerID: 7)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;But I got an error on the application when I try to load this layer "&lt;/SPAN&gt;&lt;STRONG&gt;Invalid portal item URL.&lt;/STRONG&gt;&lt;SPAN class=""&gt;"&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 11 Jul 2023 14:46:00 GMT</pubDate>
    <dc:creator>PauloKeller</dc:creator>
    <dc:date>2023-07-11T14:46:00Z</dc:date>
    <item>
      <title>Fail to load Traffic Service</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/fail-to-load-traffic-service/m-p/1307286#M7625</link>
      <description>&lt;P&gt;I'm trying to load the&amp;nbsp;&lt;A href="https://developers.arcgis.com/rest/network/api-reference/traffic-service.htm" target="_self"&gt;Traffic service&lt;/A&gt;&amp;nbsp;using the AGSPortalItem&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="swift"&gt;AGSPortalItem(url: URL(string: "http://traffic.arcgis.com/arcgis/rest/services/World/Traffic/MapServer")!)
AGSFeatureLayer(item: portalItem, layerID: 7)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;But I got an error on the application when I try to load this layer "&lt;/SPAN&gt;&lt;STRONG&gt;Invalid portal item URL.&lt;/STRONG&gt;&lt;SPAN class=""&gt;"&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2023 14:46:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/fail-to-load-traffic-service/m-p/1307286#M7625</guid>
      <dc:creator>PauloKeller</dc:creator>
      <dc:date>2023-07-11T14:46:00Z</dc:date>
    </item>
    <item>
      <title>Re: Fail to load Traffic Service</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/fail-to-load-traffic-service/m-p/1307349#M7627</link>
      <description>&lt;P&gt;Thank you for your question! The issue you're having is that the url points to a Map Service and the code above is attempting to load it as &amp;nbsp;portal item.&lt;/P&gt;&lt;P&gt;You have a couple of options, the first is to use the code you have, but use the World Traffic Service portal item and use an "AGSArcGISMapImageLayer" instead of a feature layer (because the item represents a map service):&lt;/P&gt;&lt;LI-CODE lang="c"&gt;let trafficItem = AGSPortalItem(url: URL(string: "https://www.arcgis.com/home/item.html?id=ff11eb5b930b4fabba15c47feb130de4")!)!
let trafficLayer = AGSArcGISMapImageLayer(item: trafficItem)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The second is to use the url you currently have, but instantiate an "AGSArcGISMapImageLayer", like below&lt;/P&gt;&lt;LI-CODE lang="swift"&gt;let trafficLayer = AGSArcGISMapImageLayer(url: URL(string:"https://traffic.arcgis.com/arcgis/rest/services/World/Traffic/MapServer")!)
map.operationalLayers.add(trafficLayer)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, it is best practice to ALWAYS use "https" as opposed to simply "http" for security.&lt;/P&gt;&lt;P&gt;You will need to log in with a named user to see the data.&lt;/P&gt;&lt;P&gt;And if you haven't checked out our new Swift API, you can find it &lt;A href="https://developers.arcgis.com/swift/" target="_self"&gt;here&lt;/A&gt;!&lt;/P&gt;&lt;P&gt;Let me know if you have any more issues!&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2023 17:08:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/fail-to-load-traffic-service/m-p/1307349#M7627</guid>
      <dc:creator>MarkDostal</dc:creator>
      <dc:date>2023-07-11T17:08:50Z</dc:date>
    </item>
    <item>
      <title>Re: Fail to load Traffic Service</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/fail-to-load-traffic-service/m-p/1307570#M7628</link>
      <description>&lt;P&gt;Can I use this layer without showing the credentials popup maybe using my api key "AGSArcGISRuntimeEnvironment.apiKey"?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2023 13:46:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/fail-to-load-traffic-service/m-p/1307570#M7628</guid>
      <dc:creator>PauloKeller</dc:creator>
      <dc:date>2023-07-12T13:46:58Z</dc:date>
    </item>
    <item>
      <title>Re: Fail to load Traffic Service</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/fail-to-load-traffic-service/m-p/1307632#M7629</link>
      <description>&lt;P&gt;If you look at the "Terms of Use" in the item's &lt;A href="https://www.arcgis.com/home/item.html?id=ff11eb5b930b4fabba15c47feb130de4" target="_self"&gt;description&lt;/A&gt;&amp;nbsp;it says:&lt;/P&gt;&lt;DIV&gt;&lt;EM&gt;&lt;FONT color="#b22222"&gt;Important Note:&lt;/FONT&gt; This item requires an ArcGIS Online organizational subscription or an ArcGIS Developer account and does not consume credits. To access this item, you'll need to do one of the following:&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;UL&gt;&lt;LI&gt;&lt;EM&gt;Sign in with an account that is a member of an organizational subscription&lt;/EM&gt;&lt;/LI&gt;&lt;LI&gt;&lt;EM&gt;Sign in with a developer account&lt;/EM&gt;&lt;/LI&gt;&lt;LI&gt;&lt;EM&gt;&lt;A href="https://goto.arcgis.com/termsofuse/registeranapplication" target="_blank" rel="noopener"&gt;Register an application&lt;/A&gt; and use your application's credentials.&lt;/EM&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/DIV&gt;&lt;P&gt;So you won't be able to use an API key. &amp;nbsp;You do have a couple of other options. Depending on your use case, you can hard-code your user credentials in your app and have the service use those.&lt;/P&gt;&lt;LI-CODE lang="swift"&gt;let portal = AGSPortal.arcGISOnline(withLoginRequired: true)
portal.credential = AGSCredential(user: &amp;lt;#T##String#&amp;gt;, password: &amp;lt;#T##String#&amp;gt;)
portal.load() { [weak self] error in
    let trafficItem = AGSPortalItem(portal: portal, itemID: "ff11eb5b930b4fabba15c47feb130de4")
    let trafficLayer = AGSArcGISMapImageLayer(item: trafficItem)
    self?.map.operationalLayers.add(trafficLayer)
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or, you can follow the instructions to "&lt;A href="https://goto.arcgis.com/termsofuse/registeranapplication" target="_self"&gt;Register an application&lt;/A&gt;". &amp;nbsp;You can also find iOS SDK doc for security and authentication &lt;A href="https://developers.arcgis.com/ios/security-and-authentication/" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2023 15:44:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/fail-to-load-traffic-service/m-p/1307632#M7629</guid>
      <dc:creator>MarkDostal</dc:creator>
      <dc:date>2023-07-12T15:44:42Z</dc:date>
    </item>
  </channel>
</rss>

