Uygulamamda, uygulamayı değerlendirmek istiyorlarsa her hafta sormak istiyorum. Kullanıcıya haftalık ücret oranı sorma
Bu yüzden geçmiş ya da değil ve geçmişse edildiği ı çekleri eğer değerlendirmesi isterken, bir tarih yapmaya çalıştı ve (NSDate()) artı bir haftaya tarihini değiştirdi:var rateDatum: NSDate {
get {
let defaults = NSUserDefaults.standardUserDefaults()
if let date = defaults.objectForKey("rateDatum") {
return date as! NSDate
}else{
let Datum = NSDate()
Datum.dateByAddingTimeInterval(120)
return Datum
}
}
set (newValue) {
let defaults = NSUserDefaults.standardUserDefaults()
defaults.setObject(newValue, forKey: "rateDatum")
}
}
// the function for checking
func checkRateDatum(){
let components = NSDateComponents()
components.year = 2000
components.month = 1
let calender = NSCalendar.currentCalendar()
let newDatum = calender.dateFromComponents(components)
if rateDatum != newDatum! {
let currentdate = NSDate()
if currentdate.compare(rateDatum) == NSComparisonResult.OrderedDescending {
print("alert")
let alertMotion = UIAlertController(title: "Rate?", message: "Would you mind rating the app?", preferredStyle:UIAlertControllerStyle.Alert)
alertMotion.addAction(UIAlertAction(title: "5 Sterren", style: UIAlertActionStyle.Default){action in
//Rederect to app's url
})
alertMotion.addAction(UIAlertAction(title: "Later", style: UIAlertActionStyle.Cancel){action in
//change RateDatum
self.rateDatum = NSDate()
self.rateDatum.dateByAddingTimeInterval(604800)
})
alertMotion.addAction(UIAlertAction(title: "Never", style: UIAlertActionStyle.Default){action in
//verander datum zo dat hij niet meer wordt gezien
self.rateDatum = newDatum!
})
self.presentViewController(alertMotion, animated: true, completion: nil)
}
}
}
Fakat bu gerçekten işe yaramıyor, tarihin geçip geçmediğini kontrol etmek gerçekten garip.
Her hafta bunu sormasını istiyorum, ancak yalnızca kullanıcı uygulamayı kullanıyorsa.
Böylece tarihin geçmiş olup olmadığını kontrol eder.
Ayrıca kullanıcının Asla'yı seçmesini de istiyorum, bu yüzden pop-up asla tekrar gelmeyecek.
Kodumda neyin yanlış olduğunu bilen var mı?
Ya da oran uygulamaları pop-up'ı ele almak için daha iyi bir yol biliyor?
Ps. Soru açık değilse üzgünüm, ingilizce değilim, bu yüzden bir soru sormak gerçekten zor buluyorum.
Güncelleme: Birisi gerekiyorsa tüm kod.
var userUninterestedInRating: Bool {
get {
let defaults = NSUserDefaults.standardUserDefaults()
return defaults.boolForKey("userUninterestedInRating")
}
set (newvalue) {
let defaults = NSUserDefaults.standardUserDefaults()
defaults.setBool(newvalue, forKey: "userUninterestedInRating")
}
}
var rateDatum: NSDate {
get {
let defaults = NSUserDefaults.standardUserDefaults()
if let date = defaults.objectForKey("rateDatum") {
return date as! NSDate
}else{
let Datum = NSDate(timeIntervalSinceNow: 604800)
defaults.setObject(Datum, forKey: "rateDatum")
return Datum
}
}
set (newValue) {
let defaults = NSUserDefaults.standardUserDefaults()
defaults.setObject(newValue, forKey: "rateDatum")
}
}
func checkRateDatum(){
if !userUninterestedInRating {
let currentdate = NSDate()
if currentdate.compare(rateDatum) == NSComparisonResult.OrderedDescending {
let alertMotion = UIAlertController(title: "Rate?", message: "Would you mind rating the app?", preferredStyle:UIAlertControllerStyle.Alert)
alertMotion.addAction(UIAlertAction(title: "5 Sterren", style: UIAlertActionStyle.Default){action in
//Rederect to app's url
})
alertMotion.addAction(UIAlertAction(title: "Later", style: UIAlertActionStyle.Cancel){action in
//change RateDatum
self.rateDatum = NSDate(timeIntervalSinceNow: 604800)
})
alertMotion.addAction(UIAlertAction(title: "Never", style: UIAlertActionStyle.Default){action in
//verander bool zo dat hij niet meer wordt gezien
self.userUninterestedInRating = true
})
self.presentViewController(alertMotion, animated: true, completion: nil)
}
}
}
'defaults.synchronize()' işlevini kullanmak isteyeceksiniz, aksi takdirde verileriniz kalıcı olmayacaktır. –
Artık bu doğru değil @max_. Senkronizasyon artık gerekli değil. –
@DanielT. Ne zamandan beri? –