问题描述
我正在使用swift 3.0,并试图将徽章编号添加到我的应用中.我相信执行此操作的正确方法类似于以下内容.
I am using swift 3.0 and am trying to add badge numbers to my app. I believe the correct way to do this is similar to what is below.
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound | UIUserNotificationType.Alert |
UIUserNotificationType.Badge, categories: nil
))
application.applicationIconBadgeNumber = 5
但是,使用'|'时出现错误在 UIUserNotificationSettings
块中,并且如果我只有 UIUserNotificationType,还将收到错误针对
作为第一个参数.swift 3.0是否更改了该语句的语法? UIUserNotificationSettings
的参数标签(forTypes,类别)与任何可用的重载都不匹配".badge
However, I get an error for using '|' in UIUserNotificationSettings
block and will also receive the error "Argument labels (forTypes, categories) do not match any of the available overloads" for UIUserNotificationSettings
if I only have UIUserNotificationType.badge
as the first argument. Did swift 3.0 change the syntax for this statement?
推荐答案
在Swift 2和Swift 3中均已更新.此行应可解决您的问题.此外,还要确保其他带有UIUserNotificationType的行的变量都已转换为小写.
It has been updated in both Swift 2 and Swift 3. This line should fix your issue. Also make sure any other lines with UIUserNotificationType have had their variables switched to lowercase.
let settings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
这篇关于针对UIUserNotificationSettings的Swift 3.0语法更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!