MAC 10.14中的UNUserNotificationCenter;无效的参数不令人满意:bundleProxy!= nil

时间:2019-09-16 12:13:50

标签: swift macos macos-mojave unusernotificationcenter

在MAC OS 10.14中显示通知时,我的应用程序崩溃了。使用以下代码

extension ViewController: NSUserNotificationCenterDelegate,UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: NSUserNotificationCenter, shouldPresent notification: NSUserNotification) -> Bool {
    return true
}

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
    completionHandler([.alert,.badge,.sound])

}


class AppDelegate: NSObject, NSApplicationDelegate {

var bardgenumber: Int = 0

func applicationDidFinishLaunching(_ aNotification: Notification) {
       self.shownotification("test","welcome")
}

func applicationWillTerminate(_ aNotification: Notification) {
    // Insert code here to tear down your application
}
private func shownotification(_ title: String, _ message: String)
{
    let center = UNUserNotificationCenter.current()
    let notification  = UNMutableNotificationContent()
    notification.title      = title
    notification.body       = message
    notification.sound      = UNNotificationSound.default
    notification.badge  = 1
    notification.categoryIdentifier = "actionCategory"
    let tigger  = UNTimeIntervalNotificationTrigger.init(timeInterval: 1.0, repeats: false)
    let request = UNNotificationRequest(identifier: "test", content: notification, trigger: tigger)

    let options: UNAuthorizationOptions = [.alert, .sound, .badge]

    center.delegate = self
    center.requestAuthorization(options: options){
     (granted, error) in
     if granted
     {
     center.add(request) { (error : Error?) in
     if let theError = error {
     print(theError.localizedDescription)
     }
     }
     }
     }

}

该代码正在其编译的机器上运行。当获取.app文件并在另一台机器上运行时,应用程序崩溃,并显示“无效参数不满足:bundleProxy!= nil”。

0 个答案:

没有答案