iOS 中的重复本地通知 [英] Recurring Local Notification in iOS
本文介绍了iOS 中的重复本地通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是想确保我了解本地通知的工作原理.是不是一旦我运行以下代码一次,我就会每周收到通知?
I just want to ensure I understand how local notifications work. Is it true that once I run the below code one time, I'll have weekly notifications?
//Goes in AppDelegate.swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
//Added this for notifications.
//Without this, I don't believe the user gets the opportunity to approve notifications from the app
let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge], categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
return true
}
//Goes in viewController
func weeklyNotifications () {
let localNotification = UILocalNotification()
localNotification.fireDate = NSDate(timeIntervalSinceNow: 60*60)
localNotification.alertBody = "This is the message"
localNotification.timeZone = NSTimeZone.localTimeZone()
localNotification.repeatInterval = NSCalendarUnit.WeekOfYear
localNotification.soundName = UILocalNotificationDefaultSoundName
localNotification.category = "Message" //Optional
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
}
换句话说,这段代码的结果是,我第一次运行应用程序时,我可以执行这段代码,并且通知将每周重复一次,而无需我运行其他代码?
In other words, the result of this code is that the first time I run the app, I can execute this code and the notification will repeat every week without me running additional code?
推荐答案
localNotification.repeatInterval = NSCalendarUnit.WeekOfYear
是的,这将安排每周的本地通知.
Yes this will schedule local notification for every week.
这篇关于iOS 中的重复本地通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文