【问题标题】:location based `local Notification` works in the `background` but not in the `foreground`基于位置的“本地通知”在“背景”中有效,但在“前景”中无效
【发布时间】:2013-05-03 14:29:37
【问题描述】:

只要位置靠近,通知就会激活,但它只在后台工作。即使触发事件发生在前台和后台。

- (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;

}

【问题讨论】:

  • 对,那你怎么解决呢?
  • 修复什么? application:didReceiveLocalNotification 被触发,因此如果您想向用户显示某些内容,则需要从那里处理您的操作。
  • 详细说明如何显示通知将解决它。

标签: ios uilocalnotification cllocation region background-foreground


【解决方案1】:

在您的 didReceiveLocalNotification 方法中,您可以向用户显示警报,因为如果应用程序在前台,则不会处理通知。

UIAlertView *alert = [[UIAlertView alloc]
        initWithTitle: @"Something"
        message: @"Something else you want to tell the user"
        delegate:self
        cancelButtonTitle:@"OK"
        otherButtonTitles:nil];
[alert show];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-23
    • 2023-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多