swift在IOS使用圖標上添加提示個數的辦法。本站提示廣大學習愛好者:(swift在IOS使用圖標上添加提示個數的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是swift在IOS使用圖標上添加提示個數的辦法正文
在使用圖標右上角添加音訊數提示,可以很方便的告知用戶該使用中有無新音訊需求處置。上面用xcode 7.3.1來扼要闡明一下如何用swift言語停止此功用的完成。
1、修正 AppDelegate.swift
// // AppDelegate.swift // RainbowDemo // // Created by Jackwang on 16/8/17. // Copyright © 2016年 Jackwang . All rights reserved. // import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for customization after application launch. //運用UILocalNotification除了可以完成本地音訊的推送功用(可以設置推送內容,推送時間,提示音), //還可以設置使用順序右上角的提示個數。 let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil) application.registerUserNotificationSettings(settings) return true } func applicationWillResignActive(application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } func applicationDidEnterBackground(application: UIApplication) { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } func applicationWillEnterForeground(application: UIApplication) { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. } func applicationDidBecomeActive(application: UIApplication) { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } func applicationWillTerminate(application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } }
2 修正在ViewController.swift
// // ViewController.swift // RainbowDemo // // Created by jackwang on 16/8/17. // Copyright © 2016年 jackwang. All rights reserved. // import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. //發送告訴音訊 scheduleNotification(); } //發送告訴音訊 func scheduleNotification(){ //肅清一切本地推送 UIApplication.sharedApplication().cancelAllLocalNotifications() //創立UILocalNotification來停止本地音訊告訴 let localNotification = UILocalNotification() //設置使用順序右上角的提示個數 localNotification.applicationIconBadgeNumber = 8; UIApplication.sharedApplication().scheduleLocalNotification(localNotification) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }
3 編譯運轉
第一次會彈出訊問能否允許推送音訊,確認後,第二次運轉該app後,會在圖標右上角標注音訊數,如下圖所示:
修正APP的顯示稱號,可以單擊info.plist,然後修正器Bundle name,如下圖所示:
以上所述是給大家引見的swift在IOS使用圖標上添加提示個數的辦法,希望對大家有所協助,假如大家有任何疑問請給我留言,會及時回復大家的。在此也十分感激大家對網站的支持!