【发布时间】:2014-01-10 00:40:14
【问题描述】:
我正在尝试在我打开手机并且我在特定区域内时触发本地通知。这可以按预期工作,但是每次打开设备时,我都会收到一条新通知。如果我只是离开现有的通知,它可以被推到通知列表的底部。如果我取消现有通知并创建一个新通知,我会得到一个奇怪的动画。有没有办法:
- 更新一个已经交付的现有 UILocalNotification 以将其推送到顶部。
- 以某种方式在锁定屏幕消失时收到通知然后取消通知?
这是我现有的代码:
- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region {
if ([region isKindOfClass:[CLBeaconRegion class]]) {
CLBeaconRegion *beaconRegion = (CLBeaconRegion*)region;
UILocalNotification *existingNotification = self.beaconNotification;
switch (state) {
case CLRegionStateInside:
self.beaconNotification = [[UILocalNotification alloc] init];
self.beaconNotification.alertBody = @"You're inside the region";
[[UIApplication sharedApplication] presentLocalNotificationNow:self.beaconNotification];
if (existingNotification) {
[[UIApplication sharedApplication] cancelLocalNotification:existingNotification];
}
break;
case CLRegionStateOutside:
self.beaconNotification = [[UILocalNotification alloc] init];
self.beaconNotification.alertBody = @"You're outside the region";
[[UIApplication sharedApplication] cancelAllLocalNotifications];
break;
default:
break;
}
}
}
【问题讨论】:
标签: ios core-location core-bluetooth