Can';无法在IOS中更改应用程序徽章
我试图在应用程序图标上添加徽章,但什么也没发生Can';无法在IOS中更改应用程序徽章,ios,xcode,swift,ios8,uiapplication,Ios,Xcode,Swift,Ios8,Uiapplication,我试图在应用程序图标上添加徽章,但什么也没发生 UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound | UIUserNotificationType.Alert | UIUserNotificationType.Badge, categories: nil)) UIApplicatio
UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound | UIUserNotificationType.Alert | UIUserNotificationType.Badge, categories: nil))
UIApplication.sharedApplication().applicationIconBadgeNumber = 40;
我是否遗漏了此代码中的某些内容?您是否请求更改徽章?这已在iOS8中更改,需要特定权限:
let settings = UIUserNotificationSettings(forTypes: UIUserNotificationType.Badge,
categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
您是否要求更改徽章?这已在iOS8中更改,需要特定权限:
let settings = UIUserNotificationSettings(forTypes: UIUserNotificationType.Badge,
categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
注册远程通知
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let settings = UIUserNotificationSettings(forTypes: UIUserNotificationType.Badge,
categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
return true
}
更新您的徽章号码
UIApplication.sharedApplication().applicationIconBadgeNumber = 40;
注册远程通知
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let settings = UIUserNotificationSettings(forTypes: UIUserNotificationType.Badge,
categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
return true
}
更新您的徽章号码
UIApplication.sharedApplication().applicationIconBadgeNumber = 40;
以前的答案是旧的 iOS 10及以上版本:
let options: UNAuthorizationOptions = [.alert, .sound, .badge];
UNUserNotificationCenter.current()(options: options) { (granted, error) in
//print("granted: \(granted)")
if let error = error {
print("Error requestAuthorization: \(error.localizedDescription)")
}
}
以前的答案是旧的 iOS 10及以上版本:
let options: UNAuthorizationOptions = [.alert, .sound, .badge];
UNUserNotificationCenter.current()(options: options) { (granted, error) in
//print("granted: \(granted)")
if let error = error {
print("Error requestAuthorization: \(error.localizedDescription)")
}
}
我检查了你的代码,它在我的应用程序图标中显示了40个徽章。我检查了你的代码,它在我的应用程序图标中显示了40个徽章。