gpt4 book ai didi

ios - 当用户退出区域时删除触发的基于位置的通知

转载 作者:技术小花猫 更新时间:2023-10-29 10:52:27 28 4
gpt4 key购买 nike

我已经为我的应用程序设置(默认 iOS8)基于位置的通知。

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

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

但是,我想在用户离开该区域时删除该通知消息,因为用户回家并查看通知中心直到他们收到如下所示的消息是没有意义的:

"You are at XXXXX!"

有人试过类似的东西吗?文档不清楚如何做到这一点。

最佳答案

CLRegion 对象为此具有特殊属性:notifyOnEntrynotifyOnExit
您所需要的只是以这种方式更新代码:

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 documentation这解释了它:

@property(nonatomic, copy) CLRegion *region
Assigning a value to this property causes the local notification to be delivered when the user crosses the region’s boundary.
The region object itself defines whether the notification is triggered when the user enters or exits the region.

关于ios - 当用户退出区域时删除触发的基于位置的通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31646853/

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