我正进入(状态
yld: Symbol not found: _OBJC_CLASS_$_UIUserNotificationSettings
Run Code Online (Sandbox Code Playgroud)
这是当应用程序在iOS7设备上运行时甚至根本没有在代码中调用该函数时导致错误的函数.
Run Code Online (Sandbox Code Playgroud)func reigsterForRemoteUserNotifications(notificationTypes: UIUserNotificationType, categories: NSSet) { let userNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: categories) (UIApplication.sharedApplication()).registerUserNotificationSettings(userNotificationSettings) UIApplication.sharedApplication().registerForRemoteNotifications() }
我不希望在iOS7设备上运行时可以访问此方法.我不希望在其中进行选择检查,因为这意味着该方法可用于开始.
我想要的是一个构建配置参数来检查版本:我无法找到一种方法来编写一个快速等效的预处理器宏来检查正确的iOS版本并忽略新的和未声明的iOS 8库函数.
#if giOS8OrGreater
// declare the functions that are iOS 8 specific
#else
// declare the functions that are iOS 7 specific
#endif
Run Code Online (Sandbox Code Playgroud)
在文档中,apple建议使用函数和泛型来替换复杂的宏,但在这种情况下,我需要构建配置预编译检查以避免处理未声明的函数.有什么建议.
我将角半径应用于视图的左上角和右上角.在viewDidLoad()我有:
if #available(iOS 11.0, *) {
view.layer.cornerRadius = 20.0
view.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
}
Run Code Online (Sandbox Code Playgroud)
如果iOS 11不可用,最佳方式似乎就是这样做draw(_ rect:).由于我必须在外面覆盖它viewDidLoad(),我想做以下事情
if NOT #available(iOS 11.0, *) {
override func draw(_ rect: CGRect) {
let maskPath = UIBezierPath(roundedRect: self.contentView.bounds, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize(width: 20.0, height: 20.0))
let shapeLayer = CAShapeLayer()
shapeLayer.frame = self.bounds
shapeLayer.path = maskPath.cgPath
view.layer.mask = shapeLayer
}
}
Run Code Online (Sandbox Code Playgroud)
当然,它在语法上是不正确的.我该怎么办?