2016-04-09 4 views
0

ローカル通知に問題があります。スタックオーバーで多くの回答が見られましたが、必要なものが見つかりませんでした。スウィフト複数のローカル通知最初のemelentのみを呼び出す

私は、データの各要素

スウィフトコード

コントローラコードのためのローカル通知作成する

ModulesRegistered =   (
         { 
       ModuleCode = "COMP 0304.1"; 
       ModuleName = "Object Oriented Paradigm"; 
       Session = "Session-C "; 
       Timetable =     (
             { 
         Day = Sunday; 
         EndTime = "18.00"; 
         FacultyName = "Renjini Jose"; 
         RoomNo = "IBR 112"; 
         StartTime = "16.00"; 
        } 
       ); 
      }, 
         { 
       ModuleCode = "COMP 0311"; 
       ModuleName = "Operating Systems"; 
       Session = "Session-D "; 
       Timetable =     (
             { 
         Day = Wednesday; 
         EndTime = "20.00"; 
         FacultyName = "Sheela Paudyal"; 
         RoomNo = "IBK 102"; 
         StartTime = "17.00"; 
        } 
       ); 
      }, 
         { 
       ModuleCode = "COMP 10013"; 
       ModuleName = "User Interface Design"; 
       Session = "Session-B "; 
       Timetable =     (
             { 
         Day = Thursday; 
         EndTime = "18.00"; 
         FacultyName = "Mohammed Kaleem"; 
         RoomNo = "AKZ 205"; 
         StartTime = "16.00"; 
        }, 
             { 
         Day = Wednesday; 
         EndTime = "17.00"; 
         FacultyName = "Mohammed Kaleem"; 
         RoomNo = "IBK 009"; 
         StartTime = "15.00"; 
        } 
       ); 
      }, 
         { 
       ModuleCode = "PROJ 0001"; 
       ModuleName = "PROJECT I"; 
       Session = "Session-U "; 
       Timetable =     (
             { 
         Day = Tuesday; 
         EndTime = "20.00"; 
         FacultyName = "Kamal Uddin Sarker"; 
         RoomNo = "AKZ 121"; 
         StartTime = "18.00"; 
        } 
       ); 
      } 
     ); 

このJSONデータを持っている:

override func viewDidLoad() { 
     super.viewDidLoad() 

     let noti = Notification() 
     noti.deleteAll() 

     // Add notification 

     if let GetData = DataService.DataServiceInstance.LoadData[0]["ModulesRegistered"] as? NSArray{ 


      for ModulesRegistered in GetData { 



       if let TimeTable = ModulesRegistered["Timetable"] as? NSArray{ 

         for TimeTableData in TimeTable { 


          if let TimeTableDic = TimeTableData as? Dictionary<String,String> { 

           if let moduleName = ModulesRegistered["ModuleName"] as? String{ 
            noti.createNotification(TimeTableDic["StartTime"]!, day: TimeTableDic["Day"]!, msgBody: "Your \(moduleName) will begin after one hour from now , your classroom address is \(TimeTableDic["RoomNo"]!)") 

           } 




          } 

        } 


       } 

      } 

     } 

通知クラスは、通知機能を作成notification.swift

func createNotification(hour:String, day:String, msgBody:String)->Bool 
{ 

    print(day) 
    let TheTime:String = ("\(day) \(hour) UTC+04:00") 
    let fireDate = TheTime.stringByReplacingOccurrencesOfString(".", withString: ":", options: NSStringCompareOptions.LiteralSearch, range: nil) 


    let dateFormatter = NSDateFormatter() 
    //var dateAsString = "Thursday 20:27 UTC+04:00" 
    dateFormatter.dateFormat = "EEEE HH:mm ZZZZZ" 

    dateFormatter.locale = NSLocale(localeIdentifier: "en_OM") 
    let newDate = dateFormatter.dateFromString(fireDate) 
    print(newDate) 




     let notificationClass:UILocalNotification = UILocalNotification() 
     notificationClass.alertBody = msgBody 
     notificationClass.fireDate = newDate 
     notificationClass.soundName = UILocalNotificationDefaultSoundName 
      notificationClass.repeatCalendar = NSCalendar.currentCalendar() 
     notificationClass.repeatInterval = NSCalendarUnit.Day 
     notificationClass.timeZone = NSTimeZone(name: "UTC") 
     notificationClass.applicationIconBadgeNumber = UIApplication.sharedApplication().applicationIconBadgeNumber + 1 
     UIApplication.sharedApplication().scheduleLocalNotification(notificationClass) 



      return true 
} 

コードが機能していますが、すべての通知は毎日発射と私はそれぞれが自分の日に発射する必要がありますしたい、ということたくありません。

おかげ

答えて

0

あなたの問題は、この行によって引き起こされる:

notificationClass.repeatInterval = NSCalendarUnit.Day 

UILocalnotificationの繰り返し間隔を設定します。デフォルト値は0です。これは、システムが通知を再スケジュールしないことを意味します。

https://developer.apple.com/library/ios/documentation/iPhone/Reference/UILocalNotification_Class/#//apple_ref/occ/instp/UILocalNotification/repeatInterval

その行を削除し、あなたは罰金になります。

+0

こんにちは、私は毎週日曜日のクラスを持っている場合、魔法使いは毎週通知を繰り返したいと思います。これを取り除くと毎週日曜日に通知しなければなりません。 –

+0

NSCalendarUnit.WeekOfYearをUILocalnotification –

+0

の反復間隔として設定すると、これは毎週日曜日を意味しますか?または週ごとの特定の日? –

関連する問題