Offline Map in Xamarin Forms (iOS) is blank whereas in UWP it works fine

608
2
12-15-2020 08:06 AM
KrishnaShinde
New Contributor II

I am running a Xamarin Forms application supporting both UWP and iOS. We have a TPK file on the device to be used in offline mode. And it works perfectly fine in UWP. I can see the map, interact with it. But in iOS, I get a blank map. The map initialization code is the same for both platforms.

I use different code to load the map based on the Device OS platform

 

 

 

// Using following code to load map on iPad. The tpk file is stored in Files app on iPad and we are allowing user to select the tpk file 
var result = await FilePicker.PickAsync(); 
var mapPath = result.FullPath; 
var tileCache = new TileCache(mapPackagePath); ArcGISTiledLayer tileLayer = new ArcGISTiledLayer(tileCache); 
Map = new Map(new Basemap(tileLayer)); 

// Using following code to load on Windows (UWP). On Windows, we are just providing the path where tpk file is located and it works fine. 
var mapPackageFolder = @"C:\Temp\Map Files"; 
var mapPackageFile = @"Topo.tpk"; 
var mapPackagePath = System.IO.Path.Combine(mapPackageFolder,mapPackageFile); var tileCache = new TileCache(mapPackagePath); 
ArcGISTiledLayer tileLayer = new ArcGISTiledLayer(tileCache); 
Map = new Map(new Basemap(tileLayer)); 

 

 

 

Following is the result in UWP:

Working sample in UWP 

 

Following is the result in iOS:

Sample in iOS 

 

Can someone help me with this?

Thanks in advance.

 

 

0 Kudos
2 Replies
dotMorten_esri
Esri Frequent Contributor

Try loading the layer explicitly and see if an error is thrown (and what that error is):

try {
  await tileLayer.LoadAsync();
}
catch(System.Exception ex) {
  // Inspect ex here
}

 

I'm guessing the issue is your app might not be able to directly read from the path you're specifying.

0 Kudos
JoeHershman
MVP Regular Contributor

Not sure I understand this comment:

// Using following code to load map on iPad. The tpk file is stored in Files app on iPad and we are allowing user to select the tpk file 

Pretty sure in order to load the file it will need to be in you project folder for the application.  To create a project folder the following permission is set in info.plist

<key>UIFileSharingEnabled</key>
<true/>

That will create a project folder that can be found looking at the On My iPad tab in the file browser

iPad Pro (9.7-inch) 2020-12-15 12-00-12.png 

There will be the project folder and the tpk file can be located there.  Below are folders for two applications installed on my iPad.  If you have collector you would see a folder for Collector

iPad Pro (9.7-inch) 2020-12-15 12-01-47.png

0 Kudos