0

この配列は、ダイナミックセルのテーブルビューに既に配置されています。ローカルアジェンダまたは通知またはアラームなどを作成したいユーザーに思い出させるものですアレイに表示されている日と時間に薬を服用すると助けてくれますか?お願いします。どうもありがとう。ローカルアジェンダまたはローカル通知を時間と日に表示する方法

{“medicine”:”paracetamol” 

     “day”:”tuesday” 

     “time”:”9:00”}, 

     {“medicine”:”aspirine” 

     “day”:”friday” 

     “time”:”16:00”}, 

     {“medicine”:”pills” 

     “day”:”monday” 

     “time”:”22:00”} 

答えて

0

あなたはカレンダーオブジェクトを作成し、comps.weekday、comps.hourとcomps.minuteプロパティであなたの曜日と時刻の値を設定する必要があります。

あなたのメッセージについては、notification content.bodyプロパティで設定します。

import UserNotifications 

let calendar = NSCalendar.init(calendarIdentifier: .gregorian) 
calendar?.locale = NSLocale.current 

let year = calendar?.component(.year, from: date) 
let month = calendar?.component(.month, from: date) 

let cal = Calendar.current 
var comps = cal.dateComponents([.weekOfYear, .yearForWeekOfYear], from: date) 
comps.weekday = i // Monday - Friday 
comps.hour = j 
comps.minute = minute 
comps.year = year 
comps.month = month 

let notificationDate = cal.date(from: comps)! 
let interval = String.init(format: "%d%d%d", i,j,minute) 


if #available(iOS 10.0, *) { 

    let triggerDate = Calendar.current.dateComponents([.weekday,.hour,.minute], from: notificationDate as Date) 

    let trigger = UNCalendarNotificationTrigger(dateMatching: triggerDate, 
repeats: true) 

    let content = UNMutableNotificationContent() 
    content.title = DataManager.sharedInstance.notificationTitle 
    content.body = String.init(format: "%@", DataManager.sharedInstance.notificationMessage) 
    content.sound = UNNotificationSound.default() 

    let request = UNNotificationRequest(identifier: String(interval), content: content, trigger: trigger) 
    UNUserNotificationCenter.current().add(request) {(error) in 
     if let error = error { 
      print(error) 
     } 
    } 

} else { 
    // ios 9 


    // Fallback on earlier versions 
    let notification = UILocalNotification() 

    /* Time and timezone settings */ 
    notification.fireDate = date 
    notification.repeatInterval = NSCalendar.Unit.weekday 
    notification.timeZone = NSCalendar.current.timeZone 
    notification.alertBody = "message" 

    notification.userInfo = [ "title" : String(interval)] 

    /* Schedule the notification */ 
    UIApplication.shared.scheduleLocalNotification(notification) 
} 

UPDATED ANSWER

  1. あなたのJSONはNSDictionaryのオブジェクトのNSArrayのに変換します。 NSJSonSerialisationクラスを使用します。
  2. forループをNSArrayインスタンスで実行し、NSDictionaryオブジェクトに1つずつアクセスします。
  3. NSDictionaryのvalueForKeyメソッドを使用します。キー名を渡し、辞書から値を取得します。
+0

私はこれを試してみませんか?キー "time"と "hour"にアクセスし、comps.hourとcomps.weekdayにそれを当てる方法を知らない:( – user8172235

+0

@ user8172235 updated jsonからのデータにアクセスするためのステップの私の答え。歓声:) – Basheer

関連する問題