【发布时间】:2015-05-11 14:58:53
【问题描述】:
我是一个相对较新的 swift 开发人员,我听说在 iOS 8 中您可以根据用户位置发送本地通知。我查看了一些代码,尤其是用于创建简单的基于时间的本地通知的代码。
var leftNotification1:UILocalNotification = UILocalNotification()
leftNotification1.alertBody = "NotidicationA"
leftNotification1.repeatInterval = NSCalendarUnit.CalendarUnitHour
leftNotification1.fireDate = NSDate(timeIntervalSinceNow: 900)
UIApplication.sharedApplication().scheduleLocalNotification(leftNotification1)
我还看到您可以用类似这样的位置触发器替换 fireDate:
var localNotification:UILocalNotification = UILocalNotification()
localNotification.regionTriggersOnce = true
localNotification.region = CLCircularRegion(circularRegionWithCenter: CLLocationCoordinate2D(latitude: 37.33233141, longitude: -122.03121860), radius: 50.0, identifier: "Location1")
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
我知道您需要获得用户的许可并轮询位置等位置。我不知道如何做这种事情并将其与该代码链接。当我像输入顶部代码一样将此代码输入到我的 ViewDidLoad 中时,由于明显的原因它不起作用,CoreLocation 没有注册并且它没有轮询位置。如果有人能告诉我如何让这个代码工作,或者更好地给我一个示例代码来看看,那就太好了。谢谢。
【问题讨论】:
标签: ios swift notifications location