我正在为iPhone开发一个位置日记应用程序,我正在尝试使用iOS 8的新访问监控API.我已经阅读了Xcode文档并观看了WWDC 2014视频,我想我已经正确实现了startMonitoringVisits和didVisit方法.但是,在构建应用程序的其余部分之前,我想知道它们是否确实在工作.
如何确定我的应用是否正在接收访问数据?有没有办法在Xcode中使用iPhone模拟器来测试访问事件?或者我是否真的要到处走走,在不同的地方停留并等待访问注册?
如果有任何代码示例都在Swift中,我真的很感激,因为我对它更加满意,但我不想过于苛刻,所以如果你有一些Objective-C例子,请不要犹豫.
谢谢.
编辑:我最初询问访问监控是否在"设置">"隐私">"位置服务">"系统服务"中关闭"常用位置"时有效.我做了一些测试,答案是肯定的,即使用户关闭了常用位置,访问监控也能正常工作.该设置似乎仅适用于内置访问跟踪,例如地图应用.
为什么Swift不允许我为Foo<U>类型的变量赋值Foo<T>,其中U是T的子类?
例如:
class Cheese {
let smell: Int
let hardness: Int
let name: String
init(smell: Int, hardness: Int, name: String) {
self.smell = smell
self.hardness = hardness
self.name = name
}
func cut() {
print("Peeyoo!")
}
}
class Gouda: Cheese {
let aged: Bool
init(smell: Int, hardness: Int, name: String, aged: Bool) {
self.aged = aged
super.init(smell: smell, hardness: hardness, name: name)
}
override func cut() {
print("Smells delicious")
}
}
class Platter<Food> {
var food: …Run Code Online (Sandbox Code Playgroud) 我正在开发一个应用程序来监控重要的位置更改,以便在后台获取用户的位置.我已经成功地实施locationManager.startMonitoringSignificantLocationChanges和locationManager:didUpdateLocations与locationManager:didFailWithError我的方法CLLocationManagerDelegate.
但是,SLC实际上比我需要的更准确.根据Apple的文档 - 并且通过我的测试证实 - slc大约每500米触发一次位置更新,并在5到10分钟之间触发.因此,我locationManager.allowDeferredLocationUpdatesUntilTravelled:timeout在我的委托didUpdateLocations方法中实现,如本指南中所述:http://apple.co/1W4gqEJ.
这是我的代码:
var deferringUpdates = false
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
for location in locations {
NSLog("Significant location change recorded:\n%@", location)
}
if let location = locations.first {
let secondsAgo: NSTimeInterval = location.timestamp.timeIntervalSinceNow
// Only process the location if it is very recent (less than 15 seconds old).
if abs(secondsAgo) < 15.0 {
saveExtendedUserInfo(withLocation: location)
}
} …Run Code Online (Sandbox Code Playgroud)