UILocalNotificationのローカル通知で毎週、毎月、毎年と繰返し設定ができるようになったのですが、掲題の通り隔週、3ヶ月毎、半年毎に通知をする方法を色々とググッて探してみたのですが、辿りつけずこちらに質問させていただきました。
ソースはざっくりですが、下記の通りです。
Swift
1 // ViewController.swift 2 let notification = UILocalNotification() 3 notification.alertAction = "開く" 4 notification.alertBody = "通知テスト" 5 notification.timeZone = NSTimeZone.defaultTimeZone() 6 7 let repeatNum = 3 8 9 switch repeatNum { 10 case 1: 11 // 毎週 12 notification.repeatInterval = NSCalendarUnit.WeekOfYear 13 case 2: 14 // 隔週 15 case 3: 16 // 毎月 17 notification.repeatInterval = NSCalendarUnit.Month 18 case 4: 19 // 3ヶ月毎 20 case 5: 21 // 半年 22 case 6: 23 // 毎年 24 notification.repeatInterval = NSCalendarUnit.Year 25 default: 26 break 27 } 28 29 notification.fireDate = NSDate(timeIntervalSinceNow:30) 30 UIApplication.sharedApplication().scheduleLocalNotification(notification)
ちなみに確認自体は、端末の時計機能を変更しつつ、下記のプリント文で出力された next fire dateを確認しながら行いました。
Swift
1print("通知データ = ",UIApplication.sharedApplication().scheduledLocalNotifications)
環境
Xcode 7.3
Swift 2.2
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/04/08 22:48
2016/04/09 02:38
2016/04/09 03:47
2016/04/09 04:02
2016/04/09 04:25 編集