如何在后台模式下仍然运行应用程序?
问题描述:
答
如果您已经尝试“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
答
试试这个斯威夫特3:
UIApplication.shared.applicationIconBadgeNumber = 1
谢谢你回答我,但我想知道的是,当应用程序在后台模式,有什么办法可以让应用程序仍运行函数来获得API结果,当获得真正的价值,然后更改徽章,不使用推送通知和本地通知。 – DanielTing