-1

我试图弄清楚如何检查基于区域的UILocalNotification是否被解雇。我搜索并发现当用户退出区域时删除触发的基于位置的通知,但它对我没有帮助。

我已经配置了一个基于区域的区域UILocalNotification,当用户进入该特定区域时将触发该区域,并UILocalNotification在应用程序关闭时交付。

现在,当用户打开应用程序时,我如何检查该区域是否UILocalNotification被解雇。

4

2 回答 2

0

代码片段:

    -(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];
            }
        }
    }
于 2016-03-02T09:14:08.867 回答
-1

使用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文件,如下图所示:

在此处输入图像描述

于 2016-03-02T08:39:53.203 回答