Ios 基于位置的“本地通知”在“后台”起作用,但在“前台”不起作用`
通知应该在位置靠近时激活,但它只在后台工作。即使触发事件发生在前台和后台Ios 基于位置的“本地通知”在“后台”起作用,但在“前台”不起作用`,ios,uilocalnotification,cllocation,region,background-foreground,Ios,Uilocalnotification,Cllocation,Region,Background Foreground,通知应该在位置靠近时激活,但它只在后台工作。即使触发事件发生在前台和后台 - (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region { //implement local notification: UIApplication *app = [UIApplication sharedApplication]; UILocalNotification *notification =
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
//implement local notification:
UIApplication *app = [UIApplication sharedApplication];
UILocalNotification *notification = [[UILocalNotification alloc] init];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
if (notification == nil)
return;
notification.fireDate = [NSDate date];
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.alertBody = [selectedTask discription];
notification.alertAction = [selectedTask taskName];
notification.soundName = UILocalNotificationDefaultSoundName;
notification.applicationIconBadgeNumber = 1;
[app presentLocalNotificationNow:notification];
localNotification = nil;
}
从didReceiveLocalNotification方法内部,您可以向用户显示警报,因为如果应用程序位于前台,则不会处理通知
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"Something"
message: @"Something else you want to tell the user"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
对,那你怎么解决?解决什么?应用程序:didReceiveLocalNotification被激发,因此如果您希望向用户显示某些内容,则需要从那里处理您的操作。详细说明如何显示通知将解决此问题。