Updating iOS badge without push notifications

前端 未结 6 1432
挽巷
挽巷 2020-11-28 20:25

I have seen a few todo apps that update their app badges at midnight, always showing the correct number of due tasks. They do this without the use of Push Notificat

相关标签:
6条回答
  • Set UIApplication's applicationIconBadgeNumber property in your code when application is running:

    [UIApplication sharedApplication].applicationIconBadgeNumber = someNumber;
    
    0 讨论(0)
  • 2020-11-28 20:51

    Swift 5

    UIApplication.shared.applicationIconBadgeNumber = someNumber
    
    0 讨论(0)
  • 2020-11-28 20:52

    Since iOS 4.0 you can fire local notifications on all devices that run at least iOS 4.0. Look into the UILocalNotification class, it allows you to set the badge at midnight without having your app running.

    0 讨论(0)
  • 2020-11-28 20:53

    Try this

    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
    

    To do this through local notifications you have to set the value in applicationIconBadgeNumber

    UILocalNotification *localNotification = [[UILocalNotification alloc] init];
    localNotification.applicationIconBadgeNumber = 1;// set here the value of badge
    
    0 讨论(0)
  • 2020-11-28 20:59

    And for everyone using new and shiny Swift:

    UIApplication.sharedApplication().applicationIconBadgeNumber = someNumber
    

    Swift 3:

    UIApplication.shared.applicationIconBadgeNumber = someNumber
    
    0 讨论(0)
  • 2020-11-28 21:07

    For Objective C you have to use:

    [[UIApplication sharedApplication] setApplicationIconBadgeNumber : anyNumber ];            
    
    0 讨论(0)
提交回复
热议问题