【发布时间】:2015-10-20 16:29:02
【问题描述】:
我有一个导航应用,它在获取位置更新时使用UILocalNotification。
当应用程序在 iOS 9 设备上进入后台(锁定屏幕/按下主页按钮)时 - 它会停止接收通知。适用于 iOS 8 设备。
当应用程序处于前台而不是后台时,我会收到通知(这当然更重要)。
代码如下所示:
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations
{
CLLocation *currLocation = [locations lastObject];
CLLocationDistance dist = [currLocation distanceFromLocation:[[CLLocation alloc] initWithLatitude:self.coordinate.latitude longitude:self.coordinate.longitude]];
BOOL gotToDestination = dist < 60;
if (gotToDestination) {
UILocalNotification* n1 = [[UILocalNotification alloc] init];
n1.alertBody = [NSString stringWithFormat:@"You have arrived!"];
n1.soundName = UILocalNotificationDefaultSoundName;
n1.fireDate = [NSDate date];
[[UIApplication sharedApplication] presentLocalNotificationNow:n1];
}
}
- 我一直请求授权
- 我已检查后台模式 -> 位置更新
- 我已注册用户通知
感谢您的帮助。
【问题讨论】:
标签: ios objective-c ios9 cllocationmanager uilocalnotification