2016-05-09 8 views
1

Dieser Crash-Protokoll ist, dass ich bekommen von CrashlyticsCorelocation ist null und App-Abstürze beim Start

Crashed: com.apple.main-thread 
0 Jemiyet      0x10015e794 specialized AppDelegate.updateloc(String, long : String) ->() (AppDelegate.swift:350) 
1 Jemiyet      0x10015e900 specialized AppDelegate.locationManager(CLLocationManager, didUpdateLocations : [CLLocation]) ->() (AppDelegate.swift:281) 
2 Jemiyet      0x10015c058 @objc AppDelegate.locationManager(CLLocationManager, didUpdateLocations : [CLLocation]) ->() (AppDelegate.swift) 
3 CoreLocation     0x18961c8b8 (null) + 21836 
4 CoreLocation     0x189618aac (null) + 5952 
5 CoreLocation     0x189612e48 (null) + 880 
6 CoreFoundation     0x18288900c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 20 
7 CoreFoundation     0x182888944 __CFRunLoopDoBlocks + 308 
8 CoreFoundation     0x182886d8c __CFRunLoopRun + 1960 
9 CoreFoundation     0x1827b0d10 CFRunLoopRunSpecific + 384 
10 GraphicsServices    0x184098088 GSEventRunModal + 180 
11 UIKit       0x187a85f70 UIApplicationMain + 204 
12 Jemiyet      0x10015c5a0 main (AppDelegate.swift:25) 
13 libdispatch.dylib    0x18234e8b8 (Missing) 

Ich benutze CLLocationmanage r in AppDelegate, um Benutzer-Standort zu erhalten, wenn App für Standortaktualisierungen wacht.

import UIKit 
import FBSDKCoreKit 
import FBSDKLoginKit 
import Quickblox 
import Fabric 
import Crashlytics 
import CoreLocation 

@UIApplicationMain 
class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate { 

    var window: UIWindow? 
    var locationManager: CLLocationManager! 

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 


      if var options = launchOptions { 

       if var _: NSNumber = options[UIApplicationLaunchOptionsLocationKey] as? NSNumber { 

        locationManager.startUpdatingLocation() 

       } 
      } 

     initLocationManager() 


     return true 
    } 

    func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { 

      if let lat = manager.location?.coordinate.latitude, 
       let long = manager.location?.coordinate.longitude { 

       //sends to server to update 
       updateloc(String(lat), long: String(long)) 
      } 

     } 


    func initLocationManager() { 
      if (nil == locationManager) { 
       locationManager = CLLocationManager() 
      } 
      locationManager.delegate = self 
      locationManager.desiredAccuracy = kCLLocationAccuracyBest 
      if #available(iOS 9.0, *) { 
       locationManager.allowsBackgroundLocationUpdates = true 
      } 

      let status = CLLocationManager.authorizationStatus() 
      if (status == CLAuthorizationStatus.AuthorizedAlways || status == CLAuthorizationStatus.AuthorizedWhenInUse) { 
       locationManager.startUpdatingLocation() 
      } 

     } 

Kann mir bitte jemand helfen?

Danke.

Antwort

0

Sie müssen initLocationManager() anrufen, bevor Sie es in locationManager.startUpdatingLocation() verwenden können.

Versuchen
if var options = launchOptions { 
    if options[UIApplicationLaunchOptionsLocationKey] != nil { 
     initLocationManager() 
     locationManager.startUpdatingLocation() 
    } 
} 
+0

oh yeah Ich werde versuchen, das es Ihnen danken –

+0

Sie auch verbessern möchten Ihre 'UIApplicationLaunchOptionsLocationKey' zu überprüfen, wie ich in der Post war. –

0

für Grund CLLocationManager Integration können Sie mit folgenden code überprüfen. Von Ihrer code ich fand, dass Sie nicht permission fragen, so erhalten Sie nil Wert.

Versuchen Sie mit unten code kann es für Sie helfen.

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
     // Override point for customization after application launch. 


     self.initLocationManager() 

     /* 
     if var options = launchOptions { 

      if var _: NSNumber = options[UIApplicationLaunchOptionsLocationKey] as? NSNumber { 
       locationManager.startUpdatingLocation() 
      } 
     } 
     */ 

     return true 
    } 


    func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { 

     if let lat = manager.location?.coordinate.latitude, 
      let long = manager.location?.coordinate.longitude { 

       //sends to server to update 
//    updateloc(String(lat), long: String(long)) 
     } 

    } 


    func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) { 

     if status == CLAuthorizationStatus.AuthorizedAlways { 
      locationManager.startUpdatingLocation() 
     } 
    } 


    func initLocationManager() { 

     if (nil == locationManager) { 
      locationManager = CLLocationManager() 
     } 
     locationManager.delegate = self 
     locationManager.desiredAccuracy = kCLLocationAccuracyBest 

     if #available(iOS 9.0, *) { 
      locationManager.allowsBackgroundLocationUpdates = true 
     } 

     let status = CLLocationManager.authorizationStatus() 

     if status == CLAuthorizationStatus.NotDetermined { 

      locationManager.requestAlwaysAuthorization() 

     }else if (status == CLAuthorizationStatus.AuthorizedAlways || status == CLAuthorizationStatus.AuthorizedWhenInUse) { 
      locationManager.startUpdatingLocation() 
     } 

    }