作者:鐘彦璋864175 | 来源:互联网 | 2023-09-16 17:52
IsthereanywaytorunNSTimerformorethan3minsinbackground?Ihavetocreatesimpleappthat
Is there any way to run NSTimer for more than 3 mins in background? I have to create simple app that uses
有没有办法在后台运行NSTimer超过3分钟?我必须创建使用的简单应用程序
`locationManager(manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], inRegion region: CLBeaconRegion)`
for scan my beacons. I have run into problem when I needed to check if user is exactly 10 seconds near closest beacon. I created
扫描我的信标。当我需要检查用户是否距离最近的信标10秒时,我遇到了问题。我建立
var timer: NSTimer?
var lastClosestBeacon: CLBeacon? {
didSet {
timer?.invalidate()
timer = NSTimer.scheduledTimerWithTimeInterval(10, target: self, selector: "showLocalNotification", userInfo: nil, repeats: false)
// NSRunLoop.mainRunLoop().addTimer(timer!, forMode: NSDefaultRunLoopMode)
}
}
When closest beacon changes lastClosestBeacon is set and timer is scheduled. It is working in App and for 3 mins when user enters background(locks phone etc.) with help from Scheduled NSTimer when app is in background? Is there any possibility to check that for more than 3 mins ?
当最近的信标更改时,设置lastClosestBeacon并安排计时器。当应用程序处于后台时,当用户在预定NSTimer的帮助下进入后台(锁定手机等)时,它正在App中工作3分钟?有没有可能检查超过3分钟?
PS. I have already added Background Modes with location updates.
PS。我已经添加了带有位置更新的后台模式。
2 个解决方案