简体   繁体   English

iOS核心位置(在哪里放置代码?)

[英]iOS Core Location (Where to put code?)

Where should I put the the location methods in a Tabbar app? 我应该在Tabbar应用中的位置方法放在哪里?

In the appdelegate or in a tab? 在appdelegate或标签中?

[edit] [编辑]

details of scenario: 方案的详细信息:

I need to track user position every 500 meters he move, even when the app is in the background 我需要跟踪用户移动的每500米位置,即使该应用在后台运行

Put it there, where it is most useful for you. 将其放在对您最有用的位置。 Eg, if it is need by some specific View Controller, put Core Location stuff there. 例如,如果某些特定的View Controller需要它,则将Core Location内容放在那里。 If it is need globally, you may create a singleton for it, and put code there. 如果全局需要它,则可以为其创建一个单例,然后在其中放置代码。

I personally think, AppDelegate is bad to place Core Location code directly there. 我个人认为,AppDelegate将核心位置代码直接放在此处很不好。

That all depends. 一切取决于。 If you want it every time your app is opened you should put it in your app delegate -applicationDidFinishLoading: 如果每次打开应用程序都需要它,则应将其放入应用程序委托-applicationDidFinishLoading:

If you only want it if the user does a certain action or when the user loads a certain view then you should put it within that function or viewDidLoad of that viewController. 如果仅在用户执行某个操作或加载某个视图时才需要它,则应将其放在该函数或该viewController的viewDidLoad中。

If you need this data in more than one place (object, view controller, etc.) then put it in a (MVC paradigm) shared Model object that records the location information. 如果您需要在多个位置(对象,视图控制器等)中使用此数据,则将其放在记录位置信息的(MVC范例)共享Model对象中。

For the simplest a-couple-pages-long apps, many people use the App Delegate as The Model Object. 对于最简单的a-couple-pages长的应用程序,许多人将App Delegate用作模型对象。 This may work OK for small projects, but does not scale well for projects that become significantly larger. 对于小型项目,这可能行得通,但对于变得很大的项目,则无法很好地扩展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM