我在这段代码中遇到两个错误,帮我解决一下

时间:2016-08-29 05:26:36

标签: ios swift background

码: var bgTask:BackgroundTaskManager! = UIApplication.sharedApplication()。beginBackgroundTaskWithExpirationHandler({() - > Void in 打印(“结束后台任务”) UIApplication.sharedApplication()。endBackgroundTask(self.bgTask) self.bgTask = UIBackgroundTaskInvalid }) self.timer = NSTimer.scheduledTimerWithTimeInterval(             60,             target:self.locationManager,             selector:#selector(self.startUpdatingLocation),             userInfo:nil,重复:true)

1 个答案:

答案 0 :(得分:0)

您正在使用self.bgTaskself.timerself.locationManager等,然后您必须在全球范围内声明它,

var bgTask: UIBackgroundTaskIdentifier! = UIBackgroundTaskIdentifier()

var timer: NSTimer! = NSTimer()

var locationManager : CLLocationManager!  = CLLocationManager()

第二件事var bgTask: BackgroundTaskManager!是错误的,它应该是var bgTask: UIBackgroundTaskIdentifier!