0

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

Trip Phillips
  • 430
  • 1
  • 5
  • 18
  • 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 Jul 28 '15 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 over – Trip Phillips Jul 28 '15 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 Jul 28 '15 at 16:59
  • Ok thanks. I'm very confused on how to create a background job in Parse though – Trip Phillips Jul 28 '15 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 Jul 28 '15 at 17:58

1 Answers1

1

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.

Community
  • 1
  • 1
Kelvin Lau
  • 6,373
  • 6
  • 34
  • 57