How does swift add messages to the IOS app icon and add swiftios

Source: Internet
Author: User

How does swift add messages to the IOS app icon and add swiftios

You can add a Message count reminder in the upper-right corner of the application icon to conveniently notify you of any new messages to be processed in the application. The following uses xcode 7.3.1 to briefly describe how to implement this function in swift.

1. Modify AppDelegate. swift

1 // 2 // AppDelegate. swift 3 // RainbowDemo 4 // 5 // Created by Jackwang on 16/8/17. 6 // Copyright©2016 Jackwang. All rights reserved. 7 // 8 9 import UIKit10 11 @ UIApplicationMain12 class AppDelegate: UIResponder, UIApplicationDelegate {13 14 var window: UIWindow? 15 16 17 func application (application: UIApplication, didfinishlaunchingwitexceptions launchOptions: [NSObject: AnyObject]?) -> Bool {18 // Override point for customization after application launch.19 // use UILocalNotification to push local messages (you can set the push content, push time, and prompt sound ), 20 // You can also set the number of reminders in the upper-right corner of the application. 21 let settings = UIUserNotificationSettings (forTypes :[. alert ,. badge ,. sound], 22 categories: nil) 23 application. registerUserNotificationSettings (settings) 24 25 26 return true27} 28 29 func applicationWillResignActive (application: UIApplication) {30 // 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.31 // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. games shocould use this method to pause the game.32} 33 34 func applicationDidEnterBackground (application: UIApplication) {35 // 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.36 // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.37} 38 39 func applicationWillEnterForeground (application: UIApplication) {40 // Called as part of the transition from the background to the inactive state; here you can undo events of the changes made on entering the background.41} 42 43 func applicationDidBecomeActive (application: UIApplication) {44 // Restart any tasks that were paused (or not yet started) while the application was inactive. if the application was previusly in the background, optionally refresh the user interface.45} 46 47 func applicationWillTerminate (application: UIApplication) {48 // Called when the application is about to terminate. save data if appropriate. see also applicationDidEnterBackground :. 49} 50 51 52}

2. Modify the value in ViewController. swift.

1 // 2 // ViewController. swift 3 // RainbowDemo 4 // 5 // Created by jackwang on 16/8/17. 6 // Copyright©2016 jackwang. all rights reserved. 7 // 8 9 import UIKit10 11 class ViewController: UIViewController {12 13 override func viewDidLoad () {14 super. viewDidLoad () 15 // Do any additional setup after loading the view, typically from a nib.16 // send the notification message 17 scheduleNotification (); 18} 19 20 // send notification message 21 func scheduleNotification () {22 // clear all local push 23 UIApplication. sharedApplication (). cancelalllocalconfigurications () 24 25 // create a UILocalNotification to send a local Message notification 26 let localNotification = UILocalNotification () 27 // set the number of reminders in the upper-right corner of the application 28 localNotification. applicationIconBadgeNumber = 8; 29 UIApplication. sharedApplication (). scheduleLocalNotification (localNotification) 30} 31 32 override func didReceiveMemoryWarning () {33 super. didReceiveMemoryWarning () 34 // Dispose of any resources that can be recreated.35} 36 37 38}

3 compile and run

The first dialog box will pop up asking whether messages can be pushed. After confirmation, after running the app for the second time, the number of messages will be marked in the upper-right corner of the icon, as shown in:

Modify the display name of the APP. Click info. plist and modify Bundle name, as shown in:

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.