基本上我正在运行一个像应用程序一样的火种,每次刷卡时都会给你一个新人。
在某些时候,我的查询不会再回馈用户,因为所有用户都已被拒绝或接受。当我的查询不再返回用户时,有关如何设置警报的任何想法?
query?.whereKey("objectId", notContainedIn: ignoredUsers)
// Immer nur ein Resultat pro Zeit.
query?.limit = 1
query?.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in
if error != nil {
//Alert raushauen für einen Error:
let userMessage = error!.localizedDescription
let myAlert = UIAlertController(title: "Alert", message: userMessage, preferredStyle: UIAlertControllerStyle.Alert)
let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil)
myAlert.addAction(okAction)
self.presentViewController(myAlert, animated: true, completion: nil)
return
// Muss nicht mehr auf PFObject gecastet werden (von AnyObject?)
} else if let objects = objects {
for object in objects {
displayedUserId = object.objectId!
// Name, Alter und Hashtags müssen gedownloaded werden.
// first_name sollte es ja immer geben.
var profilText = object["first_name"] as! String
self.ContainerVC.nameAgeLabel.text = profilText
if let geburtstag = object["birthday"] as? String {
profilText += ", " + geburtstag
self.ContainerVC.nameAgeLabel.text = profilText
}
if let hashtags = object["hashtags"] as? String {
self.ContainerVC.hashtagTextField.text = hashtags
}
let imageFile = object["firstImage"] as! PFFile
// Image muss ja erstmal gedownloaded werden.
imageFile.getDataInBackgroundWithBlock {
(imageData: NSData?, error: NSError?) -> Void in
if error != nil {
let userMessage = error!.localizedDescription
let myAlert = UIAlertController(title: "Alert", message: userMessage, preferredStyle: UIAlertControllerStyle.Alert)
let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil)
myAlert.addAction(okAction)
self.presentViewController(myAlert, animated: true, completion: nil)
return
} else {
if let data = imageData {
self.ContainerVC.profilePicture.image = UIImage(data: data)
self.ContainerVC.miniImage.image = UIImage(data: data)
}
}
}
}
}
})
}
}
答案 0 :(得分:1)
以下可能有效。
...} else if let objects = objects {
if objects.length() == 0 {
let myAlert = UIAlertController(title: "Alert", message: "No Users", preferredStyle: UIAlertControllerStyle.Alert)
let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil)
myAlert.addAction(okAction)
self.presentViewController(myAlert, animated: true, completion: nil)
} else {
for object in objects {
displayedUserId = object.objectId!
// Name, Alter und Hashtags müssen gedownloaded werden.
// first_name sollte es ja immer geben.
var profilText = object["first_name"] as! String
self.ContainerVC.nameAgeLabel.text = profilText
if let geburtstag = object["birthday"] as? String {
profilText += ", " + geburtstag
self.ContainerVC.nameAgeLabel.text = profilText
}
if let hashtags = object["hashtags"] as? String {
self.ContainerVC.hashtagTextField.text = hashtags
}
let imageFile = object["firstImage"] as! PFFile
// Image muss ja erstmal gedownloaded werden.
imageFile.getDataInBackgroundWithBlock {
(imageData: NSData?, error: NSError?) -> Void in
if error != nil {
let userMessage = error!.localizedDescription
let myAlert = UIAlertController(title: "Alert", message: userMessage, preferredStyle: UIAlertControllerStyle.Alert)
let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil)
myAlert.addAction(okAction)
self.presentViewController(myAlert, animated: true, completion: nil)
return
} else {
if let data = imageData {
self.ContainerVC.profilePicture.image = UIImage(data: data)
self.ContainerVC.miniImage.image = UIImage(data: data)
}
}
}
}
}
}
只是免责声明......您在每次刷卡时查询一个用户的方法并不是最有效的。您可以获得一组用户,然后将其用作每次滑动的缓冲区。