当用户退出区域时删除已触发的基于位置的通知 [英] Remove fired Location-Based notification when user exits region

查看:75
本文介绍了当用户退出区域时删除已触发的基于位置的通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的应用设置了(默认iOS8)基于位置的通知。

I've setup (default iOS8) location-based notifications for my app.

UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.regionTriggersOnce = NO;
notification.userInfo = @{ @"notification_id" : @"someID" };
notification.region = region;
notification.alertBody = alertBody;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];

当用户进入指定区域时,通知显示在 NotificationCenter 正确。

When a user enters the specified region, the notification is shown in the NotificationCenter correctly.

但是,我想在用户退出该区域时删除该通知消息,因为用户没有任何意义看看通知中心,直到他们收到一条消息,如下所示:

However, I want to remove that notification message when the user exits that region, because it makes little sense for the user to go home and look at the notification center until they recieve a message which looks like so:


你在XXXXX!

"You are at XXXXX!"

有没有人试过类似的东西?

Has anyone tried something similar? The documentation is unclear on how this can be done.

推荐答案

CLRegion 对象具有以下特殊属性: notifyOnEntry notifyOnExit

您需要的所有内容都是更新代码如下:

CLRegion object has special properties for that: notifyOnEntry and notifyOnExit.
Everything that you need is update code in this way:

CLRegion *region = .... // Configure region here
region.notifyOnEntry = YES;
region.notifyOnExit = NO;  

UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.regionTriggersOnce = NO;
notification.userInfo = @{ @"notification_id" : @"someID" };
notification.region = region;
notification.alertBody = alertBody;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];

以下是Apple 文档来解释它:

Here is Apple documentation that explains it:


@property(nonatomic,copy)CLRegion * region

为此
属性赋值会导致本地通知在用户
跨越区域的边界。

区域对象本身定义
当用户输入或退出
区域时是否触发通知。

这篇关于当用户退出区域时删除已触发的基于位置的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆