• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >swift > swift在IOS应用图标上添加提醒个数的方法

swift在IOS应用图标上添加提醒个数的方法

作者:JackWang-CUMT 字体:[增加 减小] 来源:互联网 时间:2017-05-28

JackWang-CUMT 通过本文主要向大家介绍了ios swift,ios swift教程,swift ios开发教程,ios开发swift,ios10 swift等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

在应用图标右上角添加消息数提醒,可以很方便的告知用户该应用中有无新消息需要处理。下面用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:.
}
}
</div>

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.
}
}
</div>

3 编译运行

第一次会弹出询问是否允许推送消息,确认后,第二次运行该app后,会在图标右上角标注消息数,如下图所示:

修改APP的显示名称,可以单击info.plist,然后修改器Bundle name,如下图所示:

以上所述是小编给大家介绍的swift在IOS应用图标上添加提醒个数的方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!

</div>
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • Swift 教程
  • iOS开发中Swift 指纹验证功能模块实例代码
  • 使用Swift实现iOScollectionView广告无限滚动效果(DEMO)
  • swift在IOS应用图标上添加提醒个数的方法
  • Swift自定义iOS中的TabBarController并为其添加动画
  • Swift操作Quartz 2D进行简单的绘图与坐标变换的教程
  • 使用Swift实现iOS App中解析XML格式数据的教程
  • 用Swift构建一个简单的iOS邮件应用的方法
  • Swift教程之类的析构详解
  • Swift教程之继承详解

相关文章

  • 2017-05-28程序迁移到swift 3.0的一些实用技巧
  • 2017-05-28Swift心得笔记之函数
  • 2017-05-28Swift中swift中的switch 语句
  • 2017-05-28零基础上手Swift快速入门教程概览
  • 2017-05-28Swift语言中的一些访问控制设置详解
  • 2017-05-28深入讲解C语言编程中volatile修饰符的作用
  • 2017-05-28通过一个map替换字符串中指定的字符变量方法
  • 2017-05-28Swift心得笔记之控制流
  • 2017-05-28Swift与C语言指针结合使用实例
  • 2017-05-22Swift 基本语法

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • Swift心得笔记之运算符
    • 初步理解Swift中的泛型
    • 如何设计一个秒杀系统
    • Swift算法之二叉树实现的方法示例
    • 浅谈在Swift中关于函数指针的实现
    • Swift开发之使用UIRefreshControl实现下拉刷新数据及uirefreshcontrol使用
    • 用Swift构建一个简单的iOS邮件应用的方法
    • Swift使用Cocoa中的数据类型教程
    • 深入解析Swift语言中的协议
    • Swift hello world!Swift快速入门教程

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有