2014-01-10 17 views
1

我想获得本地通知,随时打开我的手机,并且我处于特定区域内。这按预期工作,但每次我打开设备时,都会收到新通知。如果我只是离开现有的通知,它可以被推到通知列表的底部。如果我取消现有通知并创建一个新通知,我会看到一个奇怪的动画。有没有办法:CLBeaconRegion notifyEntryStateOnDisplay和UILocalNotifications

  1. 更新已经交付的现有UILocalNotification推到顶部。
  2. 当锁定屏幕消失并取消通知时会以某种方式得到通知?

这里是我现有的代码:

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

回答

0

有一定的方式,如果手机被锁定检测/解锁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"); 
} 

考虑到奇怪的动画,如果你不喜欢它,然后向Apple报告。只有他们可以解决它。我认为你不应该更新通知(如果这是可能的话)。只需推一个新的,并删除旧的或不打扰它。这是大多数应用程序所做的,用户通常不会遇到任何问题。它也是一种历史。

+0

是的,我可以检测到手机是锁定还是解锁,但当他们打开手机时我会收到通知,并且在他们关闭手机时我不会再收到通知。 –

+0

我不确定是否完全了解您的通知问题,但我在答案中添加了更多详细信息。让我知道它是否有帮助。 – allprog

相关问题