Ios CLBeaconRegion NotifyEntryStateoDisplay和UILocalNotifications

Ios CLBeaconRegion NotifyEntryStateoDisplay和UILocalNotifications,ios,core-location,core-bluetooth,Ios,Core Location,Core Bluetooth,每当我打开手机,在某个特定区域内时,我都会试图得到当地的通知,以便随时开火。这与预期的一样,但每次打开设备时,我都会收到一个新的通知。如果我只保留现有的通知,它可能会被推到通知列表的底部。如果我取消现有的通知并创建一个新的通知,我会得到一个奇怪的动画。有没有办法: 更新已交付的现有UILocalNotification以将其推到顶部。 当锁屏消失时会收到通知,然后取消通知? 以下是我现有的代码: - (void)locationManager:(CLLocationManager *)manag

每当我打开手机,在某个特定区域内时,我都会试图得到当地的通知,以便随时开火。这与预期的一样,但每次打开设备时,我都会收到一个新的通知。如果我只保留现有的通知,它可能会被推到通知列表的底部。如果我取消现有的通知并创建一个新的通知,我会得到一个奇怪的动画。有没有办法:

更新已交付的现有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;
        }
    }
}

有很多方法可以检测手机是否锁定/解锁

有关进一步通知,我建议您查看以下列表: 它包含com.apple.springboard.deviceWillShutDown通知,手机关机时会调用该通知。我刚刚用这段代码对它进行了测试,它似乎可以工作,但是,应用程序会立即被终止,XCode会话也会终止,所以我不确定这对真正的应用程序有多有用

CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
                                    NULL,
                                    shutdownCallback,
                                    CFSTR("com.apple.springboard.deviceWillShutDown"),
                                    NULL,
                                    CFNotificationSuspensionBehaviorDeliverImmediately);
void shutdownCallback (CFNotificationCenterRef center, void *observer,
                 CFStringRef name, const void *object, CFDictionaryRef userInfo)
{
    NSLog(@"Shutting down");
}

考虑到这种奇怪的动画,如果你不喜欢它,那就向苹果公司报告。只有他们能修好它。如果可能的话,我认为你不应该更新通知。只需推一个新的,或者移除旧的,或者不用麻烦。这是大多数应用程序所做的,用户通常不会有任何问题。这也是一种历史记录。

是的,我可以检测到手机是否被锁定或解锁,但当他们打开手机时,我会收到通知,当他们关闭手机时,我不会再收到通知。我不确定我是否完全理解您的通知问题,但我在回答中添加了更多细节。如果有帮助,请告诉我。