国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Swift > 正文

swift在IOS應用圖標上添加提醒個數的方法

2020-03-09 17:47:28
字體:
來源:轉載
供稿:網友

在應用圖標右上角添加消息數提醒,可以很方便的告知用戶該應用中有無新消息需要處理。下面用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@UIApplicationMainclass 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 UIKitclass 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后,會在圖標右上角標注消息數,如下圖所示:

swift,應用圖標,ios圖標提醒個數

修改APP的顯示名稱,可以單擊info.plist,然后修改器Bundle name,如下圖所示:

swift,應用圖標,ios圖標提醒個數

以上所述是小編給大家介紹的swift在IOS應用圖標上添加提醒個數的方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對VEVB武林網網站的支持!

 

注:相關教程知識閱讀請移步到swift教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 衢州市| 册亨县| 绥棱县| 青田县| 虞城县| 肥东县| 获嘉县| 安溪县| 浦北县| 广安市| 富顺县| 昆明市| 阿坝县| 丰顺县| 津市市| 泰州市| 乌拉特中旗| 深水埗区| 邯郸县| 阳西县| 奎屯市| 桑植县| 都江堰市| 和顺县| 蕲春县| 天等县| 阳谷县| 昭平县| 巫山县| 会东县| 淅川县| 福安市| 乌审旗| 泽普县| 望谟县| 称多县| 宁远县| 雅江县| 马龙县| 天门市| 饶阳县|