首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IOS地理围栏后台警报

IOS地理围栏后台警报
EN

Stack Overflow用户
提问于 2013-02-25 06:11:44
回答 3查看 4.7K关注 0票数 4

我正在开发一款应用程序,当用户接近一些地标时,它会使用区域监控来提醒用户。一切都很好,但当应用程序在后台时,我得不到警报。当我打开这个应用程序时,所有的提醒都会弹出来。我想要的是在应用程序处于后台时获得它们。我想知道这是否可能,或者应用程序是否需要运行才能收到警报?任何帮助都将不胜感激。

更新:问题似乎是我使用了Alerts而不是本地通知。下面是我使用的代码:

代码语言:javascript
复制
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
    NSLog(@"Entered Region - %@", region.identifier);
    [self showRegionAlert:@"You are near: " forRegion:region.identifier];
}

如何将其更改为本地通知?

EN

回答 3

Stack Overflow用户

发布于 2013-02-25 06:41:28

中的“测试您的应用程序区域监控”部分

https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/LocationAwarenessPG/RegionMonitoring/RegionMonitoring.html

如果您在前台和后台之间来回切换,阈值条件可能不会满足,并在您再次将应用程序带到前台之前触发。

此外,当后台应用程序收到通知时,只有一个小窗口来处理消息。尝试执行网络请求可能会超时...

检查plist设置-仅在需要高精度定位时才将位置声明为UIBackgroundModes。即使在没有定义位置的情况下,重要的位置更改仍然有效。

检查是否正在调用locationManager:didUpdateLocations:和locationManager:didFailWithError:,并且没有发布错误。

检查是否在plist中将ApplicationRunsInBackground设置为NO。

尝试实现AppDelegates applicationDidEnterBackground:,应用程序:didFinishLaunchingWithOptions:和好友,以找出在给定时间您在应用程序生命周期中的位置。

票数 7
EN

Stack Overflow用户

发布于 2014-11-25 18:42:35

  1. 对于地理围栏解决方案,您可以参考@Niels Castle给出的答案。
  2. 对于本地通知,您可以参考以下代码:

UILocalNotification* localNotification = [UILocalNotification分配初始化];localNotification.alertBody =@“我在该区域”;localNotification.userInfo = [NSDictionary allocinitWithObjectsAndKeys:@"nearBy",@"type",nil];localNotification.timeZone = NSTimeZone defaultTimeZone;localNotification.soundName = UILocalNotificationDefaultSoundName;[UIApplication sharedApplication localNotification

票数 0
EN

Stack Overflow用户

发布于 2015-09-30 17:32:24

代码语言:javascript
复制
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
    NSLog(@"Yes! Welcome to %@",region.identifier);
    UILocalNotification* notify = [UILocalNotification new];
    notify.alertBody = [NSString stringWithFormat:@"Welcome to %@",region.identifier];
    notify.soundName = UILocalNotificationDefaultSoundName;
    if (notify.applicationIconBadgeNumber == 0) {
        notify.applicationIconBadgeNumber = 1;
    }
    [[UIApplication sharedApplication] presentLocalNotificationNow:notify];
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15057263

复制
相关文章

相似问题

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