In the app I'm making I need objects to delete themselves after a certain amount of time in Parse. I'm pretty sure I need an NSTimer but I'm not positive. Is there anyone that could help me? Thanks
-
Are you able to give an example of why you want to do this? It will help give context to see if an NSTimer makes sense here.DBoyer– DBoyer2015-07-28 16:40:32 +00:00Commented Jul 28, 2015 at 16:40
-
I am having users create events and I want the data to delete at the time the user says the event is overTrip Phillips– Trip Phillips2015-07-28 16:48:12 +00:00Commented Jul 28, 2015 at 16:48
-
You will need to use Parse Cloud Code for a feature like this. Trying to implement this app-side will be either extremely error-prone or just take way to many network calls. Also you should never truly "delete" data from a database (unless of course your migrating data or something like that), it would be a better practice to use a boolean flag to specify the event as "finished".DBoyer– DBoyer2015-07-28 16:59:02 +00:00Commented Jul 28, 2015 at 16:59
-
Ok thanks. I'm very confused on how to create a background job in Parse thoughTrip Phillips– Trip Phillips2015-07-28 17:01:42 +00:00Commented Jul 28, 2015 at 17:01
-
You might want to think a little harder about the meaning of your words here. Being deleted and not being findable are very similar ideas. Events that are over are still events in the past tense, just no longer current. I'd consider changing event queries to find present, future and not past events. There's also a difference between deleting something at a given time and deleting it after a given time. You can do a lazy sweep of event data to cleanup old stuff, not highly dependent on current time.danh– danh2015-07-28 17:58:51 +00:00Commented Jul 28, 2015 at 17:58
Add a comment
|
1 Answer
You can do it with NSTimer, but depending on your use case, that may not be ideal.
NSTimer will stop running in the background after a specific amount of time. See: How to run NSTimer in background beyond 180sec in iOS 7?
Futhermore, if your app is not running, you will not be able to do this time based deletion in your Parse database.
What is ideal is to have background jobs running in the Parse cloud. See: http://blog.parse.com/announcements/introducing-background-jobs/
and the Parse documentation for further details.