2016-12-01 146 views

回答

0

如果您已經嘗試「macmoonshine」和「搶」的答案,你仍然沒有得到徽章圖標。

試試這個。希望能幫助到你。

目標C

UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil]; 

[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings]; 

[UIApplication sharedApplication].applicationIconBadgeNumber = 1; 

**夫特3 **

let badgeCount: Int = 10 
let application = UIApplication.sharedApplication() 
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [.Badge, .Sound], categories: nil))   
application.applicationIconBadgeNumber = badgeCount 

夫特3並用UserNotifications框架

進口UserNotifications

let badgeCount: Int = 10 
let application = UIApplication.shared 
let center = UNUserNotificationCenter.current() 
center.requestAuthorization(options:[.badge, .alert, .sound]) { (granted, error) in 
    // Enable or disable features based on authorization. 
} 
application.registerForRemoteNotifications() 
application.applicationIconBadgeNumber = badgeCount 
+0

謝謝你回答我,但我想知道的是,當應用程序在後臺模式,有什麼辦法可以讓應用程序仍運行函數來獲得API結果,當獲得真正的價值,然後更改徽章,不使用推送通知和本地通知。 – DanielTing

0

試試這個斯威夫特3

UIApplication.shared.applicationIconBadgeNumber = 1 
相關問題