In addition to the use of uilocalnotification to enable the push of local messages (you can set the push content, push time, beep), you can also set the number of reminders in the top right corner of the application.
The following shows how to set the following:
---appdelegate.swift---
| 123456789101112131415161718192021222324252627282930 |
import UIKit@UIApplicationMainclass AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { application.registerUserNotificationSettings(UIUserNotificationSettings( forTypes: UIUserNotificationType.Sound | UIUserNotificationType.Alert | UIUserNotificationType.Badge, categories: nil)) return true } func applicationWillResignActive(application: UIApplication) { } func applicationDidEnterBackground(application: UIApplication) { } func applicationWillEnterForeground(application: UIApplication) { } func applicationDidBecomeActive(application: UIApplication) { } func applicationWillTerminate(application: UIApplication) { }} |
---viewcontroller.swift---
| 123456789101112131415161718192021222324252627 |
import UIKitclass ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() //发送通知消息 scheduleNotification(); } //发送通知消息 func scheduleNotification(){ //清除所有本地推送 UIApplication.sharedApplication().cancelAllLocalNotifications() //创建UILocalNotification来进行本地消息通知 var localNotification = UILocalNotification() //设置应用程序右上角的提醒个数 localNotification.applicationIconBadgeNumber = 78; UIApplication.sharedApplication().scheduleLocalNotification(localNotification) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() }} |
Swift-Sets the number of reminders for the application icon (upper right corner small red circle)