Google Maps IOS + Storyboard + Segue= Crash
-
21-12-2019 - |
Domanda
Cosa faccio nella mia app sta seguendo:
Carico alcuni dati nei dati principali e quando è finita l'app finita per seguire la vista successiva (Google Map)
[self performSegueWithIdentifier:@"loadMap" sender:self];
Ma ottengo questo errore
Terminating app due to uncaught exception 'GMSThreadException', reason: 'All calls to the Google Maps SDK for iOS must be made from the UI thread'
Se faccio tutto questo, ma fai un segue con tocco su un pulsante tutto funziona bene.
Google Map View Controller in Storyboard ha una presa GMSMapView View Outlet con codice init
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:45.331875
longitude:14.450455
zoom:14];
self.mapView.camera = camera;
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = camera.target;
marker.title = @"Test title";
marker.snippet = @"Lorem ipsum...";
marker.map = self.mapView;
.
Qualcuno può aiutarmi qui?Come posso caricare il controller di visualizzazione con Google Maps a livello programmatico utilizzando Storyboard?
Soluzione
L'eccezione sembra indicare che stai cercando di eseguire un segue nella filettatura di sfondo.Per fermarlo dall'ashing, è necessario utilizzare il thread principale.Avvolgere il performSegueWithIdentifier:sender:
come segue per utilizzare il thread principale:
dispatch_async(dispatch_get_main_queue(), ^{
[self performSegueWithIdentifier:@"loadMap" sender:self];
});
. Altri suggerimenti
per SWIFT:
dispatch_async(dispatch_get_main_queue(), {})
.
Toss il codice in quelle cocenze ...