小编bre*_*eno的帖子

在后台的位置不起作用

我正在开发一个代码,它应该每10分钟获取一次我的位置并在CoreData中获得救赎.当我走进背景与conectavo应用程序到xcode无法看到服务正在运行的日志,但当我走出街道时,他根本没有保存或保存太少次.

这是我应该执行此功能的代码的一部分.请参阅codeData中的保存:

var saveLocationInterval = 60.0

func applicationDidEnterBackground(application: UIApplication) {
        UIApplication.sharedApplication().beginBackgroundTaskWithExpirationHandler(nil)
        self.timer = NSTimer.scheduledTimerWithTimeInterval(saveLocationInterval, target: self, selector: #selector(AppDelegate.saveLocation), userInfo: nil, repeats: true)
        NSRunLoop.currentRunLoop().addTimer(self.timer, forMode: NSRunLoopCommonModes)

        locationController.startUpdatingLocation()
    }

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

func saveLocation(){
        print("======")
        let logUser = NSEntityDescription.insertNewObjectForEntityForName("LOG_GPS", inManagedObjectContext: self.managedObjectContext) as! LOG_GPS

        if locationController.location == nil{
            logUser.latitude = ""
            logUser.longitude = ""
        } else {
            logUser.latitude = "\(locationController.location!.coordinate.latitude)"
            logUser.longitude = "\(locationController.location!.coordinate.longitude)"
        }

        logUser.velocidade = userSpeed > 0 ? Int(userSpeed) : 0
        logUser.address = "\(userSpeed)"

        if …
Run Code Online (Sandbox Code Playgroud)

core-data locationmanager ios swift

3
推荐指数
1
解决办法
565
查看次数

swift 2.3 to swift 3.0

我有一个项目是在xcode 7中使用swift 2开始的.我现在在xcode 8中使用swift 2.3.当我尝试迁移到pro 3时,我得到了几个错误没有项目.来自库和我的代码.首先,我更新我的pod,然后自动转换项目.我的怀疑是:如果某些库可以引起错误,我可以解锁并转换?在开始对话之前我是否必须准备一些东西?在我读到的关于它的文章中,我没有说任何关于它的内容.如果你继续使用swift 2.3,你将来会遇到什么问题吗?

应用程序非常大,最佳选择是什么?

ios swift swift3

1
推荐指数
1
解决办法
2563
查看次数

标签 统计

ios ×2

swift ×2

core-data ×1

locationmanager ×1

swift3 ×1