2016-06-25 2 views
0

私はToDoリストアプリを持っています。 このtodolistの中にはアイテムがあり、各アイテムには期限と頻度があります。 例:Itemオブジェクト迅速nsTimerコアデータ項目を更新する

  • 名:空港でのピックアップサラ
  • DueDate:06/26/16(6月の26)
  • 頻度:毎週

自動的に再スケジュールする方法アイテム?アプリは生きている、またはなどを背景に...私たちの例では は: は26/06/16の後、この項目は自動的07/03/16(7月の03)に再スケジュールされます

iはNStimer FUNCを使用すべきアイテムを再スケジュールする必要があるかどうかを確認する関数を呼び出す:

私はこのNSTimer(アプリデリゲートで、どのように?) バックグラウンドモードを初期化する/作成する必要があります

?私の側の質問の

ロット?誰もこの種の使用法の例を持っていますか?

それはのUIViewControllerでNSTimerだけではありません。

おかげ

答えて

0

あなたがnsnotification local scheduledのためにウェブを検索した場合、起動したサイトの一つは、彼はあなたが記述するものの多くを行う方法を示しますここで、thisあります。特に、彼のチュートリアルでは、このコードが含まれています

private let ITEMS_KEY = "todoItems" 

func addItem(item: TodoItem) { // persist a representation of this todo item in NSUserDefaults 
    var todoDictionary = NSUserDefaults.standardUserDefaults().dictionaryForKey(ITEMS_KEY) ?? Dictionary() // if todoItems hasn't been set in user defaults, initialize todoDictionary to an empty dictionary using nil-coalescing operator (??) 

    todoDictionary[item.UUID] = ["deadline": item.deadline, "title": item.title, "UUID": item.UUID] // store NSData representation of todo item in dictionary with UUID as key 
    NSUserDefaults.standardUserDefaults().setObject(todoDictionary, forKey: ITEMS_KEY) // save/overwrite todo item list 

    // create a corresponding local notification 
    var notification = UILocalNotification() 
    notification.alertBody = "Todo Item \"\(item.title)\" Is Overdue" // text that will be displayed in the notification 
    notification.alertAction = "open" // text that is displayed after "slide to..." on the lock screen - defaults to "slide to view" 
    notification.fireDate = item.deadline // todo item due date (when notification will be fired) 
    notification.soundName = UILocalNotificationDefaultSoundName // play default sound 
    notification.userInfo = ["UUID": item.UUID, ] // assign a unique identifier to the notification so that we can retrieve it later 
    notification.category = "TODO_CATEGORY" 
    UIApplication.sharedApplication().scheduleLocalNotification(notification) 

あなたが探しているキーコンセプトはUILocalNotificationを使用し、その上fireDateを設定することです。

+0

おかげFeldur非常に便利なチュートリアル – h3630fr