我正在开发一款应用程序,当用户接近一些地标时,它会使用区域监控来提醒用户。一切都很好,但当应用程序在后台时,我得不到警报。当我打开这个应用程序时,所有的提醒都会弹出来。我想要的是在应用程序处于后台时获得它们。我想知道这是否可能,或者应用程序是否需要运行才能收到警报?任何帮助都将不胜感激。
更新:问题似乎是我使用了Alerts而不是本地通知。下面是我使用的代码:
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
NSLog(@"Entered Region - %@", region.identifier);
[self showRegionAlert:@"You are near: " forRegion:region.identifier];
}如何将其更改为本地通知?
发布于 2013-02-25 06:41:28
中的“测试您的应用程序区域监控”部分
如果您在前台和后台之间来回切换,阈值条件可能不会满足,并在您再次将应用程序带到前台之前触发。
此外,当后台应用程序收到通知时,只有一个小窗口来处理消息。尝试执行网络请求可能会超时...
检查plist设置-仅在需要高精度定位时才将位置声明为UIBackgroundModes。即使在没有定义位置的情况下,重要的位置更改仍然有效。
检查是否正在调用locationManager:didUpdateLocations:和locationManager:didFailWithError:,并且没有发布错误。
检查是否在plist中将ApplicationRunsInBackground设置为NO。
尝试实现AppDelegates applicationDidEnterBackground:,应用程序:didFinishLaunchingWithOptions:和好友,以找出在给定时间您在应用程序生命周期中的位置。
发布于 2014-11-25 18:42:35
UILocalNotification* localNotification = [UILocalNotification分配初始化];localNotification.alertBody =@“我在该区域”;localNotification.userInfo = [NSDictionary allocinitWithObjectsAndKeys:@"nearBy",@"type",nil];localNotification.timeZone = NSTimeZone defaultTimeZone;localNotification.soundName = UILocalNotificationDefaultSoundName;[UIApplication sharedApplication localNotification
发布于 2015-09-30 17:32:24
- (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];
}https://stackoverflow.com/questions/15057263
复制相似问题