每当我打开手机,并且我在一个特定的区域内时,我都试图得到当地的通知。这如预期的工作,但每次我打开我的设备,我会得到一个新的通知。如果我只保留现有的通知,它可以向下推到通知列表的底部。如果我取消现有的通知并创建一个新的通知,我就会得到一个奇怪的动画。有没有办法:
以下是我现有的代码:
- (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;
}
}
}发布于 2014-01-10 21:30:01
确实有一些方法可以检测手机是否锁定/解锁Is there a way to check if the iOS device is locked/unlocked?。
关于进一步的通知,我建议您查看这个列表:http://iphonedevwiki.net/index.php/SpringBoard.app/Notifications--它包含在手机关机时调用的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");
}考虑到奇怪的动画,如果你不喜欢它,然后报告给苹果。只有他们才能修好它。我认为您不应该更新通知(如果这是可能的话)。只要推动一个新的,或者删除旧的,或不麻烦它。这是大多数应用程序所做的,用户通常对此没有问题。它也是一种历史。
https://stackoverflow.com/questions/21034175
复制相似问题