首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >背景UILocalNotification - iOS 9

背景UILocalNotification - iOS 9
EN

Stack Overflow用户
提问于 2015-10-20 16:29:02
回答 1查看 1.3K关注 0票数 1

我有一个导航应用程序,在获取位置更新时使用UILocalNotification

当应用程序转到iOS 9设备的后台时(锁定屏幕/按下主按钮)--它将停止接收通知。工作在iOS 8设备上。

当应用程序在前台时,我会收到通知,而不是在后台(当然,这更重要)。

代码如下所示:

代码语言:javascript
复制
- (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];
    }
}
  • 我一直在申请授权
  • 我已经检查了背景模式->位置更新
  • 我已登记用户通知。

会感谢你的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-21 11:19:51

好的,我知道了。

问题不在于UILocalNotification,而在于位置管理器。

在iOS 9中,CLLocationManager有一个新的BOOL属性--默认为NO的allowsBackgroundLocationUpdates

如果您想继续获取位置更新,您可能希望将其设置为“是”。

这解决了我的问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33241954

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档