程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 更多關於編程 >> swift在IOS運用圖標上添加提示個數的辦法

swift在IOS運用圖標上添加提示個數的辦法

編輯:更多關於編程

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運用圖標上添加提示個數的辦法,願望對年夜家有所贊助,假如年夜家有任何疑問請給我留言,小編會實時答復年夜家的。在此也異常感激年夜家對網站的支撐!

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved