iOS Development

ios – Black display screen with no warnings when operating code on iPhone

Spread the love

Please might you guys level out the place i am going unsuitable, i’ve cobbled this collectively as my first app on iOS and on the simulator it runs however provides no GPS knowledge out there, on an precise cellphone its only a black show.

After 4 hours of attempting various things to no avail i am caught.

Undecided what different particulars so as to add.

import UIKit
import CoreLocation
import AVFoundation

class ViewController: UIViewController, CLLocationManagerDelegate {

let locationManager = CLLocationManager()
let debugLabel = UILabel()

override func viewDidLoad() {


func setupUI() {
    // Arrange debug label
    debugLabel.body = CGRect(x: 20, y: 100, width: view.body.width - 40, top: 40)
    debugLabel.textAlignment = .middle
    debugLabel.textColor = .black
    debugLabel.textual content = "No GPS knowledge out there"

func setupLocationManager() {
    locationManager.delegate = self

    // Verify if location providers can be found
    if CLLocationManager.locationServicesEnabled() {
    } else {
        displayError(message: "Location providers are usually not enabled. Please allow them in Settings.")

func startTimer() {
    Timer.scheduledTimer(timeInterval: 1200, goal: self, selector: #selector(triggerAnnouncement), userInfo: nil, repeats: true)

@objc func triggerAnnouncement() {

func locationManager(_ supervisor: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
    let heading = newHeading.trueHeading

    // Replace debug label with GPS knowledge
    if let location = locationManager.location {
        let latitude = location.coordinate.latitude
        let longitude = location.coordinate.longitude
        debugLabel.textual content = "Heading: (heading) degreesnLatitude: (latitude)nLongitude: (longitude)"

func announceHeading(_ heading: CLLocationDirection) {
    let synthesizer = AVSpeechSynthesizer()
    let utterance = AVSpeechUtterance(string: "Present heading is (heading) levels")

func displayError(message: String) {
    let alert = UIAlertController(title: "Error", message: message, preferredStyle: .alert)
    let okAction = UIAlertAction(title: "OK", type: .default, handler: nil)
    current(alert, animated: true, completion: nil)

Leave a Reply

Your email address will not be published. Required fields are marked *