11

Using iPhone6, Xcode 8.1, running iOS 10.1.1, executing the following Swift code I keep getting

Unable to retrieve CarrierName

Error message appears before my first ViewController even loads. I searched for solutions to similar (but not same) CarrierName issues. Most of them recommend to import CoreTelephony. I Added the import of CoreTelephony but i still get the same error. Below is the code snippet that shows viewDidLoad followed by the console output. Any insights into this error?

//  ViewController.swift
//  MapLocator

import UIKit
import MapKit
import CoreLocation
import CoreTelephony


class ViewController: UIViewController, UISearchBarDelegate, MKMapViewDelegate,UINavigationControllerDelegate {
    var searchController:UISearchController!
    var annotation:MKAnnotation!
    var localSearchRequest1:MKLocalSearchRequest!
    var localSearchRequest2:MKLocalSearchRequest!
    var localSearch1:MKLocalSearch!
    var localSearch2:MKLocalSearch!
    var localSearchResponse1:MKLocalSearchResponse!
    var localSearchResponse2:MKLocalSearchResponse!
    var error:NSError!
    var pointAnnotation:MKPointAnnotation!
    var pinAnnotationView:MKPinAnnotationView!
    var placeMark1:MKPlacemark!
    var myRoute : MKRoute?
    var coord1 : CLLocationCoordinate2D!
    var coord2 : CLLocationCoordinate2D!
    //    var newPt : MKMapPoint!
    
    //    var lineArrayPtr = [MKMapPoint]()
    var lineArrayPtr:UnsafeMutablePointer<MKMapPoint>? = nil
    var pointIndex : Int = 0
    
    var lp1 : MKMapPoint!
    var lp2 : MKMapPoint!
    var lp3 : MKMapPoint!
    var lp4 : MKMapPoint!
    
    var searchButtonClicked = 0
    var buttonTouchCount : Double = 0
    let tapsPerMeter : Double = 2
    var pointsPerMeter : Double!
    var tapDistance : Double!
    
    //**************
    override func viewDidLoad() {
        super.viewDidLoad()
        mapView.delegate = self
        print("Entered viewDidLoad")
        
        let latitude_x: Double = 42.755139
        let longitude_x: Double = -71.584
        
        // Init the zoom level
        let coordinate:CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: latitude_x, longitude: longitude_x)
        //let span = MKCoordinateSpanMake(100, 80)
        let span = MKCoordinateSpanMake(0.01, 0.01)
        let region = MKCoordinateRegionMake(coordinate, span)
        self.mapView.setRegion(region, animated: true)
        print("mapView region set")
        
    }

********************* Console Output *********************** 2016-11-19 22:02:14.442048 MapLocator 3 Match[289:23903] [LogMessageLogging] 6.1 Unable to retrieve CarrierName. CTError: domain-2, code-5, errStr:((os/kern) failure)

Entered viewDidLoad

mapView region set

Community
  • 1
  • 1
davidwoj55
  • 131
  • 1
  • 4
  • Where did you declare your mapView? I just ran into the same issue and I made a mistake by setting the mapView to the viewControllers view property and adding it as a subview. Then this log message appeared and the App froze. Might have nothing to do with your error though. – mjrehder Jan 07 '17 at 12:35
  • A bit more info, but no solution https://forums.developer.apple.com/thread/69246 – Alexander Vasenin Feb 07 '17 at 04:18
  • Did you get solution for this..? Im having the same problem..! – Anish Kodeboyina May 26 '17 at 19:04

4 Answers4

0

Tray adding CoreTelephony to the AppDelegate maybe? You ViewController implementation is not accessing any CoreTelephony framework methods, thus your problem lies elsewhere.

der_michael
  • 3,151
  • 1
  • 24
  • 43
  • Thank you for responding. Good suggestion but still getting the error. The strange thing is that I can put some code in my viewDidLoad function to read the carrier name and it reads correctly. Does that help solve this mystery? – davidwoj55 Nov 21 '16 at 23:41
  • 1
    Any luck? I too, am having this problem. – Noah G. Dec 06 '16 at 17:28
0

On my iOS device this happens because Settings->Privacy->Location Settings<(app name)->Allow Location Settings isn't set to either "Never" or "While Using the App". Once I set it - it works.

Vin
  • 31
  • 8
0

As a solution to a different issue I did the following. Whether this fixes it or just suppresses the msg I don't know, as I was getting the msg but it was never crashing my app.

In Xcode

  • Click on your active scheme name right next to the Stop button
  • Click on Edit Scheme....
  • in Run (Debug) select the Arguments tab
  • in Environment Variables click +
  • add variable: OS_ACTIVITY_MODE = disable

credit here : https://stackoverflow.com/a/40160779

Community
  • 1
  • 1
Craig Frey
  • 29
  • 2
0

Maybe this is a litle dumb but check that XCode Maps capabilities is active :) .

Eva Madrazo
  • 4,731
  • 2
  • 23
  • 33