一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Swift - swift在IOS應用圖標上添加提醒個數(shù)的方法

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

2020-12-29 16:31JackWang-CUMT Swift

本文是通過swift語言實現(xiàn)在應用圖標右上角添加消息個數(shù)提醒的功能,非常不錯,具有參考借鑒價值,感興趣的朋友一起看下吧

應用圖標右上角添加消息數(shù)提醒,可以很方便的告知用戶該應用中有無新消息需要處理。下面用xcode 7.3.1來簡要說明一下如何用swift語言進行此功能的實現(xiàn)。

1、修改 AppDelegate.swift

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//
// 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除了可以實現(xiàn)本地消息的推送功能(可以設置推送內容,推送時間,提示音),
//還可以設置應用程序右上角的提醒個數(shù)。
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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//
// 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.
//發(fā)送通知消息
scheduleNotification();
}
//發(fā)送通知消息
func scheduleNotification(){
//清除所有本地推送
UIApplication.sharedApplication().cancelAllLocalNotifications()
//創(chuàng)建UILocalNotification來進行本地消息通知
let localNotification = UILocalNotification()
//設置應用程序右上角的提醒個數(shù)
localNotification.applicationIconBadgeNumber = 8;
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

3 編譯運行

第一次會彈出詢問是否允許推送消息,確認后,第二次運行該app后,會在圖標右上角標注消息數(shù),如下圖所示:

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

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

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

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

原文鏈接:http://www.cnblogs.com/isaboy/archive/2016/08/18/swift_ios_app_UILocalNotification_msg.html

延伸 · 閱讀

精彩推薦
  • SwiftSwift實現(xiàn)多個TableView側滑與切換效果

    Swift實現(xiàn)多個TableView側滑與切換效果

    這篇文章主要為大家詳細介紹了Swift實現(xiàn)多個TableView側滑與切換效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下...

    乞力馬扎羅的雪雪5822021-01-08
  • SwiftSwift中轉義閉包示例詳解

    Swift中轉義閉包示例詳解

    在Swift 中的閉包類似于結構塊,并可以在任何地方調用,下面這篇文章主要給大家介紹了關于Swift中轉義閉包的相關資料,需要的朋友可以參考下...

    小小小_小朋友11412021-12-26
  • SwiftSwift教程之基礎數(shù)據(jù)類型詳解

    Swift教程之基礎數(shù)據(jù)類型詳解

    這篇文章主要介紹了Swift教程之基礎數(shù)據(jù)類型詳解,本文詳細講解了Swift中的基本數(shù)據(jù)類型和基本語法,例如常量和變量、注釋、分號、整數(shù)、數(shù)值類型轉換等...

    Swift教程網(wǎng)5162020-12-18
  • SwiftSwift能代替Objective-C嗎?

    Swift能代替Objective-C嗎?

    這是我在網(wǎng)上上看到的答案,復制粘貼過來和大家分享一下,因為我和很多人一樣很關心Swift的出現(xiàn)對Mac開發(fā)的影響和對Objective-C的影響。...

    Swift教程網(wǎng)4412020-12-16
  • Swiftswift where與匹配模式的實例詳解

    swift where與匹配模式的實例詳解

    這篇文章主要介紹了swift where與匹配模式的實例詳解的相關資料,這里附有簡單的示例代碼,講的比較清楚,需要的朋友可以參考下...

    追到夢的魔術師14382021-01-06
  • Swiftmac git xcrun error active developer path 錯誤

    mac git xcrun error active developer path 錯誤

    本文主要是講訴了如何解決在mac下使用git;xcode4.6的環(huán)境時,出現(xiàn)了錯誤(mac git xcrun error active developer path)的解決辦法,希望對大家有所幫助...

    Swift教程網(wǎng)2232020-12-16
  • SwiftSwift的74個常用內置函數(shù)介紹

    Swift的74個常用內置函數(shù)介紹

    這篇文章主要介紹了Swift的74個常用內置函數(shù)介紹,這篇文章列舉出了所有的Swift庫函數(shù),內置函數(shù)是指無需引入任何模塊即可以直接使用的函數(shù),需要的朋友可...

    Swift教程網(wǎng)5802020-12-19
  • SwiftSwift使用CollectionView實現(xiàn)廣告欄滑動效果

    Swift使用CollectionView實現(xiàn)廣告欄滑動效果

    這篇文章主要為大家詳細介紹了Swift使用CollectionView實現(xiàn)廣告欄滑動效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下...

    Stevin的技術博客12372021-01-13
主站蜘蛛池模板: 精品免费久久久久久影院 | 青草青草伊人精品视频 | 日韩一品在线播放视频一品免费 | 日日摸日日添日日透 | 调教女警花穿环上班 | 日本漫画无翼乌 | 免费国产好深啊好涨好硬视频 | 美女吃男生鸡鸡 | 69日本xxxhd | 2012年免费中文视频 | 国产成年人在线观看 | 国产精品露脸国语对白99 | 色综合综合 | 亚洲大尺码 | 免费高清观看 | 国产亚洲欧美一区二区三区 | 99久久久久国产精品免费 | 美女被躁了在线观看视频 | 精品无人区麻豆乱码无限制 | 亚洲免费视频一区 | 男人亚洲天堂 | 亚洲香蕉网久久综合影院3p | 亚洲波霸 | 日韩欧美国产一区二区三区 | 亚洲娇小videos | 天天综合亚洲 | v视界影院成片 | 国产午夜一区二区在线观看 | 国产精品久久久久毛片真精品 | 桥本有菜作品在线 | 国产精品久久久久久久午夜片 | 日本在线视频网址 | 国产一区二区在线免费观看 | 纲手被强喷水羞羞漫画 | 久久国产综合精品欧美 | 性欧美xxxxx老太婆 | 波多野结衣在线看 | 99热久久这里只精品国产www | 国色天香社区视频在线观看免费完整版 | 国语在线 | 99精品免费在线 |