gpt4 book ai didi

ios - UILocalNotification 在 ios7 中只触发一次

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:01:14 24 4
gpt4 key购买 nike

我正在开发一个 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 方法。

https://developer.apple.com/library/ios/documentation/userexperience/conceptual/LocationAwarenessPG/RegionMonitoring/RegionMonitoring.html

测试 iOS 应用的区域监控支持

When testing your region monitoring code in iOS Simulator or on a device, realize that region events may not happen immediately after a region boundary is crossed. To prevent spurious notifications, iOS doesn’t deliver region notifications until certain threshold conditions are met. Specifically, the user’s location must cross the region boundary, move away from the boundary by a minimum distance, and remain at that minimum distance for at least 20 seconds before the notifications are reported.

The specific threshold distances are determined by the hardware and the location technologies that are currently available. For example, if Wi-Fi is disabled, region monitoring is significantly less accurate. However, for testing purposes, you can assume that the minimum distance is approximately 200 meters.

关于ios - UILocalNotification 在 ios7 中只触发一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22687427/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com