Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';无法在IOS中更改应用程序徽章_Ios_Xcode_Swift_Ios8_Uiapplication - Fatal编程技术网

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个徽章。