简体   繁体   English

iOS-健身应用中的推送通知和距离跟踪

[英]iOS - Push notification and distance tracking in fitness app

First of all, I'm a very beginner at iOS and I'm working on my first iOS app ever for my thesis. 首先,我是iOS的初学者,我正在为自己的论文开发第一个iOS应用程序。 (I'm using Parse.com for my database) I'm developing a fitness app(iOS) that tracks user's walked/run distance everyday. (我在数据库中使用Parse.com)正在开发一个健身应用(iOS),该应用每天跟踪用户的步行/跑步距离。 My app can already run in background to keep tracking the distance even when users are not playing on the app. 我的应用程序可以已经在后台运行,即使用户没有在应用程序上玩,它也可以跟踪距离。 Anyway, these are a few problems I have... 无论如何,这些是我遇到的一些问题...

  1. I want my app to send push notification to users when they've reached their distance goal in everyday, how do i do it? 我希望我的应用在用户每天达到其距离目标时向他们发送推送通知,我该怎么做? I guess this is possible according to some apps/games I have used, for example Candy Crush that sends me notification when my hearts is full again, or Ground Miles that alarms me when I've reached every 1,000 steps. 我想根据我使用的某些应用程序/游戏,这是有可能的,例如当我的心再次充满时,Candy Crush会向我发送通知,或者当我每迈过1000步时便会警告我。 Or I'm just getting this wrong? 还是我只是搞错了? If yes, any suggestion? 如果是,有什么建议吗?

  2. I want to send the distance walked data in that day to database and reset the distance walked value shown in app back to 0km every midnight, so that I can show users how far they've completed each day. 我想将当天的步行距离数据发送到数据库,并在每个午夜将应用程序中显示的步行距离值重置为0km,以便向用户显示他们每天完成的距离。 How do I reset the distance value shown? 如何重设显示的距离值? and how do I send the data to my database at specific time or in a way that suits my function mentioned above? 以及如何在特定时间或以适合上述功能的方式将数据发送到数据库? Right now I'm saving it to my database using saveEventually function in my applicationDidEnterBackground method, which I don't think is a right way to do it. 现在,我正在使用applicationDidEnterBackground方法中的saveEventually函数将其保存到数据库中,我认为这不是正确的方法。


Please give me some suggestion for this :) I've already been looking on many pages and sites but don't seem to get the answer I want. 请给我一些建议:)我已经在很多页面和站点上查找了,但是似乎没有得到我想要的答案。 I'd appreciate every comments and thank you so much in advance! 非常感谢您的每条评论,并在此先感谢您!

Aimme :) 目的:)

  1. Parse has Push Notifications, look into their documentation for that. Parse具有“推送通知”,请查看其文档。 You will also need to set up some script (parse also has this) when a user updates their location. 用户更新位置时,您还需要设置一些脚本(分析也有此脚本)。 (ie check if they reached their goal then send push if true) (即检查他们是否达到了目标,如果正确则发送推送)

  2. Add a date attribute/column when you update the parse database for location or distance walked. 当您更新解析数据库的位置或步行距离时,请添加日期属性/列。 On your app, when you grab data only grab data for that date (or whatever days you need) with a filter, or just filter it app side yourself. 在您的应用上,当您抓取数据时,仅使用过滤器抓取该日期(或您需要的任何天数)的数据,或者自己过滤应用端。

1) When you detect a limit has been reached use UIApplication:presentLocalNotificationNow (if your app is in the background, if its in the foreground just present an alert view, its daft to post a notification if your app is in the foreground at that time) 1)当您检测到已达到限制时,请使用UIApplication:presentLocalNotificationNow(如果您的应用程序在后台,如果它的前台只是显示一个警报视图,那么当您的应用程序在前台时,它会愚蠢地发布通知)

2) You can't schedule your app to run at midnight, nor schedule your app to save data at a particular time. 2)您无法安排您的应用在午夜运行,也无法安排您的应用在特定时间保存数据。 The only chances you will have to reset the distance and save data is if the user runs the app or if you get a location update from the OS. 您唯一必须重置距离并保存数据的机会是用户运行应用程序还是从操作系统获取位置更新。 Everytime the app runs you'll have to see what the current date/time is and save it, then next time you run, if its the first time the app is running that day then you know you have to reset the count to 0. You should be saving your data to the database every time the location has changed (make sure to filter out insignification location changes) 每次运行该应用程序时,您都必须查看当前日期/时间并将其保存,然后在下次运行时(如果该应用程序在该天首次运行),则必须将计数重置为0。每次位置更改时,您都应该将数据保存到数据库中(确保过滤掉指定位置的更改)

I'd use cloud code for that one. 我会为此使用云代码。 If you're storing the data at some point, you could implement an aftersave function that calculates whether or not the user achieved their goal. 如果要在某个时刻存储数据,则可以实现一个aftersave函数,该函数可以计算用户是否达到了目标。 Then, if they have you can send a push notification directly from parse's servers. 然后,如果有,您可以直接从parse的服务器发送推送通知。

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

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