Skip to content

Crash on iOS when opening Sygic Truck map via MapLauncher #215

@noureen

Description

@noureen

When attempting to open directions using MapLauncher with the Sygic Truck map on iOS, the app crashes with the following error:

Swift runtime failure: Unexpectedly found nil while unwrapping an Optional value
UIApplication.shared.open(URL(string:url)!, options: [:], completionHandler: nil)

Steps to reproduce:

  • Install the Flutter MapLauncher plugin.
  • Ensure Sygic Truck app is installed on the iOS device.
  • Call MapLauncher.installedMaps and select the map with mapType: sygicTruck.
  • App crashes immediately.

Code:

class MapLauncherDemo extends StatelessWidget {
  openMapsSheet(context) async {
    final coords = Coords(37.759392, -122.5107336);
    final title = "Ocean Beach";
    final availableMaps = await MapLauncher.installedMaps;

    showModalBottomSheet(
      context: context,
      builder: (BuildContext context) {
        return SafeArea(
          child: SingleChildScrollView(
            child: Container(
              child: Wrap(
                children: <Widget>[
                  for (var map in availableMaps)
                    ListTile(
                      onTap: () {
                        try {
                          map.showDirections(
                            destination: coords,
                            destinationTitle: title,
                          );
                        } catch (e) {
                          print(e);
                        }
                      },
                      title: Text(map.mapName),
                    ),
                ],
              ),
            ),
          ),
        );
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Map Launcher Demo')),
        body: Center(
          child: MaterialButton(
            onPressed: () => openMapsSheet(context),
            child: Text('Show Maps'),
          ),
        ),
      ),
    );
  }
}

Following Queries Schemes:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>comgooglemaps</string>
    <string>baidumap</string>
    <string>iosamap</string>
    <string>waze</string>
    <string>yandexmaps</string>
    <string>yandexnavi</string>
    <string>citymapper</string>
    <string>mapswithme</string>
    <string>osmandmaps</string>
    <string>dgis</string>
    <string>qqmap</string>
    <string>here-location</string>
    <string>tomtomgo</string>
    <string>copilot</string>
    <string>com.sygic.aura</string>
    <string>nmap</string>
    <string>kakaomap</string>
    <string>tmap</string>
    <string>szn-mapy</string>
    <string>mappls</string>
    <string>moovit</string>
    <string>neshan</string>
</array>

Info:

iOS device,
Flutter 3.38.7 • channel stable • https://github.com/flutter/flutter.git
Tools • Dart 3.10.7 • DevTools 2.51.1
MapLauncher version: 4.4.2
Sygic Truck installed.

Notes:
The crash occurs because the URL scheme used in the plugin for Sygic Truck (com.sygic.aura://coordinate|lat|lng|drive) seems invalid for the Truck version. The plugin force-unwraps the URL, causing a fatal error.

Stack Trace:

flutter: availableMaps: [AvailableMap { mapName: Apple Maps, mapType: apple }, AvailableMap { mapName: Google Maps, mapType: google }, AvailableMap { mapName: Citymapper, mapType: citymapper }, AvailableMap { mapName: MAPS.ME, mapType: mapswithme }, AvailableMap { mapName: Sygic Truck, mapType: sygicTruck }]
Process 4882 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = Swift runtime failure: Unexpectedly found nil while unwrapping an Optional value
    frame #1: 0x00000001042646b8 map_launcher`showDirections(mapType=<unavailable>, url="com.sygic.aura://coordinate|-122.5107336|37.759392|drive", destinationTitle="Ocean Beach", destinationLatitude="37.759392", destinationLongitude="-122.5107336", originTitle=nil, originLatitude=nil, originLongitude=nil, directionsMode="driving", waypoints=nil) at MapLauncherPlugin.swift:158:50 [opt] [inlined]
   155 	            launchOptions: [MKLaunchOptionsDirectionsModeKey: getDirectionsMode(directionsMode: directionsMode)]
   156 	        )
   157 	    default:
-> 158 	        UIApplication.shared.open(URL(string:url)!, options: [:], completionHandler: nil)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions