mapbox / mapbox-gl-native

Interactive, thoroughly customizable maps in native Android, iOS, macOS, Node.js, and Qt applications, powered by vector tiles and OpenGL
https://mapbox.com/mobile
Other
4.37k stars 1.33k forks source link

is it supposed to work in iOS action extensions? #4734

Closed rshev closed 8 years ago

rshev commented 8 years ago

Trying to incorporate Mapbox into an iOS action extension (as I haven't found any information of such tries on the Internet). Outcome: the view shows only mapbox logo, (i) button, and is completely blank. One error on the console: Failed to inherit CoreMedia permissions from 14090: (null), it seems to be appearing on a try to access non-AppGroup NSUserDefaults. Any ideas? May I help with some logs given I could turn on some verbosity/debug logging?

Platform: iOS Mapbox SDK version: 3.2.0

Code:

        MGLAccountManager.setAccessToken("pk.XXXXXX")
        let mapView = MGLMapView(frame: self.view.bounds)
        self.view.addSubview(mapView)
        mapView.translatesAutoresizingMaskIntoConstraints = false
        mapView.topAnchor.constraintEqualToAnchor(self.view.topAnchor).active = true
        mapView.bottomAnchor.constraintEqualToAnchor(self.view.bottomAnchor).active = true
        mapView.leadingAnchor.constraintEqualToAnchor(self.view.leadingAnchor).active = true
        mapView.trailingAnchor.constraintEqualToAnchor(self.view.trailingAnchor).active = true
        mapView.showsUserLocation = true
        mapView.styleURL = MGLStyle.streetsStyleURL()
        mapView.debugMask = [.CollisionBoxesMask, .TileBoundariesMask, .TileInfoMask, .TimestampsMask]
friedbunny commented 8 years ago

We haven’t tested our SDK in app extensions and I would be somewhat surprised if you could get a map to draw with any of the extension flavors — memory limits are said to be quite low.

friedbunny commented 8 years ago

While it is a bug that MGLMapView’s map fails to appear in an action extension view, I don’t think fixing this problem would be worthwhile right now — the memory limits are too low.

For example, though a MapKit view in an action extension will load and be interactive, it will immediately receive memory warnings and be killed after a few seconds.

As an alternative to a live map, I’d suggest looking at MapboxStatic.swift, which you can use to load and display a static map image.

For posterity, here is what MGLMapView looks like when loaded in an action extension:

img_4168

EPage-Ed commented 7 years ago

I'm using a Snapshot static map in a today extension and it's working well. I'm using an AppGroup UserDefaults to share some data with the main app. This was after running into the memory limits of an extension when trying to use a live map.

friedbunny commented 7 years ago

Noting that Apple explicitly calls out the GL maps use case as being problematic in extensions:

Note: Extensions have much lower per-process memory limit. Certain technologies, such as map views and SpriteKit, carry a high baseline memory cost and may be unsuitable for use in an extension.