[英]UILocalNotification Fires only once in ios7
我正在開發一個iBeacon應用程序,它使用本地通知在用戶進入/退出特定區域時提醒用戶。 但是我在后台申請時只收到一次通知。 任何幫助,將不勝感激。
這是我的代碼:
- (void)locationManager:(CLLocationManager*)manager didEnterRegion:(CLRegion *)region {
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = nil;
notification.alertBody = @"Welcome";
notification.alertAction = @"View";
notification.soundName = UILocalNotificationDefaultSoundName;
notification.applicationIconBadgeNumber = 0;
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
}
-(void)locationManager:(CLLocationManager*)manager didExitRegion:(CLRegion *)region {
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = nil;
notification.alertBody = @"Thank you for coming";
notification.alertAction = @"View";
notification.soundName = UILocalNotificationDefaultSoundName;
notification.applicationIconBadgeNumber = 0;
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
}
方法didEnterRegion和didExitRegion有一些時間間隔值。 這些方法在一段時間后開火。 並確保完全退出區域。 另外你可以使用didDetermineState方法。
測試iOS應用程序的區域監視支持
在iOS模擬器或設備上測試區域監控代碼時,請注意區域事件可能不會在跨越區域邊界后立即發生。 為防止虛假通知,iOS在滿足某些閾值條件之前不會發送區域通知。 具體而言,用戶的位置必須越過區域邊界,遠離邊界移動最小距離,並在報告通知之前保持在該最小距離至少20秒。
特定閾值距離由當前可用的硬件和定位技術確定。 例如,如果禁用Wi-Fi,則區域監控的准確性要低得多。 但是,出於測試目的,您可以假設最小距離約為200米。
在結束它不起作用之前,請確保等待最多15分鍾才能調用didEnterRegion
/ didExitRegion
。 在某些設備上,檢測可能需要很長時間。 看到這里 。
我會在你的回調中添加NSLog
行,這樣你就可以看到它們是否被調用 - 我懷疑它們不是。 如果為true,則表示問題在於檢測,而不是通知。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.