我试图弄清楚如何检查基于区域的UILocalNotification
是否被解雇。我搜索并发现当用户退出区域时删除触发的基于位置的通知,但它对我没有帮助。
我已经配置了一个基于区域的区域UILocalNotification
,当用户进入该特定区域时将触发该区域,并UILocalNotification
在应用程序关闭时交付。
现在,当用户打开应用程序时,我如何检查该区域是否UILocalNotification
被解雇。
我试图弄清楚如何检查基于区域的UILocalNotification
是否被解雇。我搜索并发现当用户退出区域时删除触发的基于位置的通知,但它对我没有帮助。
我已经配置了一个基于区域的区域UILocalNotification
,当用户进入该特定区域时将触发该区域,并UILocalNotification
在应用程序关闭时交付。
现在,当用户打开应用程序时,我如何检查该区域是否UILocalNotification
被解雇。
代码片段:
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
NSString *regionIdentifier = [notification.userInfo objectForKey:@"regionIdentifier”];
[self removeExistingNotificationWithIdentifier: regionIdentifier];
}
-(void)removeExistingNotificationWithIdentifier:(NSString*)regionIdentifier
{
NSArray *scheduledNotifications = [[UIApplication sharedApplication]scheduledLocalNotifications];
for (UILocalNotification *notification in scheduledNotifications)
{
NSDictionary *userInfoDict = notification.userInfo;
if ([[userInfoDict objectForKey:@"regionIdentifier"] isEqualToString:regionIdentifier])
{
[[UIApplication sharedApplication]cancelLocalNotification:notification];
}
}
}
使用gpx
文件检查基于区域的通知。
示例:创建一个Location.gpx
包含您希望触发通知的位置的纬度、经度的文件。下面的代码包含两个位置的经纬度。
<?xml version="1.0"?>
<gpx version="1.1" creator="Xcode">
<wpt lat="28.53191" lon="77.38311">
<name>Google</name>
</wpt>
<wpt lat="28.50848" lon="77.40825">
<name>Apple</name>
</wpt>
</gpx>
调试时,选择Location.gpx
文件,如下图所示: