当关闭视图开始位置服务通知错误发生时 [英] When close view that started locations service notification error occure

查看:111
本文介绍了当关闭视图开始位置服务通知错误发生时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个使用此项目作为核心的小应用程序:

https:/ /github.com/dsdavids/TTLocationHandler

它在我从app中的另一个视图移动说明位置服务之前一直工作正常。


应用正在执行的操作:启动时,您可以点按开始按钮,并在移动时显示地图移动路线上的<<>在模拟器中的位置。

当我在第二个视图中移动开始操作时出现问题。

在第二个视图中我只想启动位置服务并关闭它。

问题是,当我开始在第二个视图上找到时,我收到错误(应用程序崩溃 EXC_BAD ):

I have created small app that use this project as it's core:
https://github.com/dsdavids/TTLocationHandler
And it worked fine until I have moved stating location services from another view in app.

What app is doing: When it is started you can tap on START button and (in emulator locations must be enabled) on the map route of movement is displayed as you move.
The problem came when I moved starting action in a second view.
In that second view I just want to start location service and close it.
The problem is when I start locating on the second view I get error (application crash EXC_BAD) here:

TTLocationHandler
...
dispatch_async(dispatch_get_main_queue(), ^{
        if (OUTPUT_LOGS) NSLog(@"Sending notification out");
        NSNotification *aNotification = [NSNotification notificationWithName:LocationHandlerDidUpdateLocation object:[locationToSave copy]];
        [[NSNotificationCenter defaultCenter] postNotification:aNotification];
    });
...

我认为这是因为我关闭了第二个视图(查看开始服务)和 TTLocationHandler 仍尝试发送一些东西。

为了更好地理解我的问题,我在git hub添加了项目:

https://github.com/1110/common-location-features


您可以从第二个视图下载它并运行启动服务,当关闭时,该视图应用程序将在几秒钟内崩溃。

I think that it is because I close the second view (view that started service) and TTLocationHandler still tries to send it something.
For better understanding my problem I have added project at git hub:
https://github.com/1110/common-location-features

You can download it and run start service from second view and when close that view app will crash in a few seconds.

如果有人能找到一点时间告诉我我在这里做错了什么,我会非常感激,因为我确信这可能是一件小事,我可能做错了。


整个代码在 SecondViewController.m

I would be really thankful if someone can find a little time to tell me what am I doing wrong here as I am sure that it is some small thing that I probably doing wrong.

Whole code is in SecondViewController.m

谢谢

推荐答案

问题可能是位置管理器正在向不再存在的对象发送位置更新。

The problem is probably that the location manager is sending location updates to an object that no longer exists.

我没有时间挖掘你的所有代码,但一般来说,一旦你告诉位置经理 startUpdatingLocation ,你需要保持你的位置管理员委托对象,直到你告诉它停止。如果您所谓的第二个视图是您的委托对象,那么在您告诉位置管理器 stopUpdatingLocation 之前,您不能让该视图被取消分配。

I don't have the time to dig through all of your code, but generally speaking once you tell the location manager to startUpdatingLocation, you need to keep your location manager delegate object around until you tell it to stop. If what you refer to as the "second view" is your delegate object, then you can't let that view get deallocated until you tell the location manager to stopUpdatingLocation.

通常你希望有一个对象是 CLLocationManagerDelegate ,并且只要你需要它就保持该对象。每当位置发生变化时,代表都会收到通知,代表有责任更新任何关注位置的视图。

Generally you want to have one object be the CLLocationManagerDelegate, and keep that object around for as long as you need it. The delegate will get notified every time the location changes, and it is the delegate's responsibility to update any views that care about the location.

这篇关于当关闭视图开始位置服务通知错误发生时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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