ios - Error.code 在 swift 3 中不再有效语法?

标签 ios swift

<分区>

最近将我的应用程序从以前的版本转换为 swift 3。可以预见的是,这会导致我的代码出现很多错误。我不知道如何解决以下问题: (在 Appdelegate.swift 中):

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
        if error.code == 3010 {
            print("Push notifications are not supported in the iOS Simulator.\n")
        } else {
            print("application:didFailToRegisterForRemoteNotificationsWithError: %@\n", error)
        }
    }

给出的错误是类型error的值没有成员“code”。我该如何解决这个问题?

最佳答案

尝试将错误转换为 NSError

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
    if (error as NSError).code == 3010 {
        print("Push notifications are not supported in the iOS Simulator.\n")
    } else {
        print("application:didFailToRegisterForRemoteNotificationsWithError: %@\n", error)
    }
}

关于ios - Error.code 在 swift 3 中不再有效语法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39665561/

相关文章:

ios - "Open In"应该在 iPhone 相机胶卷中显示我的应用程序

objective-c - iOS 中的 PDF 包

swift - 您将在 Swift for XML 中的何处包含替换事件?

ios - 在 UITackView 中使用自定义 xib

iOS:使用 Swift2 删除 .DocumentDirectory 中的文件

ios - 自定义 UITableViewCell 图像在滚动之前不会显示

ios - AVPlayer 播放视频合成结果不正确

swift - MTLDevice.makeBuffer 上的 Metal 破裂(字节 :length:options:)

ios - TViOS 第三方库 marmelroy/Zip

ios - 如何将字典数组中的值加载到TableView单元格中