1

Users can post a pin on a map at a location, but currently once they post the pin it is set on the map forever as a user post. I would like to set a time expiration on these posts, so after 24 hours the post is wiped and gone. I'm not sure if this is a Parse thing or if its just part of Xcode?

here is where I add pins:

var annotationQuery = PFQuery(className: "Post")
    currentLoc = PFGeoPoint(location: MapViewLocationManager.location)
    //annotationQuery.whereKey("Location", nearGeoPoint: currentLoc, withinMiles: 10)
    annotationQuery.whereKeyExists("Location")
    annotationQuery.findObjectsInBackgroundWithBlock {
        (points, error) -> Void in
        if error == nil {
            // The find succeeded.
            println("Successful query for annotations")
            // Do something with the found objects

            let myPosts = points as! [PFObject]

            for post in myPosts {
                let point = post["Location"] as! PFGeoPoint
                let annotation = MKPointAnnotation()
                annotation.coordinate = CLLocationCoordinate2DMake(point.latitude, point.longitude)
                annotation.title = post["title"] as! String!
                let annotationSubTitleUser = post["username"] as! String!

                let formatter = NSDateFormatter()
                formatter.dateStyle = NSDateFormatterStyle.ShortStyle
                formatter.timeStyle = .ShortStyle
                let dateString = formatter.stringFromDate(post.createdAt!)

                annotation.subtitle = "User: \(annotationSubTitleUser)  Time: \(dateString)"

                self.mapView.addAnnotation(annotation)
            }

        } else {
            // Log details of the failure
            println("Error: \(error)")
        }
    }

Thank you for the help in advance!

Zach
  • 180
  • 1
  • 2
  • 12
  • If is a parse thing. Add an expiry day as a database entry at parse and every time you make a pin, add expiry date as `current time + 24 hours`. And then query items where "current time < pin.expiry date`. Also I haven't used parse but in a genetic server I would set up a CRON job every 24 hours, that clears all the expired pins from the database. – Gasim Apr 25 '15 at 08:45
  • For CRON jobs, read [this](http://blog.parse.com/announcements/introducing-background-jobs/) – Gasim Apr 25 '15 at 08:47
  • Im having trouble adding an expiration date and setting it to +24hrs. If I can set the exiration date to a `var` then I can set the view to load the pins `if` date is `>` `expirationDate` – Zach Apr 26 '15 at 09:22
  • The code that you provided is for selecting pins, you need to add the expiration to the database first. For simplicity, I would say add expiration_date as int the database and use epoch time (seconds since 1970; check [this](http://stackoverflow.com/questions/9321055/convert-a-nsdate-to-milliseconds-epoch-time)). And then just add `currentEpochSeconds + 24*60*60` – Gasim Apr 27 '15 at 10:26
  • I'm slightly confused as to how to implement this method. Do you have some sample code so I can understand better? – Zach May 09 '15 at 19:14

0 Answers0