Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 未调用swift 4中的DidReceivereMotentifications的本地通知_Ios_Swift_Apple Push Notifications_Swift4_Ios11 - Fatal编程技术网

Ios 未调用swift 4中的DidReceivereMotentifications的本地通知

Ios 未调用swift 4中的DidReceivereMotentifications的本地通知,ios,swift,apple-push-notifications,swift4,ios11,Ios,Swift,Apple Push Notifications,Swift4,Ios11,我的代表如下: import UIKit import CoreData import UserNotifications @available(iOS 11.0, *) @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate { var window: UIWindow? ... func applicati

我的代表如下:

import UIKit
import CoreData
import UserNotifications

@available(iOS 11.0, *)
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate
{
    var window: UIWindow?

    ...

    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any])
    {
        print("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
    }
}
我使用的是ios11和swift 4.1,但通知被正确触发。但当我点击它时,我无法在应用程序中抓取它。为什么?我使用的是xcode 9.4.1。谢谢


应用程序位于后台,当点击通知时,应用程序打开。

Hello@cdub您应该使用UserNotificationCenter

 func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {

    // do code here to show notification alert in for-ground mode 
}




func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
    //your notification handling code here 
    }

应用程序的状态如何?后台/关闭/打开?什么是本地推送通知?是推送通知还是本地通知?更新了问题如果您只想获得本地通知响应,请尝试使用userNotificationCenter。我认为您的代码是用于远程通知(DidReceiveEmotentification)的。当有人点击本地通知时,我想获取它。这是怎么做到的?我有这些答案:这也适用于appDelegate吗?只是好奇是的当然你必须把它放在AppDelegateIt working now Thanks我很高兴@cdub请在willPresent中这样做delegate和response.notification.request.content.userInfo=====像在didReceive中这样