我试图将我的 Objective-C AppDelegate 转换为 Swift AppDelegate。所以我删除了 main.m 文件并将所有 AppDelegate 代码转换为 swift。我尝试运行该项目,然后出现此错误。
Cannot find protocol declaration for 'UNUserNotificationCenterDelegate'
在他们生成的 -Swift.h 文件中,这是他们展示的委托(delegate)
- (void)userNotificationCenter:(UNUserNotificationCenter * _Nonnull)center willPresentNotification:(UNNotification * _Nonnull)notification withCompletionHandler:(void (^ _Nonnull)(UNNotificationPresentationOptions))completionHandler SWIFT_AVAILABILITY(ios,introduced=10.0);
我是这样写的
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
handleNotification(notification.request.content.userInfo)
}
请帮我弄清楚我面临的问题是什么。
我尝试过清理、重新启动 Xcode 并重新启动我的 Mac。我正在使用 Swift 3.2。
如果我评论代表,没有错误。
最佳答案
奇怪的修复,但通过在我的桥接 header 中导入#import,问题得到解决。
关于ios - 在 -Swift.h 文件中找不到 'UNUserNotificationCenterDelegate' 的协议(protocol)声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49429537/