[英]Track time spent in application
What should I use to track how long is user using my application on iOS devices?我应该使用什么来跟踪用户在 iOS 设备上使用我的应用程序的时间?
I think I can do it like this:我想我可以这样做:
application:didFinishLaunchingWithOptions:
)application:didFinishLaunchingWithOptions:
)applicationWillTerminate:
)applicationWillTerminate:
)Send report (pairs of start/exit time) to server and count time spent in app将报告(开始/退出时间对)发送到服务器并计算在应用程序中花费的时间
Do you have any better ideas?你有更好的想法吗?
Important is to be network and resources effective重要的是网络和资源有效
(not to send big amount of data or consume iOS resources on complex computing operations.) (不要在复杂的计算操作上发送大量数据或消耗 iOS 资源。)
Notice that applicationWillTerminate:
is not necessarily called when the home button is pressed (this changed from iOS 3.X to iOS 4.0).请注意,当按下主页按钮时,不一定会调用
applicationWillTerminate:
这从 iOS 3.X 更改为 iOS 4.0)。
Take a look at applicationDidEnterBackground:
and applicationWillEnterForeground:
看看
applicationDidEnterBackground:
和applicationWillEnterForeground:
I believe that calculating the time on the device itself would be best, considering you want this to be network and resource effective.考虑到您希望这对网络和资源有效,我相信计算设备本身的时间是最好的。 The calculation of endTime - starTime will be very very fast (depending on your time implementation), and then you would only need to send one piece of data (the time it took) over a network instead of two (the start and end times).
endTime - starTime 的计算将非常非常快(取决于您的时间实现),然后您只需要通过网络发送一个数据(所花费的时间)而不是两个(开始和结束时间) .
Hope this helps.希望这可以帮助。 NS
NS
Seems like a reasonable way to do it.似乎是一种合理的方法。 It's efficient enough, and depending on how you see the data, it shouldn't be more than a kilobyte or two, if that.
它足够高效,并且取决于您如何查看数据,如果那样的话,它不应该超过一两个千字节。 Be wary of privacy issues though—users are really against being logged.
不过要警惕隐私问题——用户确实反对被登录。
Your method is sound, it will have next to no overhead and get the job done nicely.您的方法是合理的,它几乎没有开销并且可以很好地完成工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.