使用未解析的标识符:"UNMutableNotificationContent"

ZB-*_*dev 3 ios uilocalnotification swift unnotificationrequest

我有以下代码:

func sendLucidNotification() {
    let content = UNMutableNotificationContent()
    content.title = "10 Second Notification Demo"
    content.subtitle = "From MakeAppPie.com"
    content.body = "Notification after 10 seconds - Your pizza is Ready!!"
    content.categoryIdentifier = "message"

}
Run Code Online (Sandbox Code Playgroud)

当我调用,UNMutableNotificationContent或任何"UNMutableNotification"变体时,我收到以下错误:

Use of unresolved identifier: "UNMutableNotificationContent"
Run Code Online (Sandbox Code Playgroud)

我在Xcode 8.0上,但是当我尝试自动完成时,它也无法识别它.有任何想法吗 ?谢谢!

Tus*_*har 16

很可能你需要在编写此代码的地方添加import notification_framework语句,例如

import notification_framework_name
Run Code Online (Sandbox Code Playgroud)

还要确保框架可用于目标构建.

更新:在您的情况下,import语句将是:

import UserNotifications
Run Code Online (Sandbox Code Playgroud)

  • `#import <UserNotifications/UserNotifications.h>` 在 obj-c (2认同)