我有一个导航应用程序,在获取位置更新时使用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];
}
}会感谢你的帮助。
发布于 2015-10-21 11:19:51
好的,我知道了。
问题不在于UILocalNotification,而在于位置管理器。
在iOS 9中,CLLocationManager有一个新的BOOL属性--默认为NO的allowsBackgroundLocationUpdates。
如果您想继续获取位置更新,您可能希望将其设置为“是”。
这解决了我的问题。
https://stackoverflow.com/questions/33241954
复制相似问题