首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >地理位置不发送通知(iOS)

地理位置不发送通知(iOS)
EN

Stack Overflow用户
提问于 2016-01-20 07:57:09
回答 1查看 161关注 0票数 0

每次用户通过我的客户端的存储(大约1700个商店)时,我都试图发送一个通知,但它不起作用。

谁能告诉我原因吗?

我的代码:

Store.m

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
-(CLCircularRegion*)createCircularRegion
{
    CLCircularRegion *region=[[CLCircularRegion alloc] initWithCenter:self.geoPoint radius:1000 identifier:self.identifier];

    region.notifyOnEntry=YES;

    return region;
}

viewController.m

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
-(void)startMonitoringAllStores
{
    if (![CLLocationManager isMonitoringAvailableForClass:[CLCircularRegion class]]) {
        NSLog(@"Monitoring is not available for CLCircularRegion class");
    }

    for (Store *currentStore in self.allStores) {
        CLCircularRegion *region=[currentStore createCircularRegion];
        [self.locationManager startMonitoringForRegion:region];
    }
}

-(void)getStoresFromParse
{
    [self findObjectsWithClassName:@"Stores"];

    [self.allStores addObjectsFromArray:self.allStores];

    [self startMonitoringAllStores];
}

AppDelegate.m

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.locationManager.delegate=self;
    [self.locationManager requestAlwaysAuthorization];

    return YES;
}


-(void)handleRegionEvent:(CLRegion*)region
{
    NSLog(@"Geofence triggered");
}


-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
    if ([region isKindOfClass:[CLCircularRegion class]]) {
        [self handleRegionEvent:region];
    }
}
EN

回答 1

Stack Overflow用户

发布于 2016-01-20 08:05:37

在iOS中,您只能同时监视20个位置。见苹果的文档。另外,确保您正在通过requestAlwaysAuthorization请求许可。

绕过这一限制的一种方法是找到最接近用户的19家商店并监视这些区域,然后使用20区域作为用户当前位置周围的外部边界,其半径是到第19商店的距离。当用户越过外部边界时,重新计算最近的19个存储和边界,然后重复。在代码中,你会做这样的事情。(请注意,我还没有测试过这段代码;它只是一个示例。)

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
- (void)installClosestGeofencesTo:(CLLocation *)currentLocation {
    [self removeAllGeofences];
    NSArray *closestStores = [self findClosestStoresTo:currentLocation limit:19];
    for (Store *store in closestStores) {
        CLCircularRegion *region = [[CLCircularRegion alloc] initWithCenter:store.location radius:100 identifier:store.identifier];
        [self.locationManager startMonitoringForRegion:region];
    }
    Store *furthestStore = [closestStores lastObject];
    CLCircularRegion *boundaryRegion = [[CLCircularRegion alloc] initWithCenter:currentLocation.coordinate radius:furthestStore.distance identifier:@"boundary"];
    [self.locationManager startMonitoringForRegion:boundaryRegion];
}

- (void)removeAllGeofences {
    NSArray *monitoredRegions = [self.locationManager monitoredRegions];
    for (CLRegion *region in monitoredRegions) {
        [self.locationManager stopMonitoringForRegion:region];
    }
}

- (NSArray *)findStoresClosestTo:(CLLocation *)location limit:(NSUInteger)limit {
    ...
}

在您的CLLocationManagerDelegate中,您可以这样做:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{
    if ([region.identifier isEqual:@"boundary"]) {
        [self installClosestGeofencesTo:self.locationManager.location];
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34904674

复制
相关文章
ios原生向react-native发送事件通知
@interfaceMySendMessageModule : RCTEventEmitter
conanma
2021/11/02
1.4K0
iOS8新特性之基于地理位置的消息通知UILocalNotification
iOS8中更新和公开了非常多接口,当中有一项本地消息通知UILocalNotification,大家肯定都不陌生。
全栈程序员站长
2022/07/10
4190
iOS8新特性之基于地理位置的消息通知UILocalNotification
js发送通知
https://developer.mozilla.org/zh-CN/docs/Web/API/notification/requestPermission
阿超
2023/02/20
2.2K0
js发送通知
iOS15 发送本地通知(附带声音)无法播报
iOS15版本下,配置UNNotificationSound来替换UNNotificationRequest声音,会出现没法播报问题
freesan44
2021/12/06
1.1K0
iOS15 发送本地通知(附带声音)无法播报
iOS15版本下,配置UNNotificationSound来替换UNNotificationRequest声音,会出现没法播报问题
freesan44
2021/11/05
1.5K0
fastlane结合Python 实现 iOS 自动化打包发送邮件通知
4.1 文件介绍 Appfile内部是个人开发者账号的配置 Fastfile 定义的是一个个的lane,执行不同的打包操作操作实例 单个打包 ElbT fastlane ElbT
大话swift
2019/07/04
1.5K0
Android 8.0无法发送通知栏?通知栏适配通知渠道
  不得不说Andoird的通知栏相比于IOS在使用上有着明显的不足,不仅是体验上的差异,还有大量的非关注通知铺满了通知栏,导致通知栏混乱,杂多。   为什么一个很好的通知栏功能现在却变得这么遭用户讨厌?很大一部分原因都是因为开发者没有节制地使用导致的。每个开发者都只想着尽可能地去宣传自己的App,最后用户的手机就乱得跟鸡窝一样了。但是通知栏又还是有用处的,比如我们收到微信、短信等消息的时候,确实需要通知栏给我们提醒。因此分析下来,通知栏目前最大的问题就是,无法让用户对感兴趣和不感兴趣的消息进行区分。就比如说,我希望淘宝向我推送卖家发货和物流的相关消息,但是我不想收到那些打折促销或者是让我去买衣服的这类消息。那么就目前来说,是没有办法对这些消息做区分的,我要么同意接受所有消息,要么就屏蔽所有消息,这是当前通知栏的痛点。   那么在Android 8.0系统中,Google也是从这个痛点开始下手的。
饮水思源为名
2018/09/06
3.6K0
iOS 本地通知
如果用户长时间没有使用我们的APP,我们就需要提醒用户来使用。这个本地通知就可以做到。 先说明一下我的解决思路:在AppDelegate里面写 1,当用户退出app时创建一个通知,一定时间后调用,比如10秒。 //进入后台响应的方法 - (void)applicationDidEnterBackground:(UIApplication *)application { // 初始化本地通知对象 UILocalNotification *notification = [[UILocalNo
王大锤
2018/05/17
1.1K0
[PHP] laravel8 发送通知邮件
laravel项目中需要用到发送通知邮件的功能,直接使用smtp模式,利用现在第三方的邮箱,比如新浪、网易或qq发送通知邮件
唯一Chat
2021/08/18
9420
[PHP] laravel8 发送通知邮件
iOS开发--本地通知与远程通知
1、NSNotification是系统内部发出通知,一般用于内部事件的监听,或者状态的改变等等,是不可见的 2、本地通知与远程通知是可见的,主要用于告知用户或者发送一些App的内容更新,推送一些相关的消息,让用户知道App内部发生了什么事情。
孙寅
2020/06/02
3.3K0
推送-iOS本地通知
从 iOS 10 新增的 UserNotifications Framework 可以发现,Apple 整合了原有散乱的 API,并且增加了许多强大的功能。以 Apple 官方的角度来看,也必然是相当重视推送服务对 App 的影响、以及对 Apple iOS 生态圈长远发展的影响。
進无尽
2018/09/12
7.4K1
推送-iOS本地通知
iOS14开发- 通知
远程通知是指在联网的情况下,由远程服务器推送给客户端的通知,又称 APNs(Apple Push Notification Services)。在联网状态下,所有设备都会与 Apple 服务器建立长连接,因此不管应用是打开还是关闭的情况,都能接收到服务器推送的远程通知。
YungFan
2021/11/24
1.7K0
iOS14开发- 通知
客户端开发(Electron)发送通知
  Electron是一个使用 JavaScript、HTML 和 CSS 构建桌面应用程序的框架。 嵌入 Chromium 和 Node.js 到 二进制的 Electron 允许您保持一个 JavaScript 代码代码库并创建 在Windows上运行的跨平台应用 macOS和Linux——不需要本地开发 经验。 ​
前端小鑫同学
2022/12/26
2K0
[GO]使用go-smtp发送邮件通知
直接使用go-smtp包 ,为了防止乱码 , 主题subject进行了base64编码
唯一Chat
2021/02/25
1.6K0
iOS Crash不崩溃
用户在使用App的过程中,经常遇到闪退的情况,体验不太好,本文尝试探索引发闪退的原因,以及在遇到crash的情况下,尽可能的保持程序运行,并及时上报错误。
用户2814378
2022/11/07
2.2K0
iOS Crash不崩溃
ios touchesBegan不触发
今天简单写了一个touchesBegan,发现无法触发,点击无效,网上找了半天没有效果。 最终发现问题是uiimageview需要开启交互:
全栈程序员站长
2022/09/15
6890
ios touchesBegan不触发
iOS 点击通知打开对应页面
这时如果点击通知的显示按钮,会调用didFinishLaunchingWithOptions,不会调用didReceiveRemoteNotification方法。
码客说
2019/10/22
2.7K0
原创投稿 | 如何实现nagios发送通知邮件
前言 上一篇已经介绍了nagios如何实现对主机及服务的监控,尽可能实现对系统运行状态的全面监控只是初级目标,nagios还可以借助smtp服务发送通知信息给指定的联系人。 本文所用到系统环境 OS
小小科
2018/05/04
2.1K0
原创投稿 | 如何实现nagios发送通知邮件
[WCF-Discovery]让服务自动发送上/下线通知[原理篇]
到目前为止,我们所介绍的都是基于客户端驱动的服务发现模式,也就是说客户端主动发出请求以探测和解析可用的目标服务。在介绍WS-Discovery的时候,我们还谈到另外一种服务驱动的模式,即服务在上线和下线的时候主动对外发出Hello/Bye通知。服务上下线通知机制依赖另外一个AnnouncementEndpoint标准终结点。 目录 AnnouncementEnpoint UdpAnnouncementEnpoint 上下线通知的发送 上下线通知的接收
蒋金楠
2018/02/07
9180
点击加载更多

相似问题

iOS中的地理位置通知

30

地理位置和发送推送通知

10

通知fireTime不工作。在ios中立即发送通知

35

地理位置不工作iOS

219

iOS推送通知: iOS日志“不传递非通知推送通知”。

14
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文