我想获得本地通知,随时打开我的手机,并且我处于特定区域内。这按预期工作,但每次我打开设备时,都会收到新通知。如果我只是离开现有的通知,它可以被推到通知列表的底部。如果我取消现有通知并创建一个新通知,我会看到一个奇怪的动画。有没有办法:CLBeaconRegion notifyEntryStateOnDisplay和UILocalNotifications
- 更新已经交付的现有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;
}
}
}
是的,我可以检测到手机是锁定还是解锁,但当他们打开手机时我会收到通知,并且在他们关闭手机时我不会再收到通知。 –
我不确定是否完全了解您的通知问题,但我在答案中添加了更多详细信息。让我知道它是否有帮助。 – allprog