我想獲得本地通知,隨時打開我的手機,並且我處於特定區域內。這按預期工作,但每次我打開設備時,都會收到新通知。如果我只是離開現有的通知,它可以被推到通知列表的底部。如果我取消現有通知並創建一個新通知,我會看到一個奇怪的動畫。有沒有辦法: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